Creating a basic DNS Server in Solaris 11

Create a zone (optional)

I created a zone to hold my temporary DNS server so it was quick and easy to remove at the end of the testing

root@sc5acn02-d1:~# zfs create -o mountpoint=/zones rpool/zones
root@sc5acn02-d1:~# zonecfg -z dns-zone
Use 'create' to begin configuring a new zone.
zonecfg:dns-zone> create
create: Using system default template 'SYSdefault'
zonecfg:dns-zone> set zonepath=/zones/dns-zone
zonecfg:dns-zone> commit
zonecfg:dns-zone> exit
root@sc5acn02-d1:~# zoneadm -z dns-zone install
The following ZFS file system(s) have been created:
    rpool/zones/dns-zone
Progress being logged to /var/log/zones/zoneadm.20140523T153804Z.dns-zone.install
       Image: Preparing at /zones/dns-zone/root.



Boot the zone
# zoneadm -z dns-zone boot

Login to the console and setup the network interfaces
# zlogin -C dns-zone

Configure DNS

Install  the BIND dns package

root@dns-zone:/var/tmp# pkg install service/network/dns/bind

Use the h2n script to convert a host based setup to a bind dns setup (I got my copy from ftp://ftp.hpl.hp.com/pub/h2n/h2n.tar.gz)

./h2n -d load.melnet.net -n 138.3

Create your named.conf file

options {
        directory       "/etc/namedb/working";
        pid-file        "/var/run/named/pid";
        dump-file       "/var/dump/named_dump.db";         
    statistics-file "/var/stats/named.stats";
};

zone "load.melnet.net" {
        type master;
        file "/etc/namedb/master/load.db";
};
zone "3.138.in-addr.arpa" {
        type master;
        file "/etc/namedb/master/3.138.db";
};

root@dns-zone:/var/tmp# mkdir -p /etc/namedb/working
root@dns-zone:/var/tmp# mkdir /var/run/named
root@dns-zone:/var/tmp# mkdir -p /var/dump
root@dns-zone:/var/tmp# mkdir -p /var/stats
root@dns-zone:/var/tmp# mkdir -p /etc/namedb/master
root@dns-zone:/var/tmp# cp db.load /etc/namedb/master/load.db
root@dns-zone:/var/tmp# cp db.138.3 /etc/namedb/master/3.138.db

My files looked like this

# cat /etc/namedb/master/load.db
@ IN  SOA dns-zone.load.melnet.net. root.dns-zone.load.melnet.net. ( 1 10800 3600 604800 86400 )
  IN  NS  dns-zone.load.melnet.net.

localhost            IN  A     127.0.0.1

dns-zone             IN  A     138.3.1.39
dns-zone             IN  MX    10 dns-zone.load.melnet.net.

host-17-128          IN  A     138.3.17.128
host-17-128          IN  MX    10 host-17-128.load.melnet.net.


root@dns-zone:/etc/namedb/master# cat /etc/namedb/master/3.138.db
@ IN  SOA dns-zone.load.melnet.net. root.dns-zone.load.melnet.net. ( 1 10800 3600 604800 86400 )
  IN  NS  dns-zone.load.melnet.net.

39.1.3.138.IN-ADDR.ARPA.        IN  PTR   dns-zone.load.melnet.net.
128.17.3.138.IN-ADDR.ARPA.      IN  PTR   host-17-128.load.melnet.net.

Setup a client to your dns

svccfg -s /network/dns/client setprop config/nameserver = net_address: 138.3.1.39
svccfg -s /network/dns/client setprop config/domain = astring: "load.melnet.net"
svccfg -s /network/dns/client setprop config/search = astring: "load.melnet.net"
svccfg -s /network/dns/client setprop config/ipnodes = astring: '"files dns"'
svccfg -s /network/dns/client setprop config/host = astring: '"files dns"'

Verify the configuration is correct:

root@dns-zone:/etc/namedb/master# svcadm enable dns/client
root@dns-zone:/etc/namedb/master# nslookup host-17-128
Server:         138.3.1.39
Address:        138.3.1.39#53

Name:   host-17-128.load.melnet.net
Address: 138.3.17.128

root@dns-zone:/etc/namedb/master# nslookup 138.3.17.128
Server:         138.3.1.39
Address:        138.3.1.39#53

128.17.3.138.in-addr.arpa       name = host-17-128.load.melnet.net.

Adding new records to your DNS

You have a couple of ways to add new records to your dns.. you can

1) Add the new entries to your host file and re-run h2n
2) Manually add entries to the load.db and 3.138.db files

and then refresh/restart the dns service.

To manually add a new host to the DNS  sc5a02-d2 138.3.17.172/etc/namedb/master/

Add a ‘forwards’ entry to /etc/namedb/master/load.db

sc5a02-d2            IN  A     138.3.17.172
sc5a02-d2            IN  MX    10 sc5a02-d2.load.melnet.net.

Add a reverse entry to /etc/namedb/master/3.138.db

172.17.3.138.IN-ADDR.ARPA.      IN  PTR   sc5a02-d2.load.melnet.net.

refresh and restart the server

root@dns-zone:/etc/namedb/master# svcadm refresh /network/dns/server
root@dns-zone:/etc/namedb/master# svcadm restart /network/dns/server

Test it forwards and backwards.

root@dns-zone:/etc/namedb/master# nslookup 138.3.17.172
Server:         138.3.1.39
Address:        138.3.1.39#53

172.17.3.138.in-addr.arpa       name = sc5a02-d2.load.melnet.net.

root@dns-zone:/etc/namedb/master# nslookup sc5a02-d2
Server:         138.3.1.39
Address:        138.3.1.39#53

Name:   sc5a02-d2.load.melnet.net
Address: 138.3.17.172

Appendix

Manually creating entries is a bit of a pain though if you have a lot of them. I’ve done a very dumb script here to generate entries..

#!/bin/sh
# quick generate DNS entries script
# accepts host and IP, produces entries for files
#Fixed variables
DOMAINER=load.melnet.net
HOSTER=$1
IPPER=$2
echo "Forwards entry"
echo "$HOSTER       IN  A             $IPPER"
echo "$HOSTER       IN  MX            10 ${HOSTER}.${DOMAINER}."

echo "Backwards entry"
BACKWARDSIP=`echo $IPPER | awk -F. '{print $4 "." $3 "." $2 "." $1}'`
echo "${BACKWARDSIP}.IN-ADDR.ARPA.     IN  PTR  ${HOSTER}.${DOMAINER}."

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s