brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: getent hosts shows what your programs really resolve

Linux
~/tips/tip-dns-getent-hosts

getent hosts nas.local

Shows the address a normal program gets, including hosts file entries that dig ignores.

You add a line to /etc/hosts and dig ignores it. That is how dig works.

dig is a DNS tool. It talks to a DNS server and never reads the hosts file. Programs on your machine use the system resolver, which follows the order set in /etc/nsswitch.conf. getent goes through that same path:

getent hosts nas.local
getent ahosts example.com

So it shows you what a normal program would get, including entries from /etc/hosts. ahosts lists all the addresses, IPv4 and IPv6, which helps when a site works on one and not the other.

That makes it the right command to settle the argument between dig and your browser. If getent and dig disagree, something local, like the hosts file or another source in nsswitch, is overriding DNS. The caveat: browsers with their own DoH setting skip the system resolver altogether, so even getent can disagree with them.

The hosts file is also the simplest way to block a name on one machine: point it at 0.0.0.0. It has no wildcard support, so every name needs its own line, and that is the moment a DNS filter becomes the better tool.

Further reading: getent manual, On this site: ipconfig /displaydns shows what Windows has cached, On this site: resolvectl flush-caches clears the DNS cache on Linux

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link