{"id":946,"date":"2021-05-29T17:07:44","date_gmt":"2021-05-29T17:07:44","guid":{"rendered":"https:\/\/labiol.xyz\/?p=946"},"modified":"2021-05-29T17:12:14","modified_gmt":"2021-05-29T17:12:14","slug":"easy-setup-freebsd-jail-for-samba-server","status":"publish","type":"post","link":"https:\/\/www.labiol.xyz\/index.php\/2021\/05\/29\/easy-setup-freebsd-jail-for-samba-server\/","title":{"rendered":"Easy setup freebsd jail for samba server."},"content":{"rendered":"\n<p>FreeBSD jail is kind of chrooted, kernel buildin advanced funciton to create several environments in one operating system. All those environments are using the same kernel &#8211; but have they own IP spaces, disk space, users and application. By desing host users (root) can access disk space utilized by the jail, but the oposite is not the case. Also jailed environment cannot access processes running in the host system &#8211; but rather can see just they own processes. <\/p>\n\n\n\n<p>Description of FreeBSD jail for samba purpose  in this article will be fairly easy. Thanks to hard work of freebsd developers there are just few steps to configure and run FBSD jail. Of course, more advanced configuration means more complicated. But, let&#8217;s start with something simple. <\/p>\n\n\n\n<p>We will use three technologies to do this configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ezjail (ezjail-admin)<\/li><li>nullfs<\/li><li>samba<\/li><\/ul>\n\n\n\n<p>First of all, update your FreeBSD using the following command:<\/p>\n\n\n\n<p><code>freebsd-update fetch update<br>pkg update<br>pkg upgrade<\/code><\/p>\n\n\n\n<p>Install ezjail (command necessary to install and manage our jail):<\/p>\n\n\n\n<p><code>pkg install ezjail<\/code><\/p>\n\n\n\n<p>Add the following to the \/etc\/rc.conf<\/p>\n\n\n\n<p><code>ezjail_enable=\"YES\"<br>cloned_interfaces=\"lo1\"<\/code><\/p>\n\n\n\n<p>Next, lets download our environment:<\/p>\n\n\n\n<p><code>ezjail-admin install<\/code><br><code>ezjail-admin update -p<\/code><\/p>\n\n\n\n<p>Where -p paramteres determine to use portsnap to fetch and extract FreeBSD port tree from portsnap. Above commands create template-like directory structure that is used to create new jails. <\/p>\n\n\n\n<p>Verify you network configuration using ifconfig command. You should see your active network card and lo interface. Restart network settings (with our changes in \/etc\/rc.conf file) to create lo1 interface:<\/p>\n\n\n\n<p><code>service netif cloneup<br>ifconfig<\/code><\/p>\n\n\n\n<p>You should see that system has created clone interface, and ifconfig should show it.<\/p>\n\n\n\n<p>Lets create our samba jail (customize IP addr to your environment):<\/p>\n\n\n\n<p><code>ezjail-admin create samba01 'lo1|127.0.1.1,em0|192.168.10.157'<\/code><\/p>\n\n\n\n<p>If you want to use &#8220;local&#8221; directory inside jail environment the easest way will be to bind directory from host system to jailed by adding the following line to \/etc\/fstab in host system (modify it as you like):<\/p>\n\n\n\n<p><code>\/host-jailshare \/usr\/jails\/samba01\/data nullfs rw 0 0<\/code><\/p>\n\n\n\n<p>Check your environment, start it and get access to the console:<\/p>\n\n\n\n<p><code>ezjail-admin list<br>ezjail-admin start samba01<br>ezjail-admin console samba01<\/code><\/p>\n\n\n\n<p>Create\/update your \/etc\/hosts (by adding 127.0.1.1 localhost) and \/etc\/resolv.conf (by adding ie nameserver 8.8.8.8).<\/p>\n\n\n\n<p>Install jail samba package:<\/p>\n\n\n\n<p><code>pkg install samba413<\/code><\/p>\n\n\n\n<p>Edit and configure samba according to your needs. Simple configuration:<\/p>\n\n\n\n<p><code>root@samba01:~ # cat \/usr\/local\/etc\/smb4.conf<br>[global]<br>interfaces = 192.168.10.157<br>bind interfaces only = yes<br>remote announce = 192.168.10.255<br>map to guest = bad user<br>[data]<br>comment = data on fbsd samba server<br>path = \/data<br>read only = no<br>guest ok = yes<br>valid users = smbuser<br>writable = yes<br>browseable = yes<\/code><\/p>\n\n\n\n<p>Also create samba user:<\/p>\n\n\n\n<p><code>adduser smbuser<br>smbpasswd -a smbuser<\/code><\/p>\n\n\n\n<p>Run and verify samba process status:<\/p>\n\n\n\n<p><code>service samba_server start<br>service samba_server status<\/code><\/p>\n\n\n\n<p>Samba should now run and be ready to use from the other servers. Verify and adjust configuration to fit your needs. <br>As promised, simple and fast configuraiton. If you want to have more secure\/advanced configuration I can recommend the following:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/docs.freebsd.org\/en\/books\/handbook\/jails\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.freebsd.org\/en\/books\/handbook\/jails\/ <\/a> &#8212; general information<\/li><li><a href=\"https:\/\/www.youtube.com\/watch?v=hQmOc0egcl4\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.youtube.com\/watch?v=hQmOc0egcl4<\/a>  &#8212; security and other interesting information<\/li><\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>FreeBSD jail is kind of chrooted, kernel buildin advanced funciton to create several environments in one operating system. All those environments are using the same kernel &#8211; but have they own IP spaces, disk space, users and application. By desing host users (root) can access disk space utilized by the &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-946","post","type-post","status-publish","format-standard","hentry","category-freebsd"],"_links":{"self":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=946"}],"version-history":[{"count":10,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/946\/revisions"}],"predecessor-version":[{"id":956,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/946\/revisions\/956"}],"wp:attachment":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}