How to Change Hostname in Ubuntu

Tutorial Dec 14, 2020

The hostname is a human-readable name assigned to computers or any other device connected to a network. Essentially, hostnames are like a computer’s nickname, and it helps to identify devices inside a network uniquely.

So that it would be easier to identify your device in a network, you may wish to change the hostname of your Ubuntu machine. And that is what this tutorial will help you with.

Note: It is recommended not to give two devices in the same network the same hostname. This defies the purpose of having hostnames and will result in conflicts between the two devices.

CURRENT HOSTNAME

When you launch a terminal in a fresh install of Ubuntu, by default, the hostname is the part after your username and the @ on the terminal. For example [email protected] tells us that usera is username and neptune is the hostname.

You can check your current hostname with the command hostname or,

cat /etc/hostname

CHANGING HOSTNAME

For assigning a new hostname, run the hostnamectl as shown below,

sudo hostnamectl set-hostname jupiter

Then we need to update /etc/hosts. So, open it in a text editor,

sudo vim /etc/hosts

And append the new hostname onto the lines containing the IPv4 address 127.0.0.1 and IPv6 address ::1, as shown below.

127.0.0.1	localhost jupiter

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback ip6-jupiter
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Exit the terminal which you were working on and launch another. You will see your new hostname on the terminal prompt string. That is all, you have successfully updated the hostname of your machine.

Tags

Lime

Simple, like quantum physics.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.