How to Change Hostname on CentOS Linux

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
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Adding New IP Addresses to a CentOS/Fedora Server via SSH

Adding New IP Addresses to a CentOS/Fedora Server via SSH Follow the procedure below to add...

Disable Ping Response

Disable Ping Response What is a ping: A ping is a simple network utility used to check if a...

How To Block an IP Address

How To Block an IP Address Login to your Linux server via SSH. Blocking an IP Address To block...

How to Change SSH Port in CentOS

How to Change SSH Port in CentOS Login to your server via PuTTY or any other SSH client....

How to Reset MySQL Password

How to Reset MySQL Password If you have forgotten your MySQL root password, follow these steps...