1838665 Members
5704 Online
110128 Solutions
New Discussion

Resolution of localhost

 
SOLVED
Go to solution
Sanjay Yugal Kishore Ha
Frequent Advisor

Resolution of localhost

Hi,

The /etc/nsswitch.conf entry reads as follows:
hosts: files nis nisplus

If I do a ping localhost, it first looks in to the local /etc/hosts and if it is not available it then uses the nis source and if not nisplus source.

My doubt over here is

1) Can I make an assumption that irrespective
of whatever is the source, "localhost" will
always resolve to 127.0.0.1?

Or

2) For certain sources, it will be resolved to be 127.0.0.1 and for something else it
will be resolved to the localhost's IP?

Please clarify.

Thanks,
Sanjay
Dying is the last thing that I will do.
2 REPLIES 2
Stefan Farrelly
Honored Contributor
Solution

Re: Resolution of localhost

As long as you have files first in your nsswitch.conf file and you have an entry in /etc/hosts for localhost pointing to 127.0.0.1 then yes, it will always resolve to 127.0.0.1.

But if you use other sources first in /etc/hosts, or someone removes or changes the localhost entry in /etc/hosts then localhost could resolve to something other than 127.0.0.1. This happened to us once, we had dns then files in our nsswitch.conf file and someone accidentally put an entry into our dns for localhost pointing to something other than 127.0.0.1 ! - talk about cause us problems! now the dns guys leave a permanent entry in the dns for localhost pointing to 127.0.0.1 just to be safe, or we could put files first in our dns search order.


Im from Palmerston North, New Zealand, but somehow ended up in London...
Bill Hassell
Honored Contributor

Re: Resolution of localhost

localhost (and loopback) are fairly important to basic networking in HP-UX which is why they should never be changed in /etc/hosts, and that /etc/hosts always be searched first. There is a big speed advantage to using files then nis or dns as the resolution order in nsswitch.conf, perhaps 100:1 or more. This is because the hosts file is essentially memory resident and thus instantly available.

This makes a huge difference when using typical network backup programs (like Omniback, etc) where gethostbyname is issued for every file. Rather than ask the NIS or DNS server for this info, use /etc/hosts. Just put the few machines that are part of backup operations into /etec/hosts. Note that maintenance of individual /etc/hosts can be simplified by putting only a few key production machines into the file. IP addresses for these systems probably won't change every few weeks.


Bill Hassell, sysadmin