Hostname is used to identify a system to the local network. On Ubuntu, system hostname is set during the installation process.

Hostname information is set on /etc/hostname. You can change the hostname of your Ubuntu system at any time after the installation by editing the file or by using hostnamectl command from the terminal.

Steps to change system hostname in Ubuntu:

  1. Launch terminal.
  2. Check current hostname using hostname command.

    user@host:~$ hostname host
  3. Set new hostname using hostnamectl.

    user@host:~$ sudo hostnamectl set-hostname newhostname [sudo] password for user:
  4. Run hostname command again to confirm hostname change.

    user@host:~$ hostname newhostname
  5. Run a new shell to see the change in shell prompt.

    user@host:~$ bash user@newhostname:~$

    This only works if $PS1 is set to display the hostname.

Guide compatibility:

Operating System
Ubuntu 16.04 LTS (Xenial Xerus)
Ubuntu 16.10 (Yakkety Yak)
Ubuntu 17.04 (Zesty Zapus)
Ubuntu 17.10 (Artful Aardvark)
Ubuntu 18.04 LTS (Bionic Beaver)
Ubuntu 18.10 (Cosmic Cuttlefish)
Ubuntu 19.04 (Disco Dingo)