4

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.

3

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.

1

Finally I got it.
Our Hosting Provider (Host Europe) has an option in the Controlpanel for each server (virtual root server). On the page "Hostname / RDNS" there is an input field "Hostname:". I changed it to the correct value and now it works as expected.

0
$ vi /etc/sysconfig/network-scripts/ifcfg-eth0

$ vi /etc/sysconfig/network

HOSTNAME="hostname<FQDN>"
DHCP_HOSTNAME="hostname<FQDN>"

$ vi /etc/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
hostnamectl --transient set-hostname "hostname"

#exit vi <:wq>

$ chmod +x /etc/rc.d/rc.local <This will make the file unchanged even after reboot>

$ Reboot

*You are ready to go the Cpanel installation for CentOS7 :)*
  • 6
    some word to explian besides shell command might be usefull. – Archemar Dec 20 '15 at 21:23
0

I know it's been a while but for anyone who's looking for an answer as to why it happens: Some providers (ISP, Company VPNs, etc) send a "Transient hostname" back to the host whenever making a request for an IP via DHCP, and depending on your machine's configuration, it gets set as the current machine's hostname

My problem (and the way I ended up here) was that I had the hostname set as the default localhost and according to the hostnamectl man page:

This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g. "Lennart's Laptop"), the static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient hostname which is a default received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used.

So a solution would be not to have the hostname set as localhost

Another solution is to make your dhcp configuration in /etc/dhcp/dhclient.conf not to request for a hostname by removing the host-name (and perhaps the domain-name) from the request property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.