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  - 19How to Change hostname in Linux  - 27How to Change hostname in Linux  - 88How to Change hostname in Linux  - 56How to Change hostname in Linux  - 15How to Change hostname in Linux  - 90How to Change hostname in Linux  - 23How to Change hostname in Linux  - 72How to Change hostname in Linux  - 87How to Change hostname in Linux  - 16How to Change hostname in Linux  - 77How to Change hostname in Linux  - 64How to Change hostname in Linux  - 67How to Change hostname in Linux  - 88How to Change hostname in Linux  - 81How to Change hostname in Linux  - 44How to Change hostname in Linux  - 5How to Change hostname in Linux  - 38How to Change hostname in Linux  - 56How to Change hostname in Linux  - 54How to Change hostname in Linux  - 41How to Change hostname in Linux  - 47How to Change hostname in Linux  - 33How to Change hostname in Linux  - 61