Centos – Avoid overwriting of hostname by transient hostname at reboot

centoshostname

My server is CentOS 7.1. After reboot the hostname is overwritten by the transient hostname (mail) and I can't find a way to avoid that.
Maybe AutoDNS and the MX record mail causes that?

  • /etc/hostname contains the correct value
  • hostnamectl --transient set-hostname my.desired.name is working but only until next reboot

So, after reboot:

  • hostnamectl status shows the correct static hostname but the wrong transient hostname (mail).
  • hostname -s or hostname -f shows the wrong hostname.

The file /etc/sysconfig/network is overwritten “by anaconda” and has the line HOSTNAME="mail". I tried to edit this file to configure the correct name but it's overwritten after reboot.

How can I prevent the transient hostname being set to mail after restarting?


EDIT:

I already tried to add DHCP_HOSTNAME="my.desired.name" to my /etc/sysconfig/network-scripts/ifcfg-e….. but with no success (line was removed after reboot).

And I tried to add execution of hostnamectl set-hostname "" --transient (which will set the transient to the value of static hostname) at reboot which failed either with activated /etc/rc.local and also as a service with chkconfig on (with # chkconfig: – 11 91 so that it should run after all other services).

Any further suggestions are welcome.

Best Answer

The transient hostname is initialised at startup to the static host name but it can be changed by DHCP or mDNS.

DHCP

If you’re using DHCP, you should check that the wrong hostname hasn’t been set in the configuration for your network device. Run ip addr show to check which network device you’re using. Then edit the appropriate configuration script. E.g. if your network interface is eth0, you should edit its configuration file, /etc/sysconfig/network-scripts/ifcfg-eth0.

From Red Hat documentation on Configuring a Network Interface Using ifcfg Files, there’s an option to

configure an interface to send a different host name to the DHCP server.

DHCP_HOSTNAME=hostname

Check to make sure that your system doesn’t have the hostname mail configured in this script.

If that’s not the issue you’ll need to check that the local DHCP server isn’t configured to set the hostname as mail. If you have a network administrator, who has configured your host as mail in the DNS / DHCP for a Local Area Network, you should talk to them. The best practice is to configure hosts with non-role based names and then to configure DNS CNAMES as aliases for the relevant servers.

If DHCP is the source of your problems and the above suggestions don’t help, the other option would be to configure your network interface to use static IP addresses.

Related Question