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...
Related videos on Youtube
Author by
DD.
Updated on September 18, 2022Comments
-
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 over 8 yearsI'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. over 11 yearsI dont have any file /etc/hostname. Do I have to change this everytime I change the hostname using the command hostname?
-
joechip over 11 yearsWhy are you asking about /etc/hostname? stew hasn't mentioned that file at all.
-
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. over 11 years@stew why do I need to change the hostname from data001.dd to data001?
-
stew over 11 yearsyou don't have to. though it seems pointless to me to have hostname return fully qualified when that is a job for
hostname --fqdn