If you have entered the wrong hostname during installation or requirement to change it, you can change it as below. The following is tested on Ubuntu and CentOS. Changing hostname involves three steps.

Change HOSTNAME value in /etc/sysconfig/network Change hostname in /etc/hosts Updating hostname on the terminal

1. Display Hostname

Let’s find out the configured name by executing hostname on the terminal. Let’s change to geekflare

2. Change Hostname

Edit /etc/sysconfig/network file using vi, look for HOSTNAME= and update that to the desired name. Note: I’ve noticed on some Cloud VM that HOSTNAME entry doesn’t exist. If you don’t find this on your server then you may ignore this step.

Before change:

After change:

The next step would change the hostname in a hosts file. Edit /etc/hosts file, look for current hostname in 127.0.0.1 and server IPs (if any) line and update that to the desired one which you configured above.

Before change:

After change:

3. Change hostname on terminal

And, finally, execute the hostname command with the desired value. Try to re-login to your server and you’ll notice the new hostname. Using DigitalOcean Server? If you would like to change the hostname on the DigitalOcean VM, then you also have to update the hostname in /etc/hostname file. Here is a quick video demonstration. That was easy. Isn’t it? Interested in learning more about Linux? Check out this administration course.

How to Change hostname in Linux  - 68How to Change hostname in Linux  - 30How to Change hostname in Linux  - 86How to Change hostname in Linux  - 43How to Change hostname in Linux  - 21How to Change hostname in Linux  - 28