One of the essential tasks for a system administrator is to know how to change the hostname.
If you have entered the wrong hostname during installation or requirement to change it, you can change it as below.
Changing hostname involves two steps.
- Change HOSTNAME value in
/etc/sysconfig/network
- Change hostname in
/etc/hosts
1. Display Hostname
[[email protected] ~]# hostname
localhost.localdomain
[[email protected] ~]# hostname
2. Change Hostname
Edit /etc/sysconfig/network file as below, look for HOSTNAME= to update the desired hostname.
Ex: Before change:
[[email protected] sysconfig]# cat network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
[[email protected] sysconfig]# vi /etc/sysconfig/network save the file
Ex: After change:
[[email protected] sysconfig]# cat network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=Chandan.Pro
[[email protected] sysconfig]#
Next step would change hostname in a hosts file.
Edit/etc/hosts file as below, look for current hostname and update the desired hostname
Ex: Before change:
[[email protected] etc]# cat hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
[[email protected] etc]#
vi /etc/hosts save the file
Ex: After change:
[[email protected] etc]# cat hosts
127.0.0.1 chandan.pro
::1 localhost6.localdomain6 localhost6
[[email protected] etc]#
3. Change hostname on terminal
[[email protected] etc]# hostname chandan.pro
Verification
[[email protected] etc]# hostname
chandan.pro
[[email protected] etc]#
Done! Your Linux hostname is changed!
Learn more about Linux administration here.
Leave a Reply