Logo

How to Change Hostname on Ubuntu 21.04

Aug 19, 2021

How do you view your hostname?

Step 1 : You need to use the hostname command or hostnamectl command

hostname

Step 2 : Output from the hostname command

Setting the hostname

Step 1 :Changing the hostname is fairly simple. To do this, we can use the hostnamectl command as root or with sudo.

sudo hostnamectl set-hostname devtutorial

Step 2 : Open the /etc/hosts file and change the old hostname to the new one.

sudo nano /etc/hosts

Step 3 : Verify the change

hostname