How to Change hostname in Linux

As a System Admin, one must be aware of changing the hostname. If you have entered the wrong hostname during installation or requirement to change it, you can change it as below. Changing hostname involve two steps.
  • Change HOSTNAME value in /etc/sysconfig/network
  • Change host name in /etc/hosts

1. Display Hostname

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostname

2. Change Hostname

Edit /etc/sysconfig/network file as below, look for HOSTNAME= to update the desired hostname.

Ex: Before change:

[root@localhost sysconfig]# cat network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain

[root@localhost sysconfig]#   vi /etc/sysconfig/network
save the file

Ex: After change:

[root@localhost sysconfig]# cat network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=Chandan.Pro
[root@localhost sysconfig]#

Next step would be change hostname in a hosts file.

Edit/etc/hosts file as below, look for current hostname and update desired hostname

Ex: Before change:

[root@localhost etc]# cat hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
[root@localhost etc]#

vi /etc/hosts
save the file

Ex: After change:

[root@localhost etc]# cat hosts
127.0.0.1 sisrv.net
::1 localhost6.localdomain6 localhost6
[root@localhost etc]#

3. Change hostname on terminal

[root@localhost etc]# hostname sisrv.net

Verification

[root@localhost etc]# hostname
sisrv.net
[root@localhost etc]#

Done! Your Linux hostname is changed!

  • linux hostname, change hostname
  • 1 utilizatori au considerat informația utilă
Răspunsul a fost util?

Articole similare

How to Set Up a Mac for Your Kids

Providing children with access to a computer and the internet is increasingly important, but so...

How to Get Help With a Command from the Linux Terminal

Whether you’re an inexperienced terminal user or a grizzled veteran, you won’t always know the...

How to change the ssh port on Linux

To Change the SSH Port for Linux Server Connect to your server via SSH Switch to the root...

How To Install screenFetch in Linux

If you've browsed Linux groups on social media, you've probably seen a lot of screenshots that...

Static IP vs. Dynamic IP Address

A static IP address is one that remains fixed and never changes. The PC always sees the same...

Powered by WHMCompleteSolution