Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: /etc/hosts is not evaluated after modification on Linux

by afoken (Chancellor)
on May 31, 2015 at 06:44 UTC ( [id://1128449]=note: print w/replies, xml ) Need Help??


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

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

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

    Yes there is no nameserver in this particular example and /etc/hosts is used for resolution.

    How already pointed by philipbailey nscd is used for caching and if after updating of /etc/hosts in the script cache needs to be invalidated by using "nscd -i hosts"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-23 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found