A 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.
- 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 my.new-hostname.server
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
127.0.0.1 (the IP address that refers to the system you are working on). It should read:
127.0.0.1 localhost localhost.localdomain localhost 4 localhost4.localdomain4 old.hostname
Change the entry
my.new-hostname.server – and spell it the same as in Step 2.
Save the file and exit.
- 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