I am a new CentOS Linux server user. How do I change hostname on CentOS Linux? How can I change server hostname on CentOS Linux 6?
You need to use the following commands to set or view current hostname, domain name and/or FQDN (Fully Qualified Domain Name):
- dnsdomainname command : Display the system’s DNS domain name.
- hostname command : Show or set the system’s host name.
You also need to edit the following files for a hostname change:
- /etc/sysconfig/network file.
- /etc/hosts file.
In this tutorial, I will show you how to set/change a server hostname in CentOS Linux to “server.servernoobs.com”.
Display current hostname
Type the following command:
# hostname
Sample outputs:
server1
To display current domain name, type the following command:
# dnsdomainname
Sample outputs:
servernoobs.com
Hostname change procedure on CentOS
Open the terminal or login to the remote server using ssh client. Edit /etc/sysconfig/network file, enter:
# nano /etc/sysconfig/network
Find and modify HOSTNAME value to set to FADN such as server.servernoobs.com:
HOSTNAME="server.servernoobs.com"
Save and close the file.
Edit hosts file
Edit /etc/hosts file, enter:
# nano /etc/hosts
You need to set or change the host that is set to your IP address on server.
127.0.0.1 localhost 108.134.20.207 server.servernoobs.com server # Added by ServerNoobs
Save and close the file.
Set hostname manually without rebooting the box
Type the following command:
# hostname server.servernoobs.com
Restart the CentOS networking and other services (if any)
You need to restart the networking service on CentOS Linux, enter:
# service network restart
OR
# /etc/init.d/network restart
Verify new hostnames
Simply type the following commands:
# hostname
# dnsdomainname
Originally posted 2016-02-27 00:16:25.