How to install and configure DNS

Install DNS

sudo apt-get install -y bind9 bind9-doc

Configure Forwarders

sudo vi /etc/bind/named.conf.options
forwarders {;;

Now configure the domain

Add the DNS zones

sudo vi /etc/bind/named.conf.local
zone "internal" {
type master;
notify no;
file "/etc/bind/db.internal";
zone "" {
type master;
notify no;
file "/etc/bind/db.0.0.10";

Create the actual zone files.
Tip, Use the date format for the serial yyyymmddss (where ss is the serial number)

sudo cp -p /etc/bind/db.local /etc/bind/db.internal
sudo vi /etc/bind/db.internal
; BIND data file for internal domain
$TTL    604800
@       IN      SOA     ns.internal. root.internal. (
2010122701         ; Serial
604800         ; Refresh
86400         ; Retry
2419200         ; Expire
604800 )       ; Negative Cache TTL
@       IN      NS      myth.internal.
; Management (10.0.0)
; Servers
homer           IN      A
marge           IN      A
printer         IN      A
wireless        IN      A
myth            IN      A
frame           IN      A
jumpstart       IN      A
; Server roles
proxy           IN      CNAME   myth
time            IN      CNAME   myth
ns              IN      CNAME   myth
mythtv          IN      CNAME   myth
web             IN      CNAME   myth
; Domains
lazygeek        IN      CNAME   myth
abacushill      IN      CNAME   myth
muggridge       IN      CNAME   myth
; Clients
bart            IN      A
barney          IN      CNAME   barney-wireless
barney-fixed    IN      A
barney-wireless IN      A
itchy           IN      CNAME   itchy-wireless
itchy-fixed     IN      A
itchy-wireless  IN      A
maggie          IN      CNAME   maggie-fixed
maggie-fixed    IN      A
maggie-wireless IN      A
atom-fixed      IN      A
atom            IN      CNAME   atom-fixed
lisa            IN      A
mini            IN      CNAME   mini-fixed
mini-fixed      IN      A
mini-wireless   IN      A
shell           IN      CNAME   shell-fixed
shell-fixed     IN      A
shell-wireless  IN      A
; Mobile Clients
rob-phone       IN      A
tanya-phone     IN      A
; Other machines
homertest       IN      A
jsflash         IN      A
jstest          IN      A
; DHCP addresses
dhcp-201        IN      A
dhcp-202        IN      A
dhcp-203        IN      A
dhcp-204        IN      A
dhcp-205        IN      A
dhcp-206        IN      A
dhcp-207        IN      A
dhcp-208        IN      A
dhcp-209        IN      A
dhcp-210        IN      A
dhcp-211        IN      A
dhcp-212        IN      A
dhcp-213        IN      A
dhcp-214        IN      A
dhcp-215        IN      A
dhcp-216        IN      A
dhcp-217        IN      A
dhcp-218        IN      A
dhcp-219        IN      A
dhcp-220        IN      A
dhcp-221        IN      A
dhcp-222        IN      A
dhcp-223        IN      A
dhcp-224        IN      A
dhcp-225        IN      A
; Routers, etc
vodafone        IN      A
annex           IN      A
skinner         IN      A

Reverse Zone file

Now create the reverse DNS file

sudo cp -p /etc/bind/db.127 /etc/bind/db.0.0.10
sudo vi /etc/bind/db.0.0.10
; BIND reverse data file for internal domain
$TTL    604800
@       IN      SOA     ns.internal. root.internal. (
2010122701      ; Serial
604800         ; Refresh
86400         ; Retry
2419200         ; Expire
604800 )       ; Negative Cache TTL
@       IN      NS      myth.
; Management (10.0.0)
; Servers
1	IN PTR	homer.internal.
3	IN PTR	marge.internal.
4	IN PTR	printer.internal.
5	IN PTR	wireless.internal.
7	IN PTR	myth.internal.
8	IN PTR	frame.internal.
9	IN PTR	jumpstart.internal.
; Clients
11	IN PTR	bart.internal.
12	IN PTR	barney-fixed.internal.
13	IN PTR	barney-wireless.internal.
14	IN PTR	itchy-fixed.internal.
15	IN PTR	itchy-wireless.internal.
16	IN PTR	maggie-fixed.internal.
17	IN PTR	maggie-wireless.internal.
18	IN PTR	atom-fixed.internal.
19	IN PTR	lisa-fixed.internal.
20      IN PTR  mini-fixed.internal.
21      IN PTR  mini-wireless.internal.
22      IN PTR  shell-fixed.internal.
23      IN PTR  shell-wireless.internal.
; Mobile Clients
30      IN PTR  rob-phone.internal.
31      IN PTR  tanya-phone.internal.
; Other machines
101     IN PTR  homertest.internal.
120     IN PTR  jsflash.internal.
121     IN PTR  jstest.internal.
; DHCP addresses
201	IN PTR	dhcp-201.internal.
202	IN PTR	dhcp-202.internal.
203	IN PTR	dhcp-203.internal.
204	IN PTR	dhcp-204.internal.
205	IN PTR	dhcp-205.internal.
206	IN PTR	dhcp-206.internal.
207	IN PTR	dhcp-207.internal.
208	IN PTR	dhcp-208.internal.
209	IN PTR	dhcp-209.internal.
210	IN PTR	dhcp-210.internal.
211	IN PTR	dhcp-211.internal.
212	IN PTR	dhcp-212.internal.
213	IN PTR	dhcp-213.internal.
214	IN PTR	dhcp-214.internal.
215	IN PTR	dhcp-215.internal.
216	IN PTR	dhcp-216.internal.
217	IN PTR	dhcp-217.internal.
218	IN PTR	dhcp-218.internal.
219	IN PTR	dhcp-219.internal.
220	IN PTR	dhcp-220.internal.
221     IN PTR  dhcp-221.internal.
222     IN PTR  dhcp-222.internal.
223     IN PTR  dhcp-223.internal.
224     IN PTR  dhcp-224.internal.
225     IN PTR  dhcp-225.internal.
; Routers, etc
252     IN PTR  vodafone.internal.
253	IN PTR	annex.internal.
254	IN PTR	skinner.internal.

Storing files in a different location

If you want to keep the bind files on a different device, say a RAID device there’s a few more steps. It is assumed that the structure will be:\\

sudo chown -R root:bind bind

The files that change are:

  • etc\named.conf.options
  • etc\named.conf.local
  • etc\db.internal
  • etc\db.0.0.10

I have used symbolic links from the default /etc/bind directory

cd /etc/named
sudo mv named.conf.options named.conf.options.old
sudo mv named.conf.local named.conf.local.old
sudo ln -s /media/store/apps/bind/etc/named.conf.options
sudo ln -s /media/store/apps/bind/etc/named.conf.local

Last job to do is update app-armor to allow /usr/sbin/named access to these directories

sudo vi /etc/apparmor.d/usr.sbin.named
/etc/bind/** r,
/var/lib/bind/** rw,
/var/lib/bind/ rw,
/var/cache/bind/** rw,
/var/cache/bind/ rw,
# Bind files are on RAID
/media/store/apps/bind/etc/** r,
/media/store/apps/bind/cache/ rw,
/media/store/apps/bind/cache/** rw,

Now update the profile

sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.named

Finally restart bind

sudo /etc/init.d/bind9 restart


Configuring forwarders
Configuring DNS Domain
Ubuntu BIND 9 HowTo
Ubuntu AppArmor HowTo