I have a Linux(Centos 6.3) dedicated server. When i log into it through SSH(PuTTy) and issue the command 'root@p2953333#ping localhost' it gives the error 'ping: unknown host localhost' as i can ping any other ips including 127.0.0.1.
i have googled alot and find some solutions like checking settings in /etc/hosts and /etc/nsswitch.conf which are correct in my server.
Any help appreciated.

Thanks,

cat /etc/hosts

You should see the lines similiar to:

    127.0.0.1      localhost
    127.0.0.1      servername.domain.local

Do you have this?

Thanks for help CimmerianX.

My /etc/hosts info is as below:

127.0.0.1 localhost.localdomain localhost
::1 localhost localhost6 localhost6.localdomain6
66.135.38.137 p2953393.pubip.serverbeach.com p2953393

and my /etc/resolv.conf info is as below:

domain pubip.serverbeach.com
options rotate
nameserver 216.187.125.131
nameserver 216.187.125.130

Please help me!

Seems like your system is not checking the hosts file and thus can't resolve localhost to 127.0.0.1

Look at /etc/nsswitch.conf. This file should have certain permissions 644. If not, then use:

chmod 644 /etc/nsswitch.conf

Cat nsswitch.conf and make sure have the following:

hosts: files dns
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.