81
General Linux / Change Hostname in CentOS Linux 5/6
« Last post by akhilt on August 04, 2018, 10:26:34 am »Change Hostname in CentOS Linux 5/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 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 hostname
Type the following command:
Sample outputs:
To display current domain name:
Type the following command:
Sample outputs:
Hostname change procedure on CentOS
Open the terminal or login to the remote server using ssh client. Edit /etc/sysconfig/network file, enter:
Find and modify HOSTNAME value to set to FQDN such as 'server.domainname.com'
Save and close the file.
Edit hosts file
Edit /etc/hosts file, enter:
You need to set or change the host that is set to your IP address on the server.
Save and close the file.
Set hostname manually without rebooting the server
Type the following command:
Restart the CentOS networking and other services
You need to restart the networking service on CentOS Linux, enter:
Verify new hostnames
Simply type the following commands:
Hoping the information will come in handy,
Thank You!
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 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 hostname
Type the following command:
Code: [Select]
# hostname
Sample outputs:
Code: [Select]
server1
To display current domain name:
Type the following command:
Code: [Select]
# dnsdomainname
Sample outputs:
Code: [Select]
domainname.com
Hostname change procedure on CentOS
Open the terminal or login to the remote server using ssh client. Edit /etc/sysconfig/network file, enter:
Code: [Select]
# vi /etc/sysconfig/network
Find and modify HOSTNAME value to set to FQDN such as 'server.domainname.com'
Code: [Select]
HOSTNAME="server.domainname.com"
Save and close the file.
Edit hosts file
Edit /etc/hosts file, enter:
Code: [Select]
# vi /etc/hosts
You need to set or change the host that is set to your IP address on the server.
Code: [Select]
127.0.0.1 localhost
10.240.40.209 server.domainname.com server
Save and close the file.
Set hostname manually without rebooting the server
Type the following command:
Code: [Select]
# hostname server.domainname.com
Restart the CentOS networking and other services
You need to restart the networking service on CentOS Linux, enter:
Code: [Select]
# service network restart
ORCode: [Select]
# /etc/init.d/network restart
Verify new hostnames
Simply type the following commands:
Code: [Select]
# hostname
# dnsdomainname
Hoping the information will come in handy,
Thank You!