DNS tips and tricks

DNS tips and tricks

ubuntu 24.04 openwrt

ping, ssh or your favorite web browser may not resolve host names in the same way, sometimes producing strange results.

Standard tools (ping, telnet, wget, curl, …) obey “Name Service Switch” configured in (/etc/nsswitch.conf). On my machine, the line about hosts reads:

cat /etc/nsswitch.conf | grep hosts
hosts:          files mdns4_minimal [NOTFOUND=return] dns

So host name resolution will be:

  • Use local files (/etc/hotsts)
  • Then mDNS but only for host names ending in .local.
  • Then DNS server (from /etc/resolv.conf) (only for host names not ending in .local)

This file may also use LDAP or NIS for host name resolution.

/etc/hosts

Here is the /etc/hosts documentation.

:point_up: You may experience problems if localhost and the local machine host name is not defined in that file.

mDNS

mDNS, (Linux: Avahi, Apple: Bonjour) is used by local machine to announce there services. You may have to install umdns on OpenWRT.

DNS (and /etc/resolv.conf)

  • Most modern Linux distributions uses systemd-resolve and/or NetworkManager, so /etc/resolve.conf contains 127.0.0.1 as nameserver.

    resolvectl status will show how host name are resolved.

Web browsers

Web browsers uses DNS caching and modifying /etc/hosts won’t affect name resolution unless the cache is cleared by a restart or an action.

~~~

Question, remark, bug? Don't hesitate to contact me or report a bug.