Centos /etc/hosts doesnt resolve my hostname

13,576

edit /etc/sysconfig/network and change the HOSTNAME setting to say data001 instead of data001.dd. Edit /etc/hosts and make sure you have a line 127.0.1.1 data001.dd data001. If you already have such a line, make sure that data001.dd is the first thing after the ip address. Doing this with 127.0.0.1 instead of 127.0.1.1 is also common, valid, and acceptable. Don't remove localhost from that line, if it exists.

After you are done, all these should work:

getent hosts data001.dd
getent hosts data001
ping data001.dd
hostname --fqdn
ping localhost

etc...

Share:
13,576

Related videos on Youtube

DD.
Author by

DD.

Updated on September 18, 2022

Comments

  • DD.
    DD. about 1 year
    [root@data001 etc]# hostname
    data001.dd
    [root@data001 etc]# ping data001.dd
    ping: unknown host data001.dd
    [root@data001 etc]#
    

    How do I fix this? This is on a fresh Centos6 build...does this not come configured by default?

    • Florian Heigl
      Florian Heigl over 8 years
      I'm puzzled by this too and would love to understand why CentOS is (under some circumstances) not able to correctly configure that on setup. We're talking about early 1980's problems here.
  • DD.
    DD. over 11 years
    I dont have any file /etc/hostname. Do I have to change this everytime I change the hostname using the command hostname?
  • joechip
    joechip over 11 years
    Why are you asking about /etc/hostname? stew hasn't mentioned that file at all.
  • stew
    stew over 11 years
    @joechip oops, I was mentioning it, and updated it to match his centos box. I thought I had commented here when I edited, but it seems I failed to.
  • DD.
    DD. over 11 years
    @stew why do I need to change the hostname from data001.dd to data001?
  • stew
    stew over 11 years
    you don't have to. though it seems pointless to me to have hostname return fully qualified when that is a job for hostname --fqdn