FreeBSD Jails

FreeBSD Jails Cheatsheet #

FreeBSD Jails is a feature of the FreeBSD operating system that allows administrators to partition a FreeBSD system into multiple independent, secure mini-systems called jails. Each jail has its own hostname, IP address, and file system.

Jail Management #

Command/OptionExampleDescription
jail -cjail -c path=/path/to/jail mount.devfs devfs_ruleset=4 host.hostname=myjail ip4.addr=192.168.0.10 command=/bin/shCreate and start a new jail
jail -rjail -r myjailRemove (stop) a jail
jail -ljail -lList all running jails
jail -mjail -m name=myjail ip4.addr=192.168.0.11Modify an existing jail

Jail Configuration #

Command/OptionExampleDescription
/etc/rc.confjail_enable="YES" jail_list="myjail"Enable jails at boot and list jails to start
/etc/jail.confmyjail { host.hostname = "myjail"; path = "/path/to/jail"; ip4.addr = "192.168.0.10"; exec.start = "/bin/sh /etc/rc"; exec.stop = "/bin/sh /etc/rc.shutdown"; }Define jail parameters in the jail.conf file

Starting and Stopping Jails #

Command/OptionExampleDescription
service jail startservice jail start myjailStart a jail using the service command
service jail stopservice jail stop myjailStop a jail using the service command
service jail restartservice jail restart myjailRestart a jail using the service command

Managing Jail Processes #

Command/OptionExampleDescription
jexecjexec myjail cshExecute a command inside a running jail
jlsjlsList all running jails and their parameters
jkilljkill -j myjail 1234Kill a process running inside a jail by its PID

Networking in Jails #

Command/OptionExampleDescription
ifconfigifconfig epair createCreate a network interface for use with a jail
ifconfigifconfig epair0a upBring up the network interface
ifconfigifconfig bridge0 addm epair0a addm epair0b upAdd network interfaces to a bridge for jail networking
/etc/jail.confmyjail { ... vnet; vnet.interface = "epair0b"; }Configure VNET for a jail in the jail.conf file

Mounting File Systems in Jails #

Command/OptionExampleDescription
mount -t nullfsmount -t nullfs /host/path /path/to/jail/mntMount a directory from the host system inside a jail
fstab.myjail/host/path /path/to/jail/mnt nullfs rw 0 0Add a persistent mount entry for a jail in its fstab file

Advanced Jail Management #

Command/OptionExampleDescription
jail -c persistjail -c name=myjail persistCreate a persistent jail that stays even if no processes are running
jail -hjail -hDisplay help information for the jail command
jail -fjail -f /etc/jail.confStart jails based on the configuration in /etc/jail.conf

This cheatsheet covers the most commonly used FreeBSD Jails commands and options, helping you to manage jail creation, configuration, networking, file systems, and advanced settings effectively.

FreeBSD Jails

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.