I am trying to set up a server(PHP/HTTPD) in CentOS. When I use ipaddress to access the website its working fine. But using domain name its not working. So I used ping command to check.

ping // Working fine 
ping example.com // ping: unknown host example.com

Here is /etc/sysconfig/network-scripts/ifcfg-eth0:





/etc/hosts: example.com   localhost


domain example.com

while using route command

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface    *        U     0      0        0 eth0
link-local      *          U     1002   0        0 eth0
link-local      *          U     1003   0        0 eth1
default         UG    0      0        0 eth0

Please help me. Also correct me if I am wrong because I am programmer not a server admin

  • 1
    what is the content of /etc/resolv.conf? You list all kinds of configurations but not the one that matters. In resolv.conf you configure your dns servers. Also in nsswitch.conf what do you have configured for hosts? – Koen van der Rijt Feb 3 '15 at 9:23
  • @KoenvanderRijt I updated question please check that.. It contains the above four lines – AnNaMaLaI Feb 3 '15 at 9:29
  • a reason for a server to not look at your /etc/hosts file first could be because of a line in your /etc/nsswitch.conf file. 'hosts: files dns' this displays the order of resources to check when resolving a hostname. Also you are checking from a different IP and not locally? I might have not picked up on that. if thats the case you either need to check if that domainname is present in the DNS or you can test this by adding the same line in your own hosts file. – Koen van der Rijt Feb 3 '15 at 9:35
  • In my nsswtich.conf: hosts: files dns line is there.. Shall i comment that line ? – AnNaMaLaI Feb 3 '15 at 9:38
  • no dont comment it. It should be there. Can you please explain how you are testing this? from a browser on a different machine? – Koen van der Rijt Feb 3 '15 at 9:41

We found out it was a DNS problem

first we added the and domainname.com to the /etc/hosts file of the workstation. This resolved the issue. So we concluded it was a DNS issue.

after that we queried his DNS servers with 'dig @' which gave no results. Without the proper dns records the workstation will never find the correct hosts.

  • @Håvid Falch makes a good point also. – Koen van der Rijt Feb 3 '15 at 10:51
  • Thanks @Koen for your support via chat to debug the problem – AnNaMaLaI Feb 3 '15 at 10:52

Your network configuration is hardly the issue here. Is the domain you are testing registered? The first DNS in your list the is the Google public DNS. It won't come up with valid addresses for fictious test domains.

Make sure that only your internal DNS servers are in resolv.conf, and make sure that there are valid records in it for the domain you are testing with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.