CentOS 7 hostname will not change

centoshostname

I have two CentOS 7 VM's running in virtualbox. On each of the machines I want to set the hostname and a static IP address. VM1 works just fine. VM2 does not. I did the same thing on both servers so I'm not sure why VM2 is having issues. It shows as localhost.localdomain and I can't get it to read the new correct hostname. Here is what I've done:

Modified the /etc/sysconfic/network file as follows:

NETWORKING=yes
HOSTNAME=newhost.newdomain

Modified the /etc/resolv.conf file as follows:

nameserver 8.8.8.8

Modified the /etc/sysconfig/network-scripts/ifcfg-enp0s3 file as follows:

HWADDR=#
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
NAME=enp0s3
UUID=#
ONBOOT=yes
IPADDR=192.168.10.1
NETMASK=255.255.255.0
NM_CONTROLLER=no
GATEWAY=192.168.10.100

The interface works and the IP is assigned as specified. The only thing that does not work is the hostname. I can change it temporarily by using the 'hostname {newname}' command but that is only a temp fix as it reverts back on reboot. All of this is the same as on VM1 (except for the IP address assigned) and VM1 works fine. I'm not concerned with the hosts file at the moment since I'm not worried about name resolution; I'm just worried with the hostname.

Any thoughts or suggestions?

Best Answer

Try setting the host name in /etc/hostname

From the hostname man page on my CentOS 7 machine:

The host name is usually set once at system startup (normally by readā€ing the >contents of a file which contains the host name, e.g. /etc/hostname).

Related Question