DNSMasq – How DNSMasq Integrates with Routers

dhcpdnsmasqdomain-name-systemlinuxrouter

Context

I've successfully installed DNSMasq on a Debian machine and everything seems to be working. Here's what I did:

  1. install DNSMasq with sudo apt-get install dnsmasq

  2. update file /etc/dnsmasq.d/home.dns with the following contents:

     # General configuration
     domain-needed
     bogus-priv
     domain=dummy.home
     dhcp-range=192.168.0.10,static,48h
     dhcp-option=3,192.168.0.1
    
     # Device IPs
     dhcp-host=00:00:5e:00:52:41,desktop,192.168.0.10
     dhcp-host=00:00:5e:00:52:12,android,192.168.0.11
    

192.168.0.1 is my ISP router's IP.

  1. turn off DHCP on my ISP router
  2. restart DNSMasq service with sudo service dnsmasq restart

That's all great, but I'm new to networking and have a bunch of questions:

  1. how does DNSMasq communicate with the router? I mean, how does it tell the router that it should start using DNSMasq's DHCP server from that point on? Is there a specific protocol for that, whereby DNSMasq communicates with the router, or is it DHCP itself?

  2. why didn't I have to configure my devices (an android phone and a desktop computer) to use DNSMasq's DNS server? [The answer to this one may be the same as from the question above, but anyways…]

  3. is there a way of using DNSMasq for DNS only and have the router's DHCP server "talk to" or "use" DNSMasq's DNS server? This way I wouldn't need to turn the router's DHCP server off.

As I said, I'm a newbie, but I couldn't find answers to these questions anywhere on the web.

Best Answer

DNSmasq does not need to communicate with your router. The DNSmasq service just took over the service of DNS and DHCP and your router does not have to provide that anymore. Since you have disabled the DHCP service on your router, only the DHCP server of the computer running DNSmasq will answer DHCP requests.
Your DHCP clients (android phone and desktop) get all needed information from the DHCP server, like IP address and netmask, DNS server and default router. From man dnsmasq:

By default, dnsmasq sends some standard options to DHCP clients, the netmask and broadcast address are set to the same as the host running dnsmasq, and the DNS server and default route are set to the address of the machine running dnsmasq.

In your case, you have set

dhcp-option=3,192.168.0.1

which tells the clients to use 192.168.0.1 as the default route. DNSmasq will also pick up the configuration in /etc/resolv.conf form the machine it is running to configure upstream DNS servers to resolve addresses outside your LAN.

You can run the DHCP server on a different server than your DNS server is running. But you will have to keep track of the clients and their IPs and corresponding names. In small networks you can easily assign static IP addresses and names, but that is nothing you want to do. There is also the option to dynamically update the DNS records from the DHCP server which is called dynamic DNS updates (DDNS) but needs a bit more configuration.

Related Topic