How To Set Hostname Ubuntu 18.04 Bionic Beaver

Step 1: Change hostname

1.1 Display hostname

sudo hostnamectl
root@srv6:~$ hostnamectl
   Static hostname: srv6
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 9eb79538e7bb4a768a4eef71dd78124c
           Boot ID: 95a2a346ec2e44b3beddbd02b517ed29
    Virtualization: vmware
  Operating System: Ubuntu 18.04.1 LTS
            Kernel: Linux 4.15.0-36-generic
      Architecture: x86-64
root@srv6:~$

1.1.a Set hostname

sudo hostnamectl set-hostname plex.home.local

Step 2: Verify parameter change

2.1 Verify hostname change

sudo hostnamectl
root@srv6:~$ sudo hostnamectl
   Static hostname: plex.home.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 9eb79538e7bb4a768a4eef71dd78124c
           Boot ID: 95a2a346ec2e44b3beddbd02b517ed29
    Virtualization: vmware
  Operating System: Ubuntu 18.04.1 LTS
            Kernel: Linux 4.15.0-36-generic
      Architecture: x86-64
root@srv6:~$

2.2 Verify /etc/hostname

sudo nano /etc/hostname
# Output in /etc/hostname
plex.home.local

Exit

Step 3: Set static table lookup for hostname

3.1 Edit /etc/hosts

sudo nano /etc/hosts
127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6

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

3.1.a Change the old hostname

127.0.0.1       plex.home.local         plex
::1             plex.home.local6        plex6

Exit and Save

3.2 Check if the  “cloud.cfg” is installed (This part can be skipped if the file is missing)

sudo ls -l /etc/cloud/cloud.cfg
root@srv6:~$ ls -l /etc/cloud/cloud.cfg
-rw-r--r-- 1 root root 3169 Apr 27 16:30 /etc/cloud/cloud.cfg
root@srv6:~$

3.2.a Edit cloud.cfg

sudo nano /etc/cloud/cloud.cfg

3.2.b Change the preserve_hostname value from false to true

# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true

# Example datasource config
# datasource:
#    Ec2:

Exit and Save

Step 4: Verify with a reboot

4.1 Reboot to verify change

sudo reboot

4.2 Verify hostname

sudo hostname

sudo hostnamectl
root@plex:~$ hostname
plex.home.local
steken@plex:~$ sudo hostnamectl
[sudo] password for steken:
   Static hostname: plex.home.local
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 9eb79538e7bb4a768a4eef71dd78124c
           Boot ID: bae1972a359d4ee3b497ac74e1c6a661
    Virtualization: vmware
  Operating System: Ubuntu 18.04.1 LTS
            Kernel: Linux 4.15.0-36-generic
      Architecture: x86-64
root@plex:~$

Donate