Change the hostname on CentOS 6 servers
This article demonstrates how to change a CentOS® 6 server hostname.
To change the hostname, perform the following steps:
-
To verify the current hostname, run the following command:
hostname -
To change the hostname in the network file, run the following command:
vi /etc/sysconfig/network -
Find the line that contains the variable "HOSTNAME", replace its value, and save the file:
HOSTNAME="server_name.domain.com"
-
To verify the current domain name, run the following command:
dnsdomainname -
To find your host IP address, run the following command:
ip addr show -
To change the domain name in the hosts file, run the following command:
vi /etc/hosts -
Add or modify the line with your host IP address, changing the domain name. Be sure to use
a fully qualified doman name (FQDN), such as the following example:10.0.2.15 server_name.domain.com server_name
-
Save your change and close the file.
-
After you change the domain name, you have to restart the network service. Use one of the
following commands:# service network restart or # /etc/init.d/network restart
-
To verify the changes, execute the following commands:
# hostname # dnsdomainname
Updated 4 months ago