Linux – DNS server information not provided to DHCP clients by dnsmasq

dhcp-serverdnsmasqdomain-name-systemlinuxraspbian

I am trying to utilize a Raspberry Pi with Raspbian Stretch (Linux) so provide additional network monitoring and also routing capabilities. To this end I have the following setup:

Internet router [eth1]
  ||
[Raspberry Pi]
  ||
Wifi for clients [wlan0]
Ethernet for clients [eth0] 

I have basically got everything working, except for assigning the DNS servers to the DHCP clients. I have been struggeling with this topic for many weeks now, followed dozens of guides on this site and others but regardless of whether I use dhcpd + dnsmasq, dnsmasq alone, bind or whatever: the DNS server is not assigned to the client. I also tried various operating systems on the clients: Windows, Ubuntu and Android, to make sure it isn't a setup problem there. But they work with all other LAN/Wifi networks and not with this setup, so it must be a problem with my configuration. The problem is the same for LAN and Wifi devices. Wifi is provided by hostapd, btw, and works.

My latest setup only utilizes dnsmasq. The clients that are thus assigned addresses via DHCP can

  • Access intranet and internat IP addresses (ping, tracert, nmap)
  • Reach the DNS server on my RPI (port open and reachable)
  • Reach other clients in the network, and vice-versa

My dnsmasq.conf file:


bogus-priv
expand-hosts
dhcp-authoritative
no-resolv    
interface=wlan0
interface=eth0
interface=lo
interface=eth1    
dhcp-range=192.168.19.30,192.168.19.160,1h    
bind-interfaces    
dhcp-option=option:dns-server,0.0.0.0,192.168.19.1,192.168.19.2,192.168.178.20
dhcp-option=3,192.168.19.1    
listen-address=127.0.0.1
listen-address=192.168.19.1
listen-address=192.168.19.2
listen-address=192.168.178.20    
server=192.168.178.1
server=8.8.8.8    
cache-size=1000    
log-queries
domain="mydomain.biz"

Since the system is using systemd, I have also setup the files wlan0.network, eth0.network and eth1.network in /etc/systemd/network. eth1 assigns a fixed IP, for wlan0 and eth0 I have


[Match]
Name=eth0

[Network]
Address=192.168.19.2/24
DHCPServer=yes

and


[Match]
Name=wlan0

[Network]
Address=192.168.19.1/24
DHCPServer=yes

It also does not matter if I add something like "DNS=192.168.19.1" to the .network files…
I really do not know what else I can do or what the problem might be.
Thanks in advance!

Best Answer

Solution I have found that works for me:

In /etc/dnsmasq.conf (or other conf file) put the following:

# Set DNS server offered to clients(dnsmasq sometimes fails to do it automatically?)   
dhcp-option=6,192.168.1.1

... replacing 192.168.1.1 with the IP address of your dnsmasq service (and/or other IP addresses as required).

My dnsmasq was previously working fine, clients getting correct DNS server (dnsmasq IP) via DHCP. Then for no apparent reason, clients were not getting DNS server info, so their DNS lookups failing. I guess some configuration change triggered this, possibly the fact that I moved dnsmasq's port from the standard 53 to 1053 because I put another DNS server at 53 (specifically adguard-home). I still had dnsmasq providing DHCP, and the primary DNS server using dnsmasq as its upstream DNS. It would seem that something about this configuration (I would guess the port 1053 change) triggered an issue/bug in dnsmasq.

Related Topic