Ubuntu – /usr/bin/host not picking up changes to /etc/hosts even after reboot

dnshostsnetworkingUbuntu

I have a Ubuntu Server 12.04 (amd64) machine on which, when I change /etc/hosts, the changes aren't picked up, even after a reboot. I am using /usr/bin/host to test, but none of the other programs seems to pick it up either.

This is a server and nscd and dnsmasq aren't installed. Also, the file /etc/nsswitch.conf contains the line:

hosts:          files dns

so that I would expect it to work. I also checked that the mtime of the file changes with editing and tried running service networking restart (against all odds) and also resolvconf -u.

All commands where run as root where needed. The machine has network configured manually in /etc/network/interfaces and not via Network Manager (it isn't installed either).

Basically what I want to achieve is that the IP for a few hosts can be manipulated. The reason being that inside our network I get an IP to which I have no route, but I can use the external IP for that service via HTTPS.

What am I missing?

Note: no DNS server is locally running and the nameserver lines in /etc/resolv.conf (and the respective lines in interfaces) point to the DNS server that gives me the wrong IP.

Also note: I've searched on the web and read through the "similar questions", but my case doesn't seem to be covered.

/etc/host.conf is:

# The "order" line is only used by old versions of the C library.
order hosts,bind
multi on

Best Answer

The host command doesn't check the hosts file. From the manpage:

host is a simple utility for performing DNS lookups.

If you want to test lookups while respecting the hosts file, then use ping or getent.

$ tail -1 /etc/hosts
127.0.0.1   google.com
$ ping -c1 google.com | head -1
PING google.com (127.0.0.1) 56(84) bytes of data.
$ getent ahosts google.com
127.0.0.1       STREAM google.com
127.0.0.1       DGRAM  
127.0.0.1       RAW    
Related Question