How to Change Hostname on CentOs 7 server?
What is a Hostname?
A hostname is a unique name that is assigned to a particular computer within a network. Over a network or the internet, the hostname was used to identify the device.
Simply, it is the name of the server that works on the network. If you have set the hostname, you can easily find your server between various servers on your network.
In another article, we wrote about, how to install cPanel on CentOs 7, which you can go ahead and read here.
Types of hostnames:
- Static hostname – How the network views your system
- Pretty hostname – The user-defined hostname
- Transient hostname – Set by the kernel
It is the most important one. We can change the static hostname by editing the /etc/hostname file. This Hostname is used to identify the server among the machines.
It is very user-friendly. It can be set by the user and not permitted for the machines. Pretty hostname allows more characters and punctuation.
The transient hostname can only be set and maintained in the kernel. By default, it is the same as the Static hostname. It is dynamic, so it will be changed once you have restarted the server.
If you want a temporary hostname and don’t want to change it permanently, you can set this for your work.
Change Host Name on CentOs7 server
The Centos7 will only accept the fully qualified domain name for both Static and Transient hostname
The acceptable values are,
- The hostname will be lower-case letters a to z
- Can contain numbers 0 to 9
- Can Contain dot(.) and special characters
- Periods and hyphens
- Hostnames can contain between 2 and 63 characters
- Must start and end with a number or letter
To change the hostname on your server, you must need root access for your server.
Next, you have to connect your server via SSH or open the terminal from your server.
Step 1: Check the current Hostname
Type the below command to know the current hostname
Step 2: Set the new Hostname
Run the below command to change the Hostname,
To change static hostname:
Syntax: sudo hostnamectl set-hostname “hostname.example.com” –static
To change pretty hostname:
Syntax: sudo hostnamectl set-hostname “Pretty HostName” –pretty
To change Transient hostname:
Syntax: sudo hostnamectl set-hostname hostname.example.com –transient
In centOS7, we have several ways to change the hostname. Now you have read the simple and quick way to change the Hostname.