Opened 9 years ago

Closed 6 years ago

Last modified 4 years ago

#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:


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/
ln -sf /tmp/ /tmp/resolv.conf

This creates /tmp/ as the actual file, and /tmp/ as the sym link to it

/etc/config/dhcp has

option 'resolvfile' '/tmp/'

/etc/init.d/dnsmasq has

append_parm "$cfg" "resolvfile" "-r"

which results the following added to the runstring of dnsmasq

-r /tmp/

which is defined as
-r, --resolv-file=path Specify path to resolv.conf (defaults to /etc/resolv.conf)

So dnsmasq uses /tmp/ 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/ /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

echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf


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

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:

/usr/sbin/dnsmasq $args --log-queries --log-facility=/tmp/dns.log && {

# rm -f /tmp/resolv.conf


grep -q "nameserver $DNS_SERVER" /tmp/resolv.conf \

echo "nameserver $DNS_SERVER" >> /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.

comment:2 Changed 8 years ago by anonymous

For some reason the wiki deleted the "
" 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

What use case are you trying to solve?

If I configure wan as dhcp, /tmp/ 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" under "config interface lan" (or wan).
This leaves /tmp/ 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

Add Comment

Modify Ticket

as closed .
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.