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.
Ubuntu set hostname permanently (computer name) command
The procedure to change hostname is as follows on Ubuntu:
- Open the terminal application
- Login to remote Ubuntu server using the ssh user@server-ip-here
- To change hostname (Computer Name) in Ubuntu type: hostnamectl set-hostname wsl-us-west2-www1
- 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
Ubuntu change hostname permanently
Simply type the following command:
$ sudo hostnamectl set-hostname wsl-us-west2-www1
Verify new changes with the following command:
One can use the cat command too:
$ cat /etc/hostname
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
You learned how to use the hostnamectl command to query and change the Ubuntu system hostname and related settings.