0% found this document useful (0 votes)
30 views2 pages

Change Hostname in Linux

The document outlines two methods for changing the hostname in Linux: using the nmcli and hostnamectl utilities. It explains the types of hostnames (static, pretty, and transient) and provides step-by-step instructions for displaying, setting, and validating the new hostname. Additionally, it notes that changing the hostname may require updates in other configurations like DNS or hosts files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Change Hostname in Linux

The document outlines two methods for changing the hostname in Linux: using the nmcli and hostnamectl utilities. It explains the types of hostnames (static, pretty, and transient) and provides step-by-step instructions for displaying, setting, and validating the new hostname. Additionally, it notes that changing the hostname may require updates in other configurations like DNS or hosts files.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

nmcli 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

[Link]

Step 2: Set new hostname

[root@oratest ~]# nmcli general hostname [Link]

NOTE: [Link] 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 [Link]

Step 4: Validate hostname

[root@oratest ~]# hostname -f


[Link]

[oracle@[Link] ~]$ ping -c 2 [Link]

PING [Link] ([Link]) 56(84) bytes of data.


64 bytes from [Link] ([Link]): icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from [Link] ([Link]): icmp_seq=2 ttl=64 time=0.046 ms
--- [Link] ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1024ms
rtt min/avg/max/mdev = 0.033/0.039/0.046/0.009 ms

hostnamectl utility

Another available method to update the hostname is hostnamectl utility.

STEP 1: Display hostname

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


[Link]

STEP 2: Change hostname using hostnamectl utility

[root@oraview ~]# hostnamectl set-hostname [Link]

STEP 3: Restart network service

[root@oracleview ~]# systemctl restart [Link]

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

STEP 4: Validate new hostname

[root@oracleview ~]# hostname -f


[Link]

You might also like