How to change the Hostname on Centos

From Brian Nelson Ramblings
Jump to: navigation, search

How to change/adjust the Hostname on Centos

Changing your Hostname on Centos

I just got a new vps server and the host name was something really shitty like vps22303_001 and I wanted to change the host name. In order to change your host name you have to chage the HOSTNAME in your /etc/sysconfig/network file

vim /etc/sysconfig/network

Now change the HOSTNAME value to your FQDN, it should look like

As this was my mail server, that is the FQDN for that server.

Now this hostname will not update until you have rebooted the server.


How to temporarily change your hostname

Not sure why any one would want to change the hostname temporarily, but you can do this with the hostname command


To verify that it has changed or view your current hostname run


This will show you the current hostname on your server/workstation

Now if you use hostname to change your HOSTNAME, once you reboot it will change to the old value

Add your FQDN to your hosts file

Now that you have changed your hostname, you will also want to update your /etc/hosts file.

echo '' >> /etc/hosts

Now to check the /etc/hosts file to make sure it was added correctly

cat /etc/hosts

Now your server is ready to know was your FQDN