Showing results for 
Search instead for 
Did you mean: 

Ping cannot use /etc/hosts for IP resolution

N A Khan

Ping cannot use /etc/hosts for IP resolution

Hi Freinds,

The ping command in HP-UX 11i is not using /etc/hosts file for IP resolution.

ping hostname results in error saying that there is no such hostname. Even ping cannot ping the same hostname.

However, ping IP_ADDRESS is working as usual.

Do you have any idea behind this problem ?

thanks in advance
steven Burgess_2
Honored Contributor

Re: Ping cannot use /etc/hosts for IP resolution


Have a look at your /etc/nsswitch.conf file

This should state what is to be used to resolve hostnames

An entry for hosts should look like

hosts: files [NOTFOUND=continue] dns

Stating that /etc/hosts will first be used. If the host is not found then dns will be used

Your dns server will be set up in your /etc/resolv.conf file

Test to see which function is being used



take your time and think things through
Michael Tully
Honored Contributor

Re: Ping cannot use /etc/hosts for IP resolution

First check to see how your /etc/nsswitch.conf file is configured. It should be to your /etc/hosts file first, as shown below.

hosts: files [NOTFOUND=continue UNAVAIL=return TRYAGAIN=return] dns [NOTFO
UND=return UNAVAIL=continue TRYAGAIN=return]

$ more /etc/resolv.conf

Removing this file or moving it to .old should resolve locally anyway. See how this goes.
Anyone for a Mutiny ?
Sukant Naik
Trusted Contributor

Re: Ping cannot use /etc/hosts for IP resolution

Hi Khan,

Do the following:

1. Rename your nsswitch.conf file.
# cd /etc
# mv nsswitch.conf nsswitch.conf.old

2. First check your hostname
# hostname

3. After that check your hosts file for the entry of your server name.

4. Now try pinging to your server.
# ping abcd

If this works, it indicates your hosts entry in the nsswitch.conf has to be changed as mentioned below.
hosts : files dns nis


Who dares he wins
sven verhaegen
Respected Contributor

Re: Ping cannot use /etc/hosts for IP resolution


in standard the HP_UX OS has what we would call an priority setup in name resolution , 3 methodes of name resolution are actively present/possible on the system : DNS , NIS and files (/etc/hosts) , the priority is that first the system will always go to DNS , if no DNS can be found it will go to NIS if non is found we revert to hosts file... there is away to revert this behaviour being the use of the /etc/nsswitch.conf file ,in this file you alter the search order , in your case that would require and entry like this

hosts : files [NOTFOUND=continue] DNS [NOTFOUND=continue]

that should solve your issue
...knowing one ignores a greath many things is the first step to wisdom...
Daimian Woznick
Trusted Contributor

Re: Ping cannot use /etc/hosts for IP resolution

Although the above comments about the nsswitch.conf file are probably the answer to your query, if that configuration file is already setup correctly you may have a corrupt hosts file (incorrect syntax).
Honored Contributor

Re: Ping cannot use /etc/hosts for IP resolution

Hi Khan

the issue can be like this :

1. wrong or incoorect /etc/resolv.conf
2. incorrect or missing /etc/nssswitch.conf
3. wrong or no entry in DNS .

Do a nslookup local hostname and see how is resolves , it must be looking for nsswitch.conf to get the information of how it will resolv the hostname . If that inforamtion is correct thean check for the DNS server anme entry in /etc/resolv.conf .

The easiest way to solve is to mv /etc/resolv.conf to .old and then check doing a nslook up < local hostname > it should use /etc/hosts to resolve the name , once this is done than you can go to check for nsswitch / reslov.conf and then DNS entry in that order.

All the best and please do award points , if you find the solution give here are helpful

Manoj Srivastava

Darrick Schuch
Occasional Visitor

Re: Ping cannot use /etc/hosts for IP resolution

On 11.11 if you ipv6 loaded on the box then you need the line in nsswitch.conf file
ipnodes : files [NOTFOUND=CONTINUE] dns
This is more than likely the problem.
Honored Contributor

Re: Ping cannot use /etc/hosts for IP resolution


Look at your /etc/nsswitch.conf file and see the entries against hosts. If the entry is set as

hosts : files

This will use your /etc/hosts for name resolution and should use your /etc/files file to do the ping if the hostname exists in the file. Try this link below on how to configure this /etc/nsswitch.conf file.

Hope this helps.

Occasional Advisor

Re: Ping cannot use /etc/hosts for IP resolution

thanks, this solved the problem I was facing 


unable to ping with lan0 down