Ubuntu set hostname permanently (computer name) command

I am a new Ubuntu Linux server user. My server is running on AWS cloud. By default they set my VM name to ‘ip-172-26-12-173’ during creation of VM but now I would like to change the computer name to ‘wsl-us-west2-www1’. How do I set hostname permanently on Ubuntu Linux 18.04 LTS? Can you tell me more about Ubuntu command to set hostname permanently?

Introduction : You can use the hostnamectl command to see or set the system’s host name. The host name or computer name is usually at system startup in /etc/hostname file. Open the terminal application and type the following commands to set or change hostname or computer name on Ubuntu Linux.

ADVERTISEMENTS

Ubuntu set hostname permanently (computer name) command

The procedure to change hostname is as follows on Ubuntu:

  1. Open the terminal application
  2. Login to remote Ubuntu server using the ssh user@server-ip-here
  3. To change hostname (Computer Name) in Ubuntu type: hostnamectl set-hostname wsl-us-west2-www1
  4. Verify new change by typing hostnamectl

Let us see all commands in details.

How to find current hostname on Ubuntu

Type the following hostnamectl command $ hostnamectl
Ubuntu display current hostname command

Ubuntu change hostname permanently

Simply type the following command:
$ sudo hostnamectl set-hostname wsl-us-west2-www1
Verify new changes with the following command:
$ hostnamectl
One can use the cat command too:
$ cat /etc/hostname
Ubuntu set hostname permanently command

Do I need to reboot my Ubuntu VM to change take effect?

No. You do not need to reboot the Linux box. Just log in again using the ssh command and your PS1 (bash shell prompt) will be updated too:
$ ssh vivek@aws-server-ip-here

Ubuntu changed hostname permanently and verified with ssh

Conclusion

You learned how to use the hostnamectl command to query and change the Ubuntu system hostname and related settings.

This entry is 13 of 19 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command
  16. CentOS 8 Linux set hostname permanently (computer name) command
  17. Ubuntu 20.04 LTS set hostname permanently (computer name) command
  18. Set / Change FQDN on Ubuntu 20.04 LTS
  19. Alpine Linux - Setting system hostname
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • Po May 13, 2018 @ 13:13

    How to change hostname in Ubuntu 18.04 LTS server?
    hostnamectl set-hostname "your-name-here"

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.