FreeBSD jails are one of the most powerful and elegant features of the BSD family, and GhostBSD inherits this capability. They’re like lightweight containers, but with deep integration into the OS.
This tutorial will guide you through creating a simple test jail on GhostBSD that runs a terminal session and displays basic system info. No services, no networking, just a clean, isolated environment to explore.
Goal: Create a jail, enter it, confirm it’s isolated, and then delete it cleanly.
Step 1: Enable Jail Support
sudo sysrc jail_enable="YES"
Step 2: Create a Jail Directory
sudo mkdir -p /usr/jails/testjail
Step 3: Install FreeBSD Base System into the Jail
cd /usr/jails/testjail
sudo fetch http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/amd64/14.0-RELEASE/base.txz
sudo tar -xvf base.txz
Note: If the download fails, the server address or file location has changed. Visit https://download.freebsd.org/ftp/releases/amd64/ to find the latest valid URL for
base.txz.
Step 4: Configure the Jail
Edit /etc/jail.conf and add:
testjail {
path = "/usr/jails/testjail";
host.hostname = "testjail.local";
ip4.addr = 127.0.1.1;
interface = "lo1";
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
persist;
}
Step 5: Create Loopback Interface
sudo ifconfig lo1 create
sudo ifconfig lo1 127.0.1.1 up
Step 6: Start the Jail
sudo service jail start testjail
Step 7: Enter the Jail
sudo jexec testjail /bin/sh
You are now inside the jail! Try these commands:
hostname
uname -a
You should see testjail.local as the hostname, proof that you’re inside the jail.
Step 8: Exit the Jail
exit
Step 9: Cleanly Delete the Jail
To remove the jail and all its files:
sudo service jail stop testjail
sudo ifconfig lo1 destroy
sudo rm -rf /usr/jails/testjail
sudo sed -i '' '/testjail {/,+6d' /etc/jail.conf
sudo sysrc -x jail_enable
Done! You’ve created, used, and deleted a FreeBSD jail on GhostBSD.