hostname is set during the installation process of Ubuntu. Hostname is used for many things especially a 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.
    [email protected]:~$ hostname
  3. Set new hostname using hostnamectl.
    [email protected]:~$ sudo hostnamectl set-hostname newhostname
    [sudo] password for user:
  4. Run hostname again to confirm hostname change.
    [email protected]:~$ hostname
  5. Run a new shell to see the change in shell prompt.
    [email protected]:~$ bash
    [email protected]:~$

    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)
Share this guide!
Discuss the article:

Comment anonymously. Login not required.