Change Linux hostname [Ubuntu]

Change Linux hostname [Ubuntu]

I think everyone has already installed a virtual machine or hired a Cloud and come across the default name in the machine’s Hostname, generally it is the OS used. Or you entered a name and want to change it, but forgot how. In this post we will show TWO WAYS you can change your hostname easily.

Method number 1

1 - Place the desired name in the hosts file

vim /etc/hosts
Edit /etc/hosts

2 - Place the desired name in the hostname file

vim /etc/hostname
Edit /etc/hostname

3 - Place the new name directly into memory

echo "NAME_YOU_DESIDRE" > /proc/sys/kernel/hostname
Edit /proc/sys/kernel/hostname

4 - Log off and log back on or run “bash

Look our new hostname:

Changed hostname on linux

Method number 2

1 - Check if you have hostnamectl in your distribution

hostnamectl status
hostnamectl status output

2 - Enter the name you want, in my example I used “tutorial”

hostnamectl set-hostname tutorial

  Change hostname via hostnamectl on linux

3 - Log off and log back on or run “bash”

Let’s see the hostname:

Changed hostname on linux using hostnamectl

That’s it! From this tutorial we learned two really cool ways to change your machine’s hostname. The tutorial was made in Ubuntu, but it should work in your distribution.

Finally, thank you for reading and we hope this post has helped you in some way! If you have any questions, please contact us at Telegram , Facebook or Instagram ! See more posts on IronLinux !