[CentOS] Changing hostname?

Marcus Moeller mm at gcug.de
Mon Sep 15 19:41:27 UTC 2008


...

> I still wonder why it also works if hostname is only set in /etc/hosts like:
>
> 127.0.0.1       localhost
> 10.0.0.50       myserver.domain.example        myserver
>
> and $HOSTNAME is undefined.

Ah, got it:

/etc/sysconfig/network-scripts/ifup-post

...
if need_hostname; then
     IPADDR=`LANG= LC_ALL= ifconfig ${DEVICE} | grep 'inet addr' |
           awk -F: '{ print $2 } ' | awk '{ print $1 }'`
     eval `/bin/ipcalc --silent --hostname ${IPADDR}`
     if [ "$?" = "0" ]; the
          set_hostname $HOSTNAME
     fi
fi
...

So the conclusion seems to be:

If you have a local interface only you should just set:

127.0.0.1       localhost
::1                  localhost6

in /etc/hosts and

HOSTNAME=localhost

in /etc/sysconfig/network

This means it is not suggested to have a hostname other than localhost
on a loopback only box.

If you have an network interface configured /etc/hosts may look like:

127.0.0.1       localhost
::1                  localhost6
10.0.0.50       host.domain.example        host

and

HOSTNAME=host.domain.example

in /etc/sysconfig/network

Best Regards
Marcus


More information about the CentOS mailing list