FreeBSD jails allow users to run multiple, isolated instances of FreeBSD on a single server. Iocage simplifies the management of FreeBSD Jails.
https://en.wikipedia.org/wiki/OS-level_virtualization
The jails will be configured to bind to an IP address on the jail host's internal network. The host OS will pass traffic from the external network to the jail.
The jails will be managed with Iocage. Iocage uses ZFS properties to store configuration data for each jail, so a ZFS file system is required.
These steps will:
PF is full featured firewall, and can do more than just pass traffic to an internal network. Refer to the PF documentation for additional configuration options.
sysrc cloned_interfaces+="lo1"
sysrc ifconfig_lo1="inet 192.0.2.1/24"
sysrc pf_enable="YES"
/etc/pf.conf
# Variables
# ext_if should be set to the hosts external NIC
ext_if = "vtnet0"
jail_if = "lo1"
jail_net = $jail_if:network
# NAT allows the jails to access the external network
nat on $ext_if from $jail_net to any -> ($ext_if)
# Redirect traffic on port 80 to the web server jail
# Add similar rules for additional jails
rdr pass on $ext_if inet proto tcp to port 80 -> 192.0.2.10
Reboot to activate the network changes
The best way to use ZFS on a VPS is to attach block storage as a new disk.
If block storage is not available, you can optionally use a file as the ZFS device.
sysrc zfs_enable="YES"
service zfs start
List the available disks. If you are using a VPS, the block store will probably be the second disk.
geom disk list
Create a ZFS pool named jailstore.
zpool create jailstore /dev/vtbd1
Create the ZFS file.
dd if=/dev/zero of=/zfsfile bs=1M count=4096
Create a ZFS pool named jailstore.
zpool create jailstore /zfsfile
pkg install py36-iocage
iocage activate jailstore
iocage fetch
iocage create -n www ip4_addr="lo1|192.0.2.10/24" -r 11.1-RELEASE
iocage start www
iocage console www
Once you have a shell inside the jail, install and start Apache.
pkg install apache24
sysrc apache24_enable="yes"
service apache24 start
Port 80 on the jail will now be accessible on the hosts IP address.
Additional jails can be installed using the example above.
iocage create
command , but use a different IP addressUnless otherwise stated, our shows are released under a Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.
The HPR Website Design is released to the Public Domain.