Ubuntu Server: How to Change Your Hostname

Changing the hostname of your Ubuntu server installation is a pretty simple affair.

To view the current hostname of your system, simply enter hostname.

Now to affect a termporary change of hostname, you could simply use:

sudo hostname mynewhostname

However, be careful here as this is really just a temporary hostname change and won’t be saved when the system restarts. The reason for this is because the hostname is usually set on system startup when the system loads the detail from a file, generally located at “/etc/hostname”.

So in order to permanently change your system’s hostname, you need to edit the correct host-related files like so:

sudo nano /etc/hosts

Set your new desired hostname next to the entry for 127.0.1.1 (leaving the 127.0.0.1 localhost entry as is). Next, run:

sudo nano /etc/hostname

Simply enter your desired hostname on a single line and save.

Once you have made your changes and saved both of the files, you should be good to go – as you can test out for yourself by simply rebooting your machine with a good old sudo reboot and then checking with hostname!

Nifty.

You might also enjoy:

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in Software & Websites, Tutorials and tagged , , , , . Bookmark the permalink.
    blog comments powered by Disqus