Friday 4 October 2013

Raspberrypi DNS Server

installation

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

configuration

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)

/etc/dnsmasq.conf

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)
domain-needed

# won't forward some non-routed addresses
bogus-priv

# won't forward requests for your intranet subdomain
local=/lan.mydomain.com/
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
expand-hosts

# appended to DHCP hosts and, if above option specified, to hosts from static IPs
domain=lan.mydomain.com
If you want to use the /etc/ethers file (see section farther down) add this option:
read-ethers
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.

/etc/resolv.conf

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.

/etc/hosts

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 mydevice.lan.mydomain.com, only specify mydevice.
192.168.1.301 mynas
192.168.1.302 webserver

/etc/ethers

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:
00:00:00:00:00:00 192.168.0.200
00:00:00:00:00:01 192.168.0.201

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

Amazon

Donate

Donate Towards More Raspberry PI's for Projects