[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:
>       localhost
>       myserver.domain.example        myserver
> and $HOSTNAME is undefined.

Ah, got it:


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

So the conclusion seems to be:

If you have a local interface only you should just set:       localhost
::1                  localhost6

in /etc/hosts and


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:       localhost
::1                  localhost6       host.domain.example        host



in /etc/sysconfig/network

Best Regards

More information about the CentOS mailing list