Here's how I set up a BIND nameserver to run in a FreeBSD jail in December, 2016.
Web pages that helped me include:
Here are the items for which to choose appropriate values prior to setting up the jail:
First, edit /etc/rc.conf by creating the following line:
cloned_interfaces="JAIL_LOOPBACK_INTERFACE_NAME"
or by adding your JAIL_LOOPBACK_INTERFACE_NAME value to that line if a line for this property already exists, such as "lo1 lo2". Use a name that is not in use by an existing network interface.
Then, run service netif cloneup
Add the following line to /etc/rc.conf to ensure that ezjail service starts at boot time:
ezjail_enable="YES"
Then, run service ezjail start to start the service now.
If you want the root of the jails system to be other than the default of /usr/jails, create/edit /usr/local/etc/ezjail.conf and modify the ezjail_jaildir setting to JAIL_FILESYSTEM_ROOT.
If you haven't yet set up the JAIL_FILESYSTEM_ROOT because you want it to exist on a different partition, do so now. You also have the alternative of accepting the default and mounting a partition there, so that the jails you install won't use up too much of the partition on which /usr resides.
Run ezjail-admin install -p. The -p adds the ports directory to the base jail, so you can build the software you need within the jail.
Run ezjail-admin create JAIL_NAME 'JAIL_LOOPBACK_INTERFACE_NAME|JAIL_LOOPBACK_ADDRESS,JAIL_NETWORK_INTERFACE_NAME|JAIL_IP'. I used em0 for JAIL_NETWORK_INTERFACE_NAME.
When creating, ezjail-admin will generate warnings about servers on the host that are listening on 0.0.0.0 or otherwise listening to the new localhost and external IP for jail. You should reconfigure those and any other servers running on the host that would listen on the jail's IP.
edit /usr/local/etc/ezjail/JAIL_NAME and change the jail_JAIL_NAME_hostname setting to JAIL_HOST_NAME.
Start the jail by running ezjail-admin start JAIL_NAME. You'll see messages like the following:
Start a root console for the jail by running ezjail-admin console JAIL_NAME.
Here's how to configure the jail in general:
::1 localhost JAIL_HOST_NAME.(optional domain name) JAIL_HOST_NAME
JAIL_LOOPBACK_ADDRESS localhost JAIL_HOST_NAME.(optional domain name) JAIL_HOST_NAME
Install BIND 9.0 by running make -C /usr/ports/dns/bind99 install clean.
This build will build the following dependencies:
Next, edit /usr/local/etc/namedb/named.conf.
Next, edit /etc/rc.conf (you may need to create it) by adding the line:
add named_enable="YES"
Next, start the name server by running service named start.
Test the name server by running /usr/local/bin/dig @JAIL_IP freebsd.org.
Start having the host computer resolve using the jailed BIND server by editing /etc/resolv.conf to change the nameserver entry to JAIL_IP.
Then, test name resolution on the host computer.
If you want to see logs of your jailed namedb daemon, in the root console for the jail, do the following:
Run as root on the host (don't since this doesn't seem to work):
Error messages of the form touch: /usr/jails/newjail//boot/kernel.old/.freebsd-update: No such file or directory when running the ezjail-admin update -U command above
Periodically, one must audit the packages in the jail to ensure that they do not contain security vulnerabilities, updating them if so. Do this by:
Why doesn't running ezjail-admin update -u work?
What about running ezjail-admin update -p or ezjail-admin update -P?
If there are vulnerable packages in the jail, update the jail's ports collection as follows:
Software development | Tutoring | Computer Security | Video | Contact |