Press "Enter" to skip to content

Ubuntu 24.04 Change hostname

Last updated on August 11, 2024

Pre-Check

## check OS/kernel version
root@baseline:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04 LTS
Release:    24.04
Codename:   noble

root@baseline:~# uname -r
6.8.0-39-generic

Change hostname

## check current hostname setting
root@baseline:~# hostnamectl
 Static hostname: baseline
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 9850dbb1123f4fea8c517d4e5f567082
         Boot ID: da582d7628fd430eb45359ea419d5055
  Virtualization: vmware
Operating System: Ubuntu 24.04 LTS
          Kernel: Linux 6.8.0-39-generic
    Architecture: arm64
 Hardware Vendor: VMware, Inc.
  Hardware Model: VMware20,1
Firmware Version: VMW201.00V.21805430.BA64.2305221830
   Firmware Date: Mon 2023-05-22
    Firmware Age: 1y 2month 2w 6d
    
## change to new hostname
root@baseline:~# hostnamectl set-hostname node1

## evaluate it
root@baseline:~# hostnamectl
 Static hostname: node1
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 9850dbb1123f4fea8c517d4e5f567082
         Boot ID: da582d7628fd430eb45359ea419d5055
  Virtualization: vmware
Operating System: Ubuntu 24.04 LTS
          Kernel: Linux 6.8.0-39-generic
    Architecture: arm64
 Hardware Vendor: VMware, Inc.
  Hardware Model: VMware20,1
Firmware Version: VMW201.00V.21805430.BA64.2305221830
   Firmware Date: Mon 2023-05-22
    Firmware Age: 1y 2month 2w 6d

Change /etc/hosts

## change local hosts resolve settings
root@baseline:~# vim /etc/hosts
root@baseline:~# cat /etc/hosts
127.0.0.1 localhost
192.168.70.5 node1

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

## evaluate resolve setting
root@baseline:~# ping node1 -c 1
PING node1 (192.168.70.5) 56(84) bytes of data.
64 bytes from node1 (192.168.70.5): icmp_seq=1 ttl=64 time=0.047 ms

--- node1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.047/0.047/0.047/0.000 ms

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *