https://ogris.de/howtos/freebsd-jails.html
Jails on FreeBSD
We have had Jails on FreeBSD since 4.0 came out 19 years ago in March
2000. This describes how to setup jails on FreeBSD 12 without any
helpers.
Steps
1. I usually place all jails under /var/jail and give each jail its
own directory, which reflects its short hostname. For this, I use
bsdinstall:
# bsdinstall jail /var/jail/mysql
Deselect all optional system components during the installation
as well as any services.
2. On the host system, you can either create one big /etc/jail.conf
or one /etc/jail.HOSTNAME.conf per jail, e.g. /etc/
jail.mysql.conf:
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
path = "/var/jail/mysql";
mysql {
host.hostname = "mysql.intra.ogris.net";
ip4.addr = "lo1|10.0.0.2";
}
3. In order to have the jails started and stopped during system boot
and shutdown, respectively, add this to /etc/rc.conf:
jail_enable="YES"
jail_list="mysql"
4. Unless you want to assign each jail an IP address from your
network, you have to setup a host-only network. In /etc/rc.conf:
cloned_interfaces="lo1"
ifconfig_lo1="inet 10.0.0.1 netmask 255.255.255.0"
5. Usually, you want to give your jails Internet access. Thus, we
need NAT on the host. First, create /etc/ipfw.rules:
nat 1 config if vtnet0 same_ports
add nat 1 ip from any to any via vtnet0
add allow ip from any to any
Replace vtnet0 by your actual network interface.
6. Now add this to /etc/rc.conf in order to activate IP forwarding
and to have the firewall rules loaded during system boot:
kld_list="ipfw_nat"
gateway_enable="YES"
firewall_enable="YES"
firewall_type="/etc/ipfw.rules"
7. Reboot the host. Afterwards, you can log into your jails, e.g. by
typing
# jexec mysql /bin/csh
8. Optionally, set up a local unbound as caching DNS resolver:
# cat >/etc/unbound/conf.d/local.conf <