How To Easily Change Your Hostname On Ubuntu, Linux Mint, Debian Or Elementary OS System, Without Restarting The System

Hello Linux Geeksters. In this quick guide I will show you how to easily change the hostname on your Ubuntu, Linux Mint, Debian or Elementary OS system, without having to reboot your system.

First, we have to temporary change of hostname:

$ sudo hostname NewHostname

To apply the changes, we reload the shell (if you are using a different shell, type its name in the terminal):

$ bash

Now, let’s make this change persistent. We have to change the old hostname with the new one, in both the /etc/hostname and /etc/hosts files (the two sed oneliners will replace the old hostname with the new one, in the needed files):

$ sudo sed -i 's/OldHostname/NewHostname/g' /etc/hostname
$ sudo sed -i 's/OldHostname/NewHostname/g' /etc/hosts

In the below screenshot, I have replaced the hostname ubuntu with the hostname trusty (the grep commands in the screenshot are just to display the changes, before and after the sed one-liners)

How To Easily Change Your Hostname On Ubuntu, Linux Mint, Debian Or Elementary OS System, Without Restarting The System

 

Tagged with: , , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!