Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 8 down vote accepted

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   google.com
$ ping -c1 google.com | head -1
PING google.com ( 56(84) bytes of data.
$ getent ahosts google.com       STREAM google.com       DGRAM       RAW    
share|improve this answer

The host utility is used for DNS lookups. It doesn't care about hosts files or non-DNS methods of resolving a hostname. If you want to see how your system would resolve a hostname under normal circumstances (taking nsswitch.conf into account), you can use getent. The host utility should be reserved for DNS testing. Here is an example:

$ host foobar.com
foobar.com has address
foobar.com mail is handled by 0 foobar.com.
$ getent hosts foobar.com    foobar.com
share|improve this answer
@0xC0000022L That statement is incorrect. If you look at the manpage it uses gethostbyaddr(3), which is a libc function. – jordanm Nov 14 '13 at 16:33
@0xC0000022L libc functions are not system calls, so they won't show up in strace. Only things in the "2" section of manpages would show up in strace. – jordanm Nov 14 '13 at 16:44
@0xC0000022L - also, since getent is part of libc on my system, it wouldn't make any sense for it to not use the library it is distributed with. – jordanm Nov 14 '13 at 16:46

Programs like dig, host and nslookup query the DNS only. They don't query other sources of host names such as /etc/hosts, NIS or LDAP.

In most setups, the easiest way to smoothly add host names locally is to run a DNS server. Running a DNS cache is a good idea anyway for performance. In other words, the fact that no DNS server is running locally is something to fix rather than something to work around.

Dnsmasq is a common choice: it's widely available, small (it's used on many Linux-based routers) and easy to configure. Dnsmasq caches DNS requests and can serve additional names from a hosts file. It also provides a basic DHCP server suitable for small networks, but you don't have to use that part. If you have an isolated machine, run Dnsmasq on it. If you have a local network, run Dnsmasq (or some other equivalent software that's already there) on your router. See How to make a machine accessible from the LAN using its hostname for more information including how to set up Dnsmasq.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.