OpenWrt Forum Archive

Topic: Problems with dnsmasq and local hostnames

The content of this topic has been archived on 29 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,

I'm having a hard time getting dnsmasq to answer DNS queries for local hostnames, whether I configure them in /etc/hosts or using static DHCP leases. I'm running OpenWRT 15.05 with dnsmasq 2.73 on a Turris Omnia router.

What I want is simple: when $host gets an IP address $a from the DHCP server, DNS queries for $host should return $a. If I have to configure static DHCP leases for this to work, that's fine -- I like knowing what my IP address is going to be anyways. From the OpenWRT docs, it sounds like this is exactly what dnsmasq is designed for, and OpenWRT configures it to do that by default. So I'm confused as to why it's not working for me.

First, here is my /etc/config/dhcp file (generated by luci):

root@turris:/etc# cat /etc/config/dhcp 

config dnsmasq
    option domainneeded '1'
    option boguspriv '1'
    option localise_queries '1'
    option rebind_protection '1'
    option rebind_localhost '1'
    option domain 'lan'
    option expandhosts '1'
    option authoritative '1'
    option readethers '1'
    option leasefile '/tmp/dhcp.leases'
    option resolvfile '/tmp/resolv.conf.auto'
    option localservice '1'
    option port '0'
    option logqueries '1'
    option nonwildcard '0'
    option local '/lan/'

config dhcp 'lan'
    option interface 'lan'
    option limit '150'
    option leasetime '12h'
    option dhcpv6 'server'
    option ra 'server'
    option ignore '0'
    option start '2'
    list dhcp_option '6,192.168.45.1'

config dhcp 'wan'
    option interface 'wan'
    option ignore '1'

config odhcpd 'odhcpd'
    option maindhcp '0'
    option leasefile '/tmp/hosts/odhcpd'
    option leasetrigger '/usr/sbin/odhcpd-update'

config host
    option name 'namazu0'
    option mac '00:21:86:a2:97:1a'
    option ip '192.168.45.3'

config host
    option name 'namazu1'
    option mac '00:21:6b:ac:e3:d6'
    option ip '192.168.45.4'

(namazu is a single laptop: namazu0 is its wired interface, namazu1 wireless.)

And the resulting dnsmasq.conf:

root@turris:/etc# cat /var/etc/dnsmasq.conf 
# auto-generated config file from /etc/config/dhcp
conf-file=/etc/dnsmasq.conf
dhcp-authoritative
domain-needed
log-queries
localise-queries
read-ethers
bogus-priv
expand-hosts
local-service
port=0
domain=lan
server=/lan/
dhcp-leasefile=/tmp/dhcp.leases
resolv-file=/tmp/resolv.conf.auto
addn-hosts=/tmp/hosts
conf-dir=/tmp/dnsmasq.d
stop-dns-rebind
rebind-localhost-ok
dhcp-broadcast=tag:needs-broadcast

dhcp-host=00:21:86:a2:97:1a,192.168.45.3,namazu0
dhcp-host=00:21:6b:ac:e3:d6,192.168.45.4,namazu1



dhcp-range=lan,192.168.45.2,192.168.45.151,255.255.255.0,12h
dhcp-option=lan,6,192.168.45.1
no-dhcp-interface=eth1

IIUC, that "server=/lan/" entry in dnsmasq.conf is the important one that is supposed to make things work. But it doesn't.

First, I've defined a bogus hostname in /etc/hosts to see if I can get back its bogus IP address:

root@turris:/etc# cat /etc/hosts
127.0.0.1 localhost
5.6.7.8 flarp.lan flarp

No luck:

root@turris:/etc# dig +short flarp.lan @127.0.0.1
root@turris:/etc# dig +short flarp @127.0.0.1

(No output to either query.)

And now one of the hostnames defined by a static lease:

root@turris:/etc# dig +short namazu0 @127.0.0.1
root@turris:/etc# dig +short namazu0.lan @127.0.0.1

I'm stumped. I must be missing something simple and obvious, but I've been through the OpenWRT docs and the dnsmasq man page and I can't see it. Help!

Thanks,

Greg

Possibly because of rebind_protection. Also why "port 0" ? See syslog for details (logread command)

(Last edited by bolvan on 22 Oct 2016, 17:39)

bolvan wrote:

Possibly because of rebind_protection. Also why "port 0" ? See syslog for details (logread command)

A-HA!! It took a bit more digging, but that "port 0" was the clue I needed. Thank you!

Short version: on the Turris Omnia, something called kresd is already listening on port 53. When I reconfigured dnsmasq with "port 53", it failed to start:

2016-10-22T20:00:46-04:00 crit dnsmasq[19251]: failed to create listening socket for port 53: Address in use
2016-10-22T20:00:46-04:00 crit dnsmasq[19251]: FAILED to start up
2016-10-22T20:00:51-04:00 crit dnsmasq[19292]: failed to create listening socket for port 53: Address in use
2016-10-22T20:00:51-04:00 crit dnsmasq[19292]: FAILED to start up
2016-10-22T20:00:56-04:00 crit dnsmasq[19323]: failed to create listening socket for port 53: Address in use
2016-10-22T20:00:56-04:00 crit dnsmasq[19323]: FAILED to start up
2016-10-22T20:01:01-04:00 crit dnsmasq[19361]: failed to create listening socket for port 53: Address in use
2016-10-22T20:01:01-04:00 crit dnsmasq[19361]: FAILED to start up
2016-10-22T20:01:06-04:00 crit dnsmasq[19400]: failed to create listening socket for port 53: Address in use
2016-10-22T20:01:06-04:00 crit dnsmasq[19400]: FAILED to start up
2016-10-22T20:01:11-04:00 crit dnsmasq[19431]: failed to create listening socket for port 53: Address in use
2016-10-22T20:01:11-04:00 crit dnsmasq[19431]: FAILED to start up
2016-10-22T20:01:11-04:00 info procd[]: Instance dnsmasq::instance1 s in a crash loop 6 crashes, 0 seconds since last crash

I found the culprit with netstat:

root@turris:/etc# netstat -ulnp | grep :53
udp        0    704 0.0.0.0:53              0.0.0.0:*                           2380/kresd
udp        0      0 :::53                   :::*                                2380/kresd

Googling for "openwrt kresd" didn't find much, but it looks like kresd is from a package called knot-resolver. I've never heard of that, but it looks like that's what the folks behind the Turris Omnia selected as the local DNS server, instead of dnsmasq.

I configured dnsmasq to listen on port 553, and used "dig -p 553" to send queries to it: worked perfectly, resolving both real hostnames from static leases and bogus hostnames from /etc/hosts.

So... either I need to figure out how to disable kresd and use dnsmasq instead, or configure kresd to use dnsmasq for local hostnames.

All daemons usually start with init script in /etc/init.d
Search there. if you find something like "/etc/init.d/kresd" then
/etc/init.d/kresd stop
/etc/init.d/kresd disable
If not then do textual search for all files in /etc/init.d for the string "kresd".
If nothing found do the same for the whole fs
Also search packages for the name, possibly its installed as a package
opkg list | grep kresd

(Last edited by bolvan on 23 Oct 2016, 08:42)

You may find this topic useful: discourse dot labs dot nic dot cz/t/dnsmasq-local-domain-issue/924
The Knot resolver is made by CZ.nic, the same guys who designed the Omnia,

The discussion might have continued from here.