FreeBSD Jails:
Installation
This guide was written for FreeBSD 10.x, there were some changes to jail setup (configuration moved from /etc/rc.conf to /etc/jail.conf)
No installation is required on the host, as jails are part of the FreeBSD infrastructure, to "install" a guest simply create and build-out its filesystem:
mkdir /jail
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.1-RELEASE/base.txz
mkdir -p /jail/myjail
tar xf base.txz -C /jail/myjail
Note: Your jail's filesystem can be directly manipulated from the host.
Configuration
Add the following to the host's /etc/rc.conf:
# Jail Configuration
jail_enable="YES" # Set to NO to disable starting of any jails
ifconfig_bge0_alias0="inet 192.168.0.100 netmask 255.255.255.0"
Create the jail's /jail/myjail/etc/rc.conf:
hostname="myjail.example.org"
sshd_enable="YES"
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
Copy hosts's /etc/resolv.conf to /jail/myjail/etc
Create /etc/jail.conf:
myjail {
path = /jail/myjail;
mount.devfs;
devfs_ruleset = 4;
host.hostname = myjail.example.org;
ip4.addr = 192.168.0.100;
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
}
Management
After a reboot, or an ifconfig to set your new alias there are a few commands to help manage jails
List running jails:
jls
Stop/Start a Jail:
service jail stop myjail
service jail start myjail
Run a command locally in the jail (such as a shell):
jexec {jailid from jls} csh
Before you try to ssh to your jail, you may need to jexec as above and create a new user.
If the date/time looks off in your jail, run tzsetup within the jail.
Happy Jailing!