Difference between revisions of "Centralised Local DNS"
(How to centrally manage local DNS with custom domain names) |
|||
Line 5: | Line 5: | ||
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: | 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: | ||
− | + | {{Code| | |
+ | Code=zone "test.mydomainname.com" { | ||
type master; | type master; | ||
file "/etc/bind/test.mydomainname.com"; | file "/etc/bind/test.mydomainname.com"; | ||
allow-query {any;}; | 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. | 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. | ||
Line 17: | Line 19: | ||
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: | 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: | ||
− | + | {{Code| | |
+ | Code=$TTL 604800 | ||
@ IN SOA ns.test.mydomainname.com. test.mydomainname.com. ( | @ IN SOA ns.test.mydomainname.com. test.mydomainname.com. ( | ||
1 ; Serial | 1 ; Serial | ||
Line 27: | Line 30: | ||
@ IN NS test.mydomainname.com. | @ IN NS test.mydomainname.com. | ||
test.mydomainname.com. IN A 192.168.0.40[/code] | test.mydomainname.com. IN A 192.168.0.40[/code] | ||
− | + | }} | |
Here are some things to note about this: | Here are some things to note about this: |
Revision as of 20:31, 15 November 2012
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:
bash code |
---|
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 can be internal (ie wherever I'm 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:
bash code |
---|
$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[/code]
|
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 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".