http://www.perlmonks.org?node_id=753850


in reply to gethostbyname() problem

As ikegami has pointed out, your system name resolution isn't doing what you want, so Perl won't either, as it uses the same underlying libraries to do so.

On many/most *nix systems, name resolution is controlled by entries in /etc/nsswitch.conf. You'll find a line there for "hosts" that will control where your system looks to resolve names, and in what order it does. For your system to look at /etc/hosts first, you'll want your file to have a line that looks like:

hosts: files dns
This line essentially says, "look at /etc/hosts, and if you don't find it there, use DNS".

If your /etc/nsswitch.conf file looks right, your /etc/hosts may have other issues that prevent that line from matching.