Local DNS doesn't resolve router itself

I’ve followed these instructions to make the dnsmasq DHCP clients available on local DNS. This works well indeed for the DHCP clients, but the router itself still doesn’t resolve. Any hints on how to achieve name resolution for the router? I tried adding an entry for it in LuCI’s Network->Host names, both with and without the local domain suffix, but that didn’t change anything.

You should not need such instructions to enable *.lan names at all. You click a checkbox in the Foris UI, and it’s supposed to just work. If you log in via ssh, you can inspect the list of names generated from DHCP at /tmp/dhcp.leases.dynamic

I’m not sure about automatic DNS name for the router itself, but you certainly can add whatever names you like: https://doc.turris.cz/doc/en/public/dns_knot_misc#adding_static_address_records

1 Like

Thank you, I had somehow managed to overlook that!

From memory /etc/init.d/dnsmasq is supposed to do something like the following, but (I just tested my TO, and) it does not:

. /lib/functions/network.sh; network_get_ipaddr LAN_IPADDR lan
uci add dhcp domain
uci set dhcp.@domain[-1].name=${HOSTNAME} # is created by /etc/init.d/dnsmasq??
uci set dhcp.@domain[-1].ip=${LAN_IPADDR}
uci commit dhcp

The above makes changes to /etc/config/dhcp (to make an A record) in the same way LuCI does, just via the CLI. Also, just noticed that I then had to reboot my router, as neither of the following effected the change (but I did get the expected behavior after a reboot):

/etc/init.d/dnsmasq reload
/etc/init.d/dnsmasq restart

1 Like

Ah, just had a look in , and found the following:

config_get_bool ADD_LOCAL_HOSTNAME “$cfg” add_local_hostname 1

So there you go:

uci set dhcp.@dnsmasq[0].add_local_hostname=1

Don’t forget to delete the old A record (be careful if you have more than one):

uci del dhcp.@domain[-1]
uci commit dhcp

I will test this & get back to you…

1 Like

Hmm…

The preferred method (add_local_hostname) just didn’t seem to work - dunno why (there are some PRs in LEDE git for this script) - both methods place an entry in /tmp/hosts/dhcp. Maybe one for me to have another look at later on!

1 Like

Thanks for looking into this. I just tested your suggestions before you wrote your last post and found the same result. Interestingly, the router’s IP seems to reverse-resolve to ‘localhost’:

$ nslookup 10.0.0.1
Server:         10.0.0.1
Address:        10.0.0.1#53

Non-authoritative answer:
1.0.0.10.in-addr.arpa   name = localhost.

Don’t know whether this means anything, but it looks odd to me.

BTW, is there any way to paste code blocks in here without manually indenting every line?

I use three backticks to delimit multi-line code blocks. It’s a habit from elsewhere, and it works here as well :slight_smile:

code
block
1 Like

Posting this for anyone still having the problem (after years) and googling like me for a solution: I managed to solve the problem on my Turris MOX just by adding router name (without .lan) and its IP into LuCI’s Network->Host names. At that moment, nslookup on the router started to resolve the router’s name. To get the same on my computer, I had to flush DNS cache. On my Ubuntu 18.04.6, it is performed by sudo systemd-resolve --flush-caches. Alternatively, you might restart the computer or wait long enough time for the cache to expire.

1 Like