33.1 Linux Jail Basics
Linux Jail is a feature of the FreeBSD operating system used to run Linux binaries and applications within a Jail. It works by integrating a compatibility layer in the FreeBSD kernel that translates Linux system calls into corresponding FreeBSD native system calls. Linux Jail enables FreeBSD systems to run Linux software without the need to deploy a separate Linux virtual machine or runtime environment.
The following introduces the initial configuration for deploying a Linux Jail within a FreeBSD Jail.
Prerequisites
This section binds all Jails to the virtual network interface lo1, forming a local area network within the FreeBSD system, where the FreeBSD host acts as the gateway.
All Jail network traffic must pass through the network interface lo1, so network forwarding must be enabled. This section uses the pf firewall to accomplish this.
Note
The pf firewall must be configured to implement network access control.
Prepare the Network Interface
Add and enable the cloned network interface lo1:
# sysrc cloned_interfaces+="lo1"
# service netif cloneupPrepare the pf Firewall
Two configuration methods are provided; choose as needed.
Method One
A table in the pf firewall is a named structure used to store a collection of addresses and networks. Addresses in the table can access the network through NAT.
Even when no rules reference a table, the persist flag ensures the firewall always retains it, preventing the table from being automatically cleared when firewall rules are reloaded.
Edit the /etc/pf.conf file and add the following configuration:
Tip
In practice, replace the interface name
em0and each Jail's IP address with the actual configuration in your environment.
You can use pfctl to add or remove entries from the jails table to control network access. For example:
pfctl -t jails -T add 192.168.5.1adds 192.168.5.1 to the jails table, allowing it to access the network.pfctl -t jails -T delete 192.168.5.1removes 192.168.5.1 from the jails table, preventing it from accessing the network.
This method requires manual management but offers greater flexibility.
Method Two
Write the rule directly in the /etc/pf.conf file:
This method allows 192.168.5.1 to access the network. The rules are fixed in the configuration file, which is more convenient for scenarios without special requirements.
Enable the pf Firewall
Even without using firewall rules, the pf service must be enabled to implement NAT functionality. For instructions on enabling the pf firewall, refer to other chapters.
Load the Linux Binary Compatibility Layer (Linuxulator) Kernel Module
Enable and start the Linux compatibility layer service. This method automatically loads the various kernel modules required by the Linux compatibility layer:
Prepare Directories
Create a directory for storing Jail-related files:
File Structure
References
FreeBSD Wiki. LinuxApps[EB/OL]. [2026-03-25]. https://wiki.freebsd.org/LinuxApps. Lists Linux applications and methods running on FreeBSD, providing reference for compatibility practices.
Last updated