Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Change Hostname in CentOS Linux 5/6  (Read 1460 times)

0 Members and 1 Guest are viewing this topic.

akhilt

  • Guest
Change Hostname in CentOS Linux 5/6
« 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:
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 OR
Code: [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! :)