dnsmasq temporarily breaks DNS resolution when starting for the first time
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dnsmasq (Debian) |
New
|
Undecided
|
Unassigned | ||
dnsmasq (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
The first time that dnsmasq is started, DNS resolution is broken for a few seconds. You can see this on initial installation:
root@phil-test-1:~# apt-get install dnsmasq ; dig github.com
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
dnsmasq
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 0 B/15.1 kB of archives.
After this operation, 111 kB of additional disk space will be used.
Selecting previously unselected package dnsmasq.
(Reading database ... 92556 files and directories currently installed.)
Unpacking dnsmasq (from .../dnsmasq_
Processing triggers for ureadahead ...
Setting up dnsmasq (2.59-4ubuntu0.1) ...
* Starting DNS forwarder and DHCP server dnsmasq [ OK ]
; <<>> DiG 9.8.1-P1 <<>> github.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 56221
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;github.com. IN A
;; Query time: 0 msec
;; SERVER: 127.0.0.
;; WHEN: Mon Nov 4 11:29:16 2013
;; MSG SIZE rcvd: 28
Or you can recreate the problem on an existing installation by removing /var/run/
root@phil-test-1:~# service dnsmasq stop
* Stopping DNS forwarder and DHCP server dnsmasq [ OK ]
root@phil-test-1:~# rm /var/run/
root@phil-test-1:~# service dnsmasq start; dig github.com
* Starting DNS forwarder and DHCP server dnsmasq [ OK ]
; <<>> DiG 9.8.1-P1 <<>> github.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 10196
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;github.com. IN A
;; Query time: 0 msec
;; SERVER: 127.0.0.
;; WHEN: Mon Nov 4 11:31:21 2013
;; MSG SIZE rcvd: 28
The REFUSED status line shows that dns resolution has failed in both cases. I expect that if `apt-get install dnsmasq` or `service dnsmasq start` has returned successfully, and resolvconf has had dnsmasq registered as the sole resolver for lo.dnsmasq, then dnsmasq is ready to respond to DNS requests. Therefore, the REFUSED response from dig is the opposite of what I expect to happen.
In both cases, resolution works again after a few seconds, once resolvconf generates the /var/run/
Even though the window is short (syslog reports ~ 4 seconds of unavailability), this causes me pain because I am doing a lot of automated installations using puppet; immediately after installing dnsmasq, any other package installations or apt-get update runs fail.
I believe the problem is that the init.d script assumes that /var/run/
This was on Ubuntu 12.04.3 LTS, using dnsmasq 2.59-4ubuntu0.1
When the dnsmasq package is installed its postinst starts the dnsmasq daemon via the initscript. Dnsmasq initially reads what is most probably an empty file from /var/run/ dnsmasq/ resolv. conf and so initially can't resolve names. (The file is probably empty because it is generated by /etc/resolvconf /update. d/dnsmasq which is included in the dnsmasq package.) Then the dnsmasq initscript tells resolvconf that dnsmasq is listening at 127.0.0.1. In response to this, resolvconf runs the aforementioned hook script /etc/resolvconf /update. d/dnsmasq which writes a new /var/run/ dnsmasq/ resolv. conf containing information about other nameservers. The dnsmasq binary notices that the latter file has changed and re-reads it. Meanwhile resolvconf updates /etc/resolv.conf to contain "nameserver 127.0.0.1" so that the resolver will talk to dnsmasq.
It's this "meanwhile" that is the problem. Resolvconf may update resolv.conf to point to dnsmasq before dnsmasq is ready to resolve names on the basis of the information just written to /var/run/ dnsmasq/ resolv. conf.
In other words, you're right. :)
I think that the postinst should be enhanced such that if /etc/resolvconf /update. d/dnsmasq has appeared or changed on install or upgrade then it (the postinst) does "resolvconf -u" before starting dnsmasq. The postinst should refrain from doing the "resolvconf -u" if IGNORE_RESOLVCONF is set in /etc/default/ dnsmasq.