#5637 closed defect (worksforme)
dnsmasq - improper handling of resolv.conf
Reported by: | rmcgonegal@… | Owned by: | thepeople |
---|---|---|---|
Priority: | normal | Milestone: | Barrier Breaker 14.07 |
Component: | base system | Version: | Kamikaze 8.09 |
Keywords: | dnsmasq resolv.conf | Cc: |
Description
The symptom is quite often than name lookup fails.
Because the dnsmasq start() command appears to mishandle the sym link /tmp/resolv.conf, the nemserver entries end up in the wrong file and are not accessible to dnsmasq while running.
/etc/init.d/boot has
touch /tmp/resolv.conf.auto
ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf
This creates /tmp/resolv.conf.auto as the actual file, and /tmp/resolv.conf.auto as the sym link to it
/etc/config/dhcp has
option 'resolvfile' '/tmp/resolv.conf.auto'
/etc/init.d/dnsmasq has
append_parm "$cfg" "resolvfile" "-r"
which results the following added to the runstring of dnsmasq
-r /tmp/resolv.conf.auto
which is defined as
-r, --resolv-file=path Specify path to resolv.conf (defaults to /etc/resolv.conf)
So dnsmasq uses /tmp/resolv.conf.auto as the file with the nameservers in it
However, in the /etc/init.d/dnsmasq file itself
In the stop command it does
[ -f /tmp/resolv.conf ] && {
rm -f /tmp/resolv.conf
ln -s /tmp/resolv.conf.auto /tmp/resolv.conf
}
which deletes the sym link and then re-creates it, which does nothing to the contents of the file.
In the start command it does
rm -f /tmp/resolv.conf
DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
for DNS_SERVER in $DNS_SERVERS ; do
echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
done
which deletes the sym link and then creates a real file with the nameservers in it
Net result is that there are two files, however the one with the nameservers in it is not used by dnsmasq
The fix is to replace the line in dnsmasq start()
rm -f /tmp/resolv.conf
with the line
echo -n "" > /tmp/resolv.conf
This will result in one file and a sym link to it, and the file contents will be removed during a start.
Attachments (0)
Change History (6)
comment:1 Changed 8 years ago by anonymous
comment:2 Changed 8 years ago by anonymous
" that was in front of the echo command on the continuation line - it should be |
grep -q "nameserver $DNS_SERVER" /tmp/resolv.conf \ ||echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
comment:3 Changed 8 years ago by monte <peabody.bb4wtmzci8qj@…>
I'm fairly new to OpenWRT, but this is working for me with snapshot r19759
(2/20/2010).
What use case are you trying to solve?
If I configure wan as dhcp, /tmp/resolv.conf.auto is populated with nameservers
when it gets it's lease.
If I configure wan as static, I have to go into /etc/config/dhcp and add
"option cachelocal 0" under "config dnsmasq" and go into /etc/config/network
and add "option dns 8.8.8.8" under "config interface lan" (or wan).
This leaves /tmp/resolv.conf.auto blank, but populates /tmp/resolv.conf.
In both cases, I can resolve hostnames.
comment:4 Changed 8 years ago by thepeople
- Owner changed from developers to thepeople
- Status changed from new to assigned
comment:5 Changed 6 years ago by nbd
- Resolution set to worksforme
- Status changed from assigned to closed
comment:6 Changed 4 years ago by jow
- Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07
Milestone Attitude Adjustment 12.09 deleted
Actually, after testing this, it is an incomplete fix. Because udhcpc only runs when the interface comes up, but you can do a dnsmasq restart anytime, the above fix ends up correct after a reboot, but a subsequent dnsmasq restrart wipes out the nameserver information in resolv.conf from udhcpc. However each restart of dnsmasq will rewrite the nameserver information that it enters multiple times.
A better fix is as follows:
# rm -f /tmp/resolv.conf
This checks whether the nameserver line is already in resolv.conf and does not modify it.
You can check this by issuing "ifup wan" and looking at the contents of /tmp/resolv.conf and then issue a "/etc/init.d/dnsmasq restart" and look again.