Friday, 4 October 2013

Raspberrypi DNS Server


Through the magic of Debian, installing dnsmasq is as simple as:
sudo apt-get install dnsmasq


For my setup, dnsmasq configuration happens in the following files: * /etc/dnsmasq.conf - dnsmasq specific configuration * /etc/resolv.conf - DNS to forward to (and the one used by the server running dnsmasq) * /etc/hosts - host names for static IPs * /etc/ethers - manually assigned IPs specified as MAC to IP mappings (optional)


This configures how the DNS server and the DHCP provider (if enabled) should behave. I'll discuss the main options I used, but the example configuration file provided with the install has good documentation.
Some domain lookups are essentially guaranteed to come up empty on the wider Internet. You can disable forwarding of them with the following lines:
# won't forward unqualified names (e.g. myserver)

# won't forward some non-routed addresses

# won't forward requests for your intranet subdomain
That last one is key. It forces that subdomain to be resolved only via internal config: the hosts file or DHCP clients.
To specify the root subdomain for your intranet, use the following two options:
# append the domain (below) to all hosts in the hosts file

# appended to DHCP hosts and, if above option specified, to hosts from static IPs
If you want to use the /etc/ethers file (see section farther down) add this option:
The rest is DHCP config. I copied it from my router's dnsmasq config, so I don't know much about all of the options.
NOTE: If you do enable DNS via dnsmasq, you should shut off the DHCP on your router. After an IP refresh, your DHCP clients should all work fine.


In my network, this points to my router. I would expect that is the normal setup, but your mileage may vary. The file's only contents are the IP of the DNS server to point to.


You'll want to leave the existing contents, but add the host names for any of your devices using static IPs. You do not need every device listed in here, just the ones you want to be addressable via a domain name.
Format is <IP> <host name>, and the host name should only be the lowest level qualifier of the host (not the full domain name). For example, if you want a device to be, only specify mydevice. mynas webserver


This is only needed if you have a few devices you want to assign static IPs to, but can't or don't want to configure the static IP on the devices themselves.
This is simply a <MAC> <IP> formatted file, with one mapping per line, for example:

final thoughts

As neat as it is, the benefits of domain names internally are pretty minimal. I already had the handful of static IPs I use memorized, but it will be nice to have a friendlier name to use. I do like having domains for the DHCP clients, however, since it removes the need to look up the IP beforehand.

No comments:

Post a Comment



Donate Towards More Raspberry PI's for Projects