Managing Jails
Created: 06/30/2008
General Information
This document is an introduction to basic FreeBSD jails also called ‘fat jails’. We discuss an easy jail installation process. We will do some basic jail configuration and show you how to manage the jail environment. This document wil not cover building ‘chroot jails’ in a jail.Requirements
Installation
Before we start: the machine which will run the jails is refered as ‘host’. The jails are built and configured from the host. Every individual jail runs the desired services. The host’s services are minimized, running a syslogd and sshd should be enough.Jail Location
Determine where you want to install the jail(s). Throughout the document/usr/jails will be used. For example we will install a web server in the jail, so let us take /usr/jails/webserver1 as the location for the web server. |
# # # # # |
cd /usr/ mkdir jails cd jails mkdir webserver1 sysinstall |
|
# cd /usr/jails/webserver1 # ls .cshrc boot libexec rescue tmp .profile dev media root usr COPYRIGHT etc mnt sbin var bin lib proc sys # |
Host – rc.conf
|
hostname="host" ifconfig_rl0="inet 10.0.0.10 netmask 255.255.255.0" ifconfig_rl0_alias0="inet 10.0.0.20 netmask 255.255.255.255" inetd_enable=”NO” # if you need inetd sevices on the host, uncomment the inetd lines #inetd_enable="YES" #inetd_flags="-wW -a 10.0.0.10" rpcbind_enable="NO" sendmail_enable="NO" sendmail_submit_enable="NO" sendmail_outbound_enable="NO" sendmail_msp_queue_enable="NO" syslogd_enable="YES" syslogd_flags="-ss" syslogd_flags="-a 10.0.0.10" syslogd_flags="-a 10.0.0.20" keymap="us.iso" sshd_enable="YES" # Jail general settings jail_set_hostname_allow=”NO” jail_enable="YES" jail_list="webserver1" jail_interface="rl0" jail_devfs_enable="YES" jail_procfs_enable="YES" # settings per jail listed in jail_list jail_webserver1_rootdir="/usr/jails/webserver1" jail_webserver1_hostname="webserver1" jail_webserver1_ip="10.0.0.20" jail_webserver1_devfs_ruleset="devfsrules_jail" |
Webserver1 – rc.conf
|
hostname="webserver1" ifconfig_rl0="inet 10.0.0.20 netmask 255.255.255.255" defaultrouter="10.0.0.1" rpcbind_enable="NO" clear_tmp_enable="YES" sendmail_enable="YES" sshd_enable="YES" |
Webserver1 – resolv.conf
If your host box has already an internet connection, you can copy the host’s DNS information to webserver1.| # | cp /etc/resolv.conf /usr/jails/webserver1/etc/resolv.conf |
| # | /bin/sh /etc/rc |
|
# jls JID IP Address Hostname Path 1 10.0.0.20 webserver1 /usr/jails/webserver1 # ping -c 3 10.0.0.20 PING 10.0.0.20 (10.0.0.20): 56 data bytes 64 bytes from 10.0.0.20: icmp_seq=0 ttl=64 time=0.324 ms 64 bytes from 10.0.0.20: icmp_seq=1 ttl=64 time=0.222 ms 64 bytes from 10.0.0.20: icmp_seq=2 ttl=64 time=0.220 ms --- 10.0.0.20 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/stddev = 0.220/0.255/0.324/0.049 ms # |
Jail configuration
Some basic jail configuration: creating an empty fstab, setting a root password, adding a user and setting the timezone.|
jexec <jail ID> <execute command in the jail> |
|
# # # # |
jexec 1 touch /etc/fstab jexec 1 passwd jexec 1 adduser jexec 1 tzsetup |
|
# jexec 1 login $ su # exit $ exit # |
|
# # # # |
jexec 1 /bin/sh ee /etc/group exit jexec 1 login |
|
# # # # |
/etc/rc.d/sshd stop ee /etc/ssh/sshd_config /etc/rc.d/sshd start exit |
|
# # |
/etc/rc.d/jail start /etc/rc.d/jail stop |
|
# # |
/etc/rc.d/jail start webserver1 /etc/rc.d/jail stop webserver1 |
Installing a service
Let us continue and install a webserver trough the host’s ports collection. Installing the ports collection in a jail is unnessecary. Checkig installed ports for known vulnarabilities is of course necessary. We will mount the host’s ports against our jailed environments. Unmount the host’s /usr/ports and /usr/src them when done.|
# # # # # # # # # # # |
jexec 1 mkdir /usr/ports mount_nullfs /usr/ports /usr/jails/webserver1/usr/ports mount_nullfs /usr/src /usr/jails/webserver1/usr/src jexec 1 login su cd /usr/ports/ports-mgmt/portaudit make install distclean /usr/local/sbin/portaudit -Fda cd ../../www/apache22 make install distclean echo 'apache22_enable="YES"' >> /etc/rc.conf |
|
ee /usr/local/etc/apache22/httpd.conf ServerName 10.0.0.20 |
| # | /usr/local/sbin/apachectl start |
|
[warn] (2)No such file or directory: Failed to enable the ‘httpready’ Accept Filter |
| # | echo ‘accf_http_load=”YES” ‘ >> /boot/loader.conf |
Conclusion
The jail environment is just a virtual box with extra features for free.References
This guide is © 2008 philg.
Author: philg
demonjokerjr at hotmail dot com