I want to run dnsmasq on my local machine in order to configure a wildcard to resolve to 127.0.0.1 for testing purposes.
However, when I went to start dnsmasq with systemd I got the following error message:
[root@dhcppc4 ~]# systemctl status dnsmasq -l ● dnsmasq.service - DNS caching server. Loaded: loaded (/usr/lib/systemd/system/dnsmasq.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Fri 2015-10-09 21:49:58 BST; 14s ago Process: 2652 ExecStart=/usr/sbin/dnsmasq -k (code=exited, status=2) Main PID: 2652 (code=exited, status=2) Oct 09 21:49:58 dhcppc4 systemd: Started DNS caching server.. Oct 09 21:49:58 dhcppc4 systemd: Starting DNS caching server.... Oct 09 21:49:58 dhcppc4 dnsmasq: dnsmasq: failed to create listening socket for port 53: Address already in use Oct 09 21:49:58 dhcppc4 systemd: dnsmasq.service: main process exited, code=exited, status=2/INVALIDARGUMENT Oct 09 21:49:58 dhcppc4 systemd: Unit dnsmasq.service entered failed state. Oct 09 21:49:58 dhcppc4 systemd: dnsmasq.service failed.
Confused as to how port 53 is taken with no current DNS server running (and confirmed with
dig @127.0.0.1), I ran
netstat -ln and found a process listening on port 53 on address
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN udp 0 0 192.168.122.1:53 0.0.0.0:*
An ifconfig shows that
192.168.122.1 is the virtual interface virbr0.
A quick Google search and wiki later, I understand that libvirt provides virtual networking to the host in order to abstract physical interfaces. Libvirt uses a virtual network switch through which all traffic is routed . The default virtual network switch, virbr0, is created when the daemon first starts.
I can then confirm that I can send queries via DIG to dnsmasq on this interface:
[grobinson@dhcppc4 ~]$ dig @192.168.122.1 +short a.root-servers.net. j.root-servers.net. m.root-servers.net. b.root-servers.net. i.root-servers.net. k.root-servers.net. l.root-servers.net. d.root-servers.net. g.root-servers.net. c.root-servers.net. h.root-servers.net. e.root-servers.net. f.root-servers.net.
Question 1: I don't understand the reason behind having dnsmasq listen on this virtual interface? For /etc/resolv.conf I can see that the DNS servers configured at the DHCP server tell the machine to direct queries to Google DNS servers. What is its use?
# Generated by NetworkManager nameserver 184.108.40.206 nameserver 220.127.116.11
I find that I can edit
/etc/NetworkManager/NetworkManager.conf and add the line
dns=dnsmasq and then restart network manager with systemd. From here on network manager is configured to direct queries to dnsmasq on the loopback address and can be seen with a simple call to dig:
[grobinson@dhcppc4 ~]$ dig @127.0.0.1 +short l.root-servers.net. g.root-servers.net. i.root-servers.net. ...
netstat -ln output now shows two sockets bound and listening on port 53:
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
Question 2: how come network manager can start dnsmasq on 127.0.0.1 and I can't with systemctl? Is that because the default configuration is attempting to listen on all interfaces, which fails for virbr0? I just need to state the desired interface?
Question 3: It looks like there are two configuration options for dnsmasq:
/etc/dnsmasq.conf and a folder
/etc/NetworkManager/dnsmasq.d/ where configuration files can be written. It looks like the latter is for when
dns=dnsmasq is set and dnsmasq listening on 127.0.0.1 since editing
/etc/dnsmasq.conf has no effect on queries to @127.0.0.1. Could the former be for dnsmasq in libvirt?