in reply to /etc/hosts is not evaluated after modification on Linux
I am trying to find out, if a given hostname can be resolved and if not, I update a hosts file and check if the resolution works again.
Very strange approach. It seems you are working in a network with private IP addresses, and have a nameserver that does not "know enough" about that network. Why don't you update the data the nameserver uses instead of messing with /etc/hosts, probably on many computers?
Another question: How to you update records in /etc/hosts when needed, e.g. when test_host moves from 192.168.0.50 to 192.168.0.55? Do you touch each and every /etc/hosts file?
And a third thing: There should be no underscore (_) in a hostname (see Wikipedia for the relevant RFCs). It may work, but only by chance.
UPDATE:
Maybe you don't have a nameserver at all? Maybe you are abusing gethostbyname() to find a hostname in /etc/hosts? If yes, consider using dnsmasq. It provides DNS and DHCP services (optionally also TFTP), and adding hostnames to the DNS service is as easy as editing /etc/hosts - literally, because you simply edit /etc/hosts on the machine running dnsmasq. dnsmasq "watches" /etc/hosts, so you don't have to do more than editing the file.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: /etc/hosts is not evaluated after modification on Linux
by Anonymous Monk on May 31, 2015 at 09:02 UTC |