To change the hostname, follow the steps shown below.
1. Use hostname command to Change Hostname
In this example, we’ll change the hostname from dev-server to prod-server.
hostname command by default will display the current hostname as shown below:
# hostname dev-server
The following will change the hostname to prod-server.
# hostname prod-server
Once the hostname is changed, verify that it has changed the hostname successfully. As you see below, it has changed the hostname to prod-server
# hostname prod-server
Update /etc/hosts
Now, you need to edit /etc/hosts file, enteR:
vi /etc/hosts