How To Change Hostname Ubuntu 16.04

Step 1: Change /etc/hostname

1.1 Display hostname

sudo hostnamectl
root@srv6:/# sudo hostnamectl
   Static hostname: srv6
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 5d1a62d58946610fd747a1095bdcca8d
           Boot ID: 0da81775bd7943a89fe2824a34aee404
    Virtualization: vmware
  Operating System: Ubuntu 16.04.5 LTS
            Kernel: Linux 4.4.0-131-generic
      Architecture: x86-64
root@srv6:/#

1.2 Set hostname

sudo hostnamectl set-hostname ubuntu.home.local

1.3 Verify hostname change

sudo hostnamectl
root@srv6:/# sudo hostnamectl
sudo: unable to resolve host ubuntu.home.local
   Static hostname: ubuntu.home.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 5d1a62d58946610fd747a1095bdcca8d
           Boot ID: 0da81775bd7943a89fe2824a34aee404
    Virtualization: vmware
  Operating System: Ubuntu 16.04.5 LTS
            Kernel: Linux 4.4.0-131-generic
      Architecture: x86-64
root@srv6:/#

1.4 Verify /etc/hostname

sudo nano /etc/hostname
# Ourout in file should look like this:

ubuntu.home.local

Exit

Step 2: Set static table lookup for hostnames

2.1 Edit /etc/hosts

sudo nano /etc/hosts
127.0.0.1       localhost
127.0.1.1       srv6

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

Change the old hostname to the new one

127.0.0.1       ubuntut
127.0.1.1       ubuntu.home.local ubuntu

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

Exit and Save

2.2 Verify change

sudo hostname
steken@ubuntu:~$ sudo hostname
ubuntu.home.local
steken@ubuntu:~$

2.3 Reboot

sudo reboot

2.4 Verify that changes work after reboot

sudo hostnamectl
sudo hostname
steken@ubuntu:~$ sudo hostnamectl
[sudo] password for steken:
   Static hostname: ubuntu.home.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 5d1a62d58946610fd747a1095bdcca8d
           Boot ID: 25e9983f934d433fa29234dcc5823446
    Virtualization: vmware
  Operating System: Ubuntu 16.04.5 LTS
            Kernel: Linux 4.4.0-131-generic
      Architecture: x86-64
steken@ubuntu:~$ sudo hostname
ubuntu.home.local
steken@ubuntu:~$

Donate