Currently the DNS services are hosted outside using Hosting services from other company, so the main target is to bring back the DNS services inside our office and using our own server.

We choose OpenBSD 5.2 for its lightweight and secure by default. Since we only have one machine at this moment (or maybe for quite a long time), we will be using the same machine to be our Web Server, and also our DNS server (which will acts as our primary and also secondary DNS server – by using alias on the network interface). This machine will be located in the DMZ zone behind the firewall – which we use Fortigate-60M firewall appliance.

The overall basic setup will looks like diagram below.

We have changed the registered IP into new IP for this entry purposes, Assuming the registered ip address for hosts:

firewall/gateway registered ip is

mail server registered ip is and the internal DMZ ip is

the web server which will also act as the DNS Server, physically only one machine will hold two ip addresses, the registered ip for DNS and while the internal DMZ ip addresses is and (alias)

Basically the IP address will looks like below:

Firstly, all the references website that we use in order to setup, install and configure our server.

The packages/software:

The installation guides:

The O/S:

Now the steps.

1. prepare, download and install the operating system, the OpenBSD 5.2, and set the as the main IP address for the network interface. Make sure you put more space for the /var filesystem, since we will be using /var a lot, so we put around 120GB for the /var.

After the installation finish, reboot/restart the server. log-in as root and create alias IP for the network interface for the second IP address

The file to edit is /etc/hostname.bge0 (the .bge0 is the network interface name of our server, do a “ls -al /etc/hostname.*” to see your actual filename). Below are our /etc/hostname.bge0 entry. (refer to:

# cat /etc/hostname.bge0
inet alias

To be sure, reboot the server, and log-in back as root, do a “ping” to both IP address or use “ifconfig” to see all the network interface.

2. Configure the nginx Web Server, it should comes with the OpenBSD, and the config file should be in the /etc folder. By default the web directory is located at /var/www.

3. Now comes to the TinyDNS installation.

Main reference site for the TinyDNS installation is the, but to install two TinyDNS services on one OpenBSD machine (with alias IP) we extend the references to the

a. download and install the daemontools-0.76.tar.gz

b. download and install the ucspi-tcp-0.88.tar.gz

c. then download and install the djbdns/tinydns
d. add the group for dns

# groupadd -g 151 dns

e. add user: tinydns and dnslog

# useradd -g 151 -u 151 -d /nonexistent -c "tinydns" -s /sbin/nologin tinydns
# useradd -g 151 -u 152 -d /nonexistent -c "tinydns" -s /sbin/nologin dnslog

f. To run two tinydns services on one machine:

The syntax is:
# tinydns-conf tinydns dnslog /var/tinydns IP

where tinydns-conf is the utilities to setup the tinydns services, the user account to use is “tinydns” and the user account “dnslog” that will log all the queries and errors, “/var/tinydns” is the directory where the service is located, lastly the IP is the IP address the service will listen to.

for the first nameserver:
/usr/local/bin/tinydns-conf tinydns dnslog /var/tinydns1

for the second nameserver:
/usr/local/bin/tinydns-conf tinydns dnslog /var/tinydns2

We choose /var folder to standardise the location since the Web services is also using the /var. As you can see, the IP address that the services should listen to is the IP address DMZ and NOT the registered ip address. The registered IP address will be mapped to this DMZ IP address by the Firewall.

then the link:

ln -s /var/tinydns1 /service
ln -s /var/tinydns2 /service

Once you have done this, the services will be up, check the process using “ps -aux”, you should see both tinydns running, or you can check the tinydns log file in both /var/tinydns1/log/main/current and /var/tinydns2/log/main/current, you should see a line with “starting tinydns”.

Now we should add the DNS information.

There are two ways to add the DNS information, Manually or use the utilities command provided. We follow the Manually method as it’s much more fater and easier. Modify the /var/tinydns1/root/data file to look like this:

# -- name servers

# — hosts


Of course the domainname should be your domainname, and as you can see, all the IP address in the file must be the Registered IP address, NOT the DMZ IP address.

Copy the /var/tinydns1/root/data to the second service folder /var/tinydns2/root – override the data file in that folder. To make sure everything will start correctly, Reboot/Restart the server.

Once everything is startup OK, we need to look into one more service, the Packet Filtering or the “pf”, this service will startup by default on OpenBSD, so we need to create a rule to open/allow the DNS service to this server.

Since our server is behind the firewall so we decided to open all first, and then later on (someday) will restrict it. If we just let the default “pf” setting, the DNS services will be blocked – when do a port scanning from outside you will received something like “connection refused” instead of closed. So to open all, add the following lines into “/etc/pf.conf”

pass in log quick keep state
pass out log quick keep state

and as usual, to make sure everything will start correctly, restart/reboot the server.

4. Now the only thing left is to add the “Virtual IP” in the fortigate firewall to map the DNS service for Registered IP to and to, and add a firewall Policy to all DNS service (tcp/udp) from WAN to the DMZ (specific to the server and as of now you can test the DNS server from outside using the “dig @” and “dig @”, because we need one more step complete it.

Log-in to your ISP provider where your domain is registered, and change the NameServer IP address to the new registered IP address in this case the Primary DNS ( to and the Secondary DNS ( to

You might need to wait for a few hours to it to be escalated. After that you can test the DNS from outside just using “dig” without the specific IP address server, if everything OK, you should get the expected returns.

Happy New Year and Happy trying !

Tags: , , , , , , , , , , ,

One Response to “Setting up DNS Server Using TinyDNS/djbdns on OpenBSD behind Firewall”

  1. Özgür Kazançç? says: