hostname is set during the installation process of Ubuntu. The hostname is used for many things, especially as an identifier within the local network.

You can change the hostname of your Ubuntu system 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
  3. Set new hostname using hostnamectl.
    user@host:~$ sudo hostnamectl set-hostname newhostname
    [sudo] password for user:
  4. Run hostname again to confirm hostname change.
    user@host:~$ hostname
  5. Run a new shell to see the change in shell prompt.
    user@host:~$ bash

    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)
Discuss the article:

Comment anonymously. Login not required.