Hostname or computer name is used to identify a system to the local network. On Ubuntu, you can see the hostname of your system when launching the terminal.

You first set the system's hostname during Ubuntu's installation. Hostname information is stored on the /etc/hostname file. You can change the hostname of your Ubuntu system at any time after the installation by manually editing the /etc/hostname file or by using a helper program such as hostnamectl.

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. Check content of /etc/hostname file.
    user@host:~$ cat /etc/hostname
  5. Run hostname command again to confirm hostname change.
    user@host:~$ hostname
  6. 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.

  7. Reboot your system for the change to be applied systemwide (optional).
    user@newhostname:~$ sudo reboot
Discuss the article:

Comment anonymously. Login not required.