dnsmasq

My router has a DHCP server which assigns IP addresses to my different devices. Each device (DHCP client) in the LAN has a unique MAC address which they will broadcast to the network when they boot. The DHCP server listens to these broadcasts and responds with an IP address. It also takes care of the book keeping, mapping MAC addresses to IP addresses.

dhcp-01

This works fine and it allows me to access the Red Pitaya if I know the IP address. However, it would be even better if I could give each device an easy to remember name. So instead of:

$ ssh 192.168.1.107

I could say:

$ ssh redpitaya

In the internet so called DNS (Domain Name System) servers are used to map names to IP addresses so that e.g. we can access web sites using names instead of hard to remember IP addresses.

I could install my own local full-blown DNS server but that would be an overkill if all I want is a simple name to address mapping. Luckily all linux distributions have a simpler alternative called dnsmasq. Basically it combines two servers: a DHCP server and a DNS server, but still it is quite easy to setup. The nice thing about it is that when the DHCP server assigns an IP address it can also pass the IP address and a name to the DNS server. And when the DHCP server responds to the client with the IP address it can also tell the client to use the same server as a DNS server.

As I already have a linux mint box I just need to configure the dnsmasq, disable the DHCP server in my router and start the dnsmasq. My network topology would change to:

dhcp-02

The dnsmasq settings are stored in /etc/dnsmasq.conf. Let’s assume:

  • the linux box has a static address 192.168.1.25
  • the router has a static address 192.168.1.1
  • we want to reserve the addresses .100-.199 for the DHCP server.
  • Red Pitaya MAC address is  00:26:32:f0:aa:bb

Then the following settings could be used:

interface=eth0
except-interface=lo
dhcp-range=192.168.1.100,192.168.1.199,12h
server=192.168.1.1
dhcp-host=00:26:32:f0:aa:bb,redpitaya
dhcp-option=option:router,192.168.1.1
dhcp-option=option:dns-server,192.168.1.25
dhcp-option=option:domain-name,home

The dhcp-host setting assigns a name to a MAC address. The dhcp-option settings specify what information the DHCP server sends to the clients (=dhcp-hosts).

On linux mint I can start the server with:

$ sudo service dnsmasq start

For more details please check:

$ man dnsmasq

Now if I boot my laptop it will get an IP address from the dnsmasq and it will use dnsmasq for name resolution. I can check this by running ipconfig.

C:\> ipconfig /all

Wireless LAN adapter Wireless Network Connection:

 Connection-specific DNS Suffix  . : home
 Description . . . . . . . . . . . : Intel(R) Wireless WiFi Link 4965AGN
 Physical Address. . . . . . . . . : 00-1D-E0-93-CC-DD
 DHCP Enabled. . . . . . . . . . . : Yes
 Autoconfiguration Enabled . . . . : Yes
 IPv4 Address. . . . . . . . . . . : 192.168.1.123(Preferred)
 Subnet Mask . . . . . . . . . . . : 255.255.255.0
 Default Gateway . . . . . . . . . : 192.168.1.1
 DHCP Server . . . . . . . . . . . : 192.168.1.25
 DNS Servers . . . . . . . . . . . : 192.168.1.25
 NetBIOS over Tcpip. . . . . . . . : Disabled

And by the way I can still browse the internet because the dnsmasq will forward all queries for unknown names to my router (which has the DNS info from my ISP).

Leave a Reply

Your email address will not be published. Required fields are marked *