use the hostnamectl
command on Ubuntu (and other Systemd based distros)
1hostnamectl set-hostname new.hostname.com
1# TEMPORARILY update hostname, will reset on reboot, will need a new Terminal to see the change
2hostname my.newHostname.com
1# make a more permanent change by updating `/etc/hosts` and `/etc/hostname` files
2sudo nano /etc/hostname
3sudo nano /etc/hosts
4sudo reboot
1# use the `hostnamectl` command
2hostnamectl set-hostname new.hostname.com
1hostnamectl
Static hostname: new.mydomain.com
Icon name: computer-vm
Chassis: vm
Machine ID: 23f62493fbfe41359cc6b4f409570ac1
Boot ID: 6916c2a8a1e049bda00ed12a189d90dd
Virtualization: xen
Operating System: Ubuntu 18.04.1 LTS
Kernel: Linux 4.15.0-1021-aws
Architecture: x86-64