Internal DNS server on CentOS 6
I went a long time just editing hosts files on the machines on my network. That works just fine, but the more machines you add, the more hosts files you need to edit.
What about mobile devices? I need to be able to test some sites and web apps on mobile devices as well. So I decided it was time to setup an internal DNS server.
I have an existing Centos 6 box that I will use as a DNS server.
Setting up BIND
yum install bind bind-chroot bind-utils
Edit the config file
vim /etc/named.conf
Change these lines
listen-on port 53 { any; };
allow-query { any; };
After allow-query add Google's public DNS servers to foward requests
forwarders { 8.8.8.8; 8.8.4.4; };
My home network will be on the domain home.local, you can setup whatever you like.
At the bottom of this file, I added two zones right after the existing zone. One is the name to IP address lookup, the other is reverse, IP address to name lookup. Replace "home.local" in the first line to whatever you want your internal domain to be.
zone "home.local" IN {
type master;
file "master.home.local";
allow-update { none; };
};
zone "0.168.192.in-addr.arpa" IN {
type master;
file "reverse.192.168.0";
allow-update { none; };
};
Next we will create the two zone files that are reference in the file option above. My main file for the home.local zone is called master.home.local.
vim /var/named/chroot/var/named/master.home.local
$TTL 1d
@ IN SOA .home.local. paul.home.local. (
2014071900 ; se = serial number
3h ; ref = refresh
15m ; ret = update retry
3w ; ex = expiry
3h ; min = minimum
)
IN NS .home.local.
;local network hosts
ns IN A 192.168.0.10
devserver IN A 192.168.0.11
otherserver IN A 192.168.0.12
alias IN CNAME devserver
Use A records to setup unique IP's on the network. When you want a new name to point to an existing record, use the CNAME record.
Now we setup the reverse file. I called mine reverse.192.168.0.
vim /var/named/chroot/var/named/reverse.192.168.0
$TTL 1d
@ IN SOA .home.local. paul.home.local. (
2014071900 ; se = serial number
3h ; ref = refresh
15m ; ret = update retry
3w ; ex = expiry
3h ; min = minimum
)
IN NS .home.local.
;local network hosts
10 IN PTR ns.home.local
11 IN PTR devserver.home.local
12 IN PTR otherserver.home.local
Because we're using the /var/named/chroot/var/named folder for our zone files, I had to copy the existing files to the same folder. The files named.ca, named.empty, named.localhost and name.loopback all need to be moved.
cp /var/named/named.* /var/named/chroot/var/named/
Finally, permissions. named needs to be able to access the zone files.
chown named.named /var/named/chroot/var/named/*
Start the service
/etc/init.d/named start
Make sure it starts automatically
chkconfig named on
Pushing the DNS to devices on the local network
Now that the DNS server is running, we want all local devices to be able to use it. For devices that have a static IP, you can just set the DNS Server manually. On Centos you can edit the resolve.conf.
domain home.local
nameserver 192.168.0.10
Make sure to set the domain, then you don't need to access the resources with the domain at the end. So you can use http://devserver instead of http://devserver.home.local
For devices that use DHCP you'll have to set your DHCP server to use your internal DNS server as one of the DNS servers, and give it the domain.
I'm using my router as a DHCP server, so it's easy enough to tell it which DNS servers and domain to use in the router control panel. I use my internal DNS + Google's public DNS servers.