How to Change Host-Name in Linux Without Rebooting
As to identify any person or place we need a name in the same way to identify a system / server we need to give a name to it.
In This tutorial we will discuss about changing hostname in Linux (Redhat, CentOS).
When you install any Linux based operating system host/server name will either localhost or localhost.localhost ,
We can change hostname from 5 locations to apply changes globally in all locations.
- hostname command
/etc/sysconfig/network files contains network information and hostname, to change the hostname edit thid file with vi editor.
# vim /etc/sysconfig/network
Add you desire host-name as below and save it
Next configuration file is /etc/hosts, this file contains DNS FQDN name edit this file and entry as below.
# vim /etc/hosts
Next command is hostname, using this command you can see the existing hotname as well change the current hostname.
to check hostname simply type #hostname and enter to change the hostname type #hostname newname
# hostname tecgeeks
after configuring all the files you need to restart network service to reflect the changes, run the below command to restart the network service.
#service network restart or #/etc/init.d/network restart
If you do not want to restart the network service, append the file /proc/sys/kernel/hostname to reflect the changes without restarting any service, run below command and close the terminal and reopen to see the changes.
#echo “tecgeeks” > /proc/sys/kernel/hostname
The /etc/hostname file should contain the hostname only, Edit this file and add only hostname not FQDN.
[root@Tecgeeks ~]# cat /etc/hostname
Hope it will help you.
Your Profile can also be listed here, Want to share you Experience, become a TecGeeks Author Submit here
Latest posts by Rahul Kansi (see all)
- Top 10 Linux supporting Laptops in India with Best Price and features - March 30, 2017
- Former US president admits he ordered cyber attacks on North Korea - March 6, 2017
- Deny SSH Access to Particular User and Group - February 25, 2017