Change Hostname in CentOS Linux 5/6You 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 hostname.
You also need to edit the following files for a hostname change:
1.
/etc/sysconfig/network file.
2.
/etc/hosts file.
In this tutorial, I will show you how to set/change a server hostname in CentOS Linux to “
server.domainname.com”.
Display current hostnameType the following command:
# hostname
Sample outputs:
server1
To display current domain name:
Type the following command:
# dnsdomainname
Sample outputs:
domainname.com
Hostname change procedure on CentOSOpen the terminal or login to the remote server using ssh client. Edit
/etc/sysconfig/network file, enter:
# vi /etc/sysconfig/network
Find and modify HOSTNAME value to set to FQDN such as '
server.domainname.com'
HOSTNAME="server.domainname.com"
Save and close the file.
Edit hosts fileEdit
/etc/hosts file, enter:
# vi /etc/hosts
You need to set or change the host that is set to your IP address on the server.
127.0.0.1 localhost
10.240.40.209 server.domainname.com server
Save and close the file.
Set hostname manually without rebooting the serverType the following command:
# hostname server.domainname.com
Restart the CentOS networking and other servicesYou need to restart the networking service on CentOS Linux, enter:
# service network restart
OR
# /etc/init.d/network restart
Verify new hostnamesSimply type the following commands:
# hostname
# dnsdomainname
Hoping the information will come in handy,
Thank You!