Centralised Local DNS

From Amahi Wiki
Revision as of 03:11, 16 November 2012 by Bigfoot65 (talk | contribs)
Jump to: navigation, search

If you've ever wanted to create DNS entries on your local network so that, for example, you can test a website you've been developing on an iDevice, you probably had to point your iDevice to a web proxy that would then redirect you to the right place. Or, if you wanted to test the said website from your laptop, you would have likely had to add entry in your laptop's "hosts" file so that the laptop would know that test.your-domain-name.com should go to 192.168.1.50.

However, this is all a bit tedious, and it means you're either editing loads of host files (one for each machine), or worse. Wouldn't it be good if you could set all this in a central place - and what better central place than your Amahi box! The result would be that you could set up internal dns entries for such purposes, and it'll work for both fixed IP machines and WiFi machines on your network. It's reasonably simple to do...

Amahi uses "Bind" for its DNS, and Bind looks to the file /etc/named.conf for DNS-related configurations. You'll see in there some stuff that Amahi is in control of (eg the "zone" used by your network, et "home.com"). At the very bottom, you should see an include to "/etc/named.conf.local". This is where our magic will start. Basically, as su (or sudo) you need to open up this file and place an entry like this:

Text
​zone "test.mydomainname.com" { type master; file "/etc/bind/test.mydomainname.com"; allow-query {any;}; };​

What this does is tell Bind that, for the domain "test.mydomainname.com", you want to go to the file "/etc/bind/test.mydomainname.com" to look up the configuration.

NOTE: Notice that there's a "test." prefix on the domain. This is so that the test server will be internal machine (ie wherever we are going to point it to in the above-mentioned conf file) without affecting how other subdomains of the same domain. So "www.mydomainname.com" will still go to the live website (if that's what you wanted!).

Right, now create the following folder: "/etc/bind/". In here, you can store all the config files for each "zone" you want to configure. Once you've done that, you can create the config file "/etc/bind/test.mydomainname.com". The contents of this should be like this:

Text
​$TTL 604800 @ IN SOA ns.test.mydomainname.com. test.mydomainname.com. ( 1 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS test.mydomainname.com. test.mydomainname.com. IN A 192.168.0.40​

Here are some things to note about this: 1) This will redirect all calls to "test.mydomainname.com" to the IP address 192.168.0.40 2) For some reason, on the 2nd line, I had to have 2 domains listed there, the 1st one being prefixed by "ns.". I don't quite know why, but Bind didn't like it if I only had the 1 domain there, and hence the above is what I needed for it to work for me. 3) Note also that all domain references have a final "." at the end!! This is important! So, instead of "test.mydomainname.com", it must be "test.mydomainname.com."

Right, once this is done, you'll need to restart your DNS server. I use the following command from the command line as a super user: service named restart

Of course, you can also do this through the HDA control panel (go to HDA Setup, and then "Settings" from the tab bar, and then "Servers" from the sub tab bar. Expand the bit for "DNS Server" and click on "restart".