Instructions

Obtain current hostname

Use

hostnamectl

command to retrieve a current system hostname:

$ hostnamectl   Static hostname: ubuntu         Icon name: computer-vm           Chassis: vm        Machine ID: ceb8b579410b472899a95049f8a61e05           Boot ID: 3f73eea15fb34a38937488149143d9d3    Virtualization: oracle  Operating System: Ubuntu Bionic Beaver            Kernel: Linux 4.13.0-32-generic      Architecture: x86-64

Change Hostname

hostnamectl

command can also be used to set new or update the current hostname on Ubuntu 18.04 Bionic Beaver. The following

will change system’s static hostname to

linuxconfig

:

$ sudo hostnamectl set-hostname linuxconfig

Futhermore, check for the existence of

/etc/cloud/cloud.cfg

configuration. If the file exists edit the file and change the settings within:

FROM:preserve_hostname: falseTO:preserve_hostname: true

The above will preserve your new hostname after reboot.

Next, confirm the new hostname:

$ hostnamectl    Static hostname: linuxconfig         Icon name: computer-vm           Chassis: vm        Machine ID: ceb8b579410b472899a95049f8a61e05           Boot ID: 3f73eea15fb34a38937488149143d9d3    Virtualization: oracle  Operating System: Ubuntu Bionic Beaver            Kernel: Linux 4.13.0-32-generic      Architecture: x86-64
Your command line prompt will update to reflect the new hostname settings the next time you login.

Appendix

You may also want to update your /etc/hosts file so the system can resolve itself via new host name. Open /etc/hosts file:
$ sudo nano /etc/hosts
and append your new hostnane right after the old hostname:
$ cat /etc/hosts127.0.0.1       localhost127.0.1.1       ubuntu linuxconfig# The following lines are desirable for IPv6 capable hosts::1     localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodesff02::2 ip6-allrouters