Skip to content

Lesson 5 of 9 · 28m

Jails: Operational Containment Done Right

Build isolated service environments with jail.conf, understand filesystem and network models, and avoid treating jails as virtual machines.

Jails predate modern containers and still outperform many container deployments in one crucial dimension: clarity. A jail is a filesystem, process tree, hostname, user namespace of behavior, and network isolation primitive enforced by the kernel. It is not a virtual machine and not a security miracle. It is a strong operational boundary when designed deliberately.

Start with jail.conf, not shell improvisation

Modern jail configuration is declarative:

exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
path = "/jail/$name";

web {
    host.hostname = "web.internal";
    ip4.addr = "lo1|10.7.0.10/32";
    allow.raw_sockets = 0;
}

Start and inspect it with:

service jail start web
jls
jexec web ps aux

The important part is intent: where the root filesystem lives, which address it owns, whether it can use raw sockets, and what lifecycle commands run. Hand-assembled jail invocations become snowflakes quickly.

Jails share the host kernel

A jail does not boot its own kernel. The host kernel version constrains the userland compatibility you can run inside. This makes jails lightweight and fast, but it also means kernel-level exploit mitigation depends on the host. Patch the host. Do not place mutually hostile security domains in jails and pretend they are separate machines.

Choose the filesystem layout deliberately

A common pattern is a ZFS dataset per jail:

zfs create -o compression=lz4 zroot/jails
zfs create zroot/jails/web

Base system content can be copied or managed with templates. Thin jails using nullfs mounts or read-only shared bases can reduce duplication, but shared mutable state defeats isolation. Decide which parts are shared and which are private. /etc, /var, application data, and package state usually deserve independence.

Networking has real models

Traditional jails can bind to addresses on host interfaces or use a loopback clone such as lo1 with PF redirection. More advanced deployments use VNET, giving a jail its own network stack and interfaces. That complexity is warranted for routing, firewalling, or multi-tenant network behavior — not because it sounds more modern.

ifconfig lo1 create
ifconfig lo1 inet 10.7.0.1/32

If services only need private internal communication, lo1 plus PF is often simpler than bridging everything into a virtual network maze.

Treat jails as service units

A jail should host a coherent service or small service family. Logging, backup, package updates, and secrets are then scoped to that unit. A jail containing twenty unrelated daemons is just an undersized server with worse documentation.

Field notes

  • allow.raw_sockets matters for ping-like tooling and some network daemons; grant it knowingly.
  • DevFS inside jails must be controlled through rulesets when device access matters.
  • ZFS delegated datasets can be powerful but expand what jail operators can destroy.
  • If you need kernel isolation or foreign operating systems, use bhyve or hardware virtualization, not a jail.

Was this lesson helpful?

Sign in to rate