Change Hostname In Linux


Changing hostname is not a usual task that we perform in our day today activity, however if somehow, we’ve to change the hostname, then we can do it using 2 methods.


(1) nmcli 

(2) hostnamectl                                  

                                  

NOTE: changing hostname can also cause to change the configuration in several areas like replacing the old hostname with new one in dns server or hosts file etc.

 

                                        Types Of Hostnames

 

Linux system now has 3 types of hostnames configured:


(1)   Static Hostname: Stored in /etc/hosts file or we can say the  hostname set by kernel. Typically, service use this name as the hostname


(2)  Pretty Hostname: A descriptive name or a user-defined hostname, such as proxy centre in data centre A.


 (3)  Transient Hostname: A fall-back value that is typically received from the network configuration or how the network views our system.

  

                                            nmcli Utility

This utility is use to update the system hostname however other utilities might use a different parameter such as static or persistent.

 

STEP 1:  Display current hostname

 

[root@oratest ~]# nmcli general hostname

oratest.localdomain

 

STEP 2: Set new hostname

 

[root@oratest ~]# nmcli general hostname oraview.in

 

NOTE: oraview.in in above command is the new hostname


STEP 3: Network manager automatically restart the system-hostnamed to activate the new name. however, below manual action is required if we don’t want to restart the host.

 

[root@oratest ~]# systemctl restart network.service

 

STEP 4: Validate hostname

 

[root@oratest ~]# hostname -f

oraview.in

 [oracle@oraview.in db_1]$ ping -c 2 oraview.in

PING oraview.in (192.168.10.12) 56(84) bytes of data.

64 bytes from oraview.in (192.168.10.12): icmp_seq=1 ttl=64 time=0.206 ms

64 bytes from oraview.in (192.168.10.12): icmp_seq=2 ttl=64 time=0.039 ms

--- oraview.in ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1064ms

rtt min/avg/max/mdev = 0.039/0.122/0.206/0.084 ms


                                    hostnamectl utility


Another available method to update the hostname is hostnamectl utility.


STEP 1: Display hostname

 

[root@oraview ~]# hostnamectl status --static

oraview.in

 

STEP 2: Change hostname using hostnamectl utility

 

[root@oraview ~]# hostnamectl set-hostname oracleview.example.com

 

STEP 3: Restart network service

 

[root@oracleview ~]# systemctl restart network.service

 

NOTE: Active shell users must relogin to take the effect.

 

STEP 4: Validate new hostname

 

[root@oracleview ~]# hostname -f

oracleview.example.com







Post a Comment

Previous Post Next Post