How to Change Hostname on CentOS Linux Print

  • 0

How to Change Hostname on CentOS Linux

Changing the hostname on CentOS Linux involves 4 easy steps. Follow the instructions below:

Step 1: Modify /etc/sysconfig/network

Open the /etc/sysconfig/network file with your favorite text editor, and modify the HOSTNAME value to match your Fully Qualified Domain Name (FQDN) hostname:

sudo nano /etc/sysconfig/network

Change the HOSTNAME value to your new hostname:

HOSTNAME=myserver.domain.com

Step 2: Update the /etc/hosts File

Next, modify the /etc/hosts file to associate your server's IP address with the new hostname. This is necessary for internal networking:

sudo nano /etc/hosts

Ensure that the new hostname is reflected in the appropriate entry in the hosts file.

Step 3: Use the Hostname Command

The hostname command allows you to change the hostname temporarily for the current session. However, this does not update the hostname for other running programs or ensure persistence after a reboot.

hostname myserver.domain.com

Step 4: Restart Networking

Finally, restart the networking service to apply the changes and make sure they persist across reboots:

/etc/init.d/network restart

Was this answer helpful?

« Back