How To Set Or Change A Hostname In CentOS 7

hostname is simply the name a server goes by on the network. Setting a unique hostname is an excellent way to quickly find and identified different servers on your network.

There are three 3 types of hostnames.

  1. The static hostname is the most important one, and it’s stored in the /etc/hostname file. This hostname is used among machines to identify a particular server.

Step 2: Set a New Static Hostname

As CentOS 7 only allows Fully Qualified Domain Names (FQDN’s), double-check the hostname you plan to use.

Acceptable values include lower-case letters a to z, numbers 0 to 9, period, and hyphen. Also, it allows between 2 and 63 characters.

Type in the following command in the terminal:

hostnamectl set-hostname

Step 4: Edit the /etc/hosts File

sudo vim /etc/hosts

Start by opening the hosts file by typing:

In the text editor, look for the line that begins with (the IP address that refers to the system you are working on). It should read:  localhost localhost.localdomain localhost 4 localhost4.localdomain4 old.hostname

Change the entry old.hostname to – and spell it the same as in Step 2.

Save the file and exit.

  1. Using a text editor, open the server’s /etc/sysconfig/network file. The following example shows how to open this file in the GNU nano text editor: # sudo nano /etc/sysconfig/network

 652 total views,  3 views today


So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *