CentOS 7 hostname will not change

Michael Haynes

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?

user92134

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change hostname on CentOS 6.5?

From Dev

CentOS 7 hostname netbios/fqdn output

From Dev

Does your hostname save on your NIC | centos 7?

From Dev

Making "host -v hostname" command work for CentOS 7

From Dev

CentOS7 unable to resolve nslookup for short hostname

From Dev

How to change the timezone on CentOS 7?

From Dev

change root password in CentOS 7

From Dev

How to ping by hostname on CentOS

From Dev

CentOS7 change in visudo not accepted

From Dev

Change default swap disk in Centos7

From Dev

How to change mode for a file on CentOS 7?

From Dev

/etc/hostname vs /etc/hosts vs /etc/sysconfig/network in centos7

From Dev

How to keep sshd service running all the time and set permanent FQDN hostname in CentOS7?

From Dev

"hostname: command not found" CentOS 8

From Dev

change localhost hostname in nginx

From Dev

Change hostname of Linux machine

From Dev

meteor js change hostname

From Dev

Change Ubuntu hostname on the fly

From Dev

Revert/Prevent hostname change

From Dev

How to change a hostname

From Dev

How to change hostname

From Dev

how to change my hostname?

From Dev

Is modifying /etc/hostname enough to change the hostname?

From Dev

How to change the MySQL root account password on CentOS7?

From Dev

How to change keyboard layout for all users in CentOS 7 Mate?

From Dev

How to change language using command line on CentOS 7?

From Dev

How to permanently change Ctrl + C to Ctrl + K in CentOS 7?

From Dev

Change write permissions on samba share mount CentOS7

From Dev

Is 'home' a special hostname on Windows 7?