This is a configuration I’m using for testing inside the FreeBSD jails.
In this example the jail shares the host’s network interfaces.
Here we assume using the zfs filesystem. Using zfs is not mandatory, but it allows simple use of snapshots and rollback if I break something.
Create the jail system template and datasets
su -
zfs create -o mountpoint=/jails zroot/jails
zfs create -o compression=on -o encryption=on -o keyformat=passphrase zroot/jails/template
bsdinstall jail /jails/template/
cp /etc/resolv.conf /jails/template/etc/
zfs snapshot zroot/jails/template@base001
zfs create zroot/jails/containers
zfs clone zroot/jails/template@base001 zroot/jails/containers/test
# we could create new dataset with different key and run `bsdinstall` to the directory
# but if I need to scrap/recreate the dataset (filesystem) when testing, this is quicker
/etc/jail.conf
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.consolelog = "/var/log/jail_console_${name}.log";
# PERMISSIONS
allow.raw_sockets;
exec.clean;
mount.devfs;
# HOSTNAME/PATH
host.hostname = "${name}.jails";
path = "/jails/containers/${name}";
.include "/etc/jail.conf.d/*.conf";
/etc/jail.conf.d/test.conf
test {
persist;
ip4 = inherit;
ip6 = inherit;
}
sysrc jail_enable="YES"
service jail start
jls
JID IP Address Hostname Path
1 test.jails /jails/containers/test
To create a jail with separate network easily, we can use bastille. This is nice example of creating a jail with separate vnet.