How to change hostname in Ubuntu 16

by Daniel Pham
Published: Updated:

How to change the hostname in Ubuntu 16. This article will guide you how to change hostname in Ubuntu server 16. This article can be used for operating systems that are using systemd. Currently, Ubuntu version 16 or later, CentOS version 7 or later, these are the two most popular OS are using systemd.

Check the current hostname

You run the following command to check the current hostname:

cat /etc/hostname
How to change hostname in Ubuntu 16
Command to check the current hostname in Ubuntu 16.

Change hostname in Ubuntu 16

For operating systems that use systemd (Ubuntu 16 or later, CentOS 7 or later), there is support for a command that lets you change hostnames quickly.

How to change hostname in Ubuntu 16
Command ‘hostnamectl’ to display the current hostname information.

To change the hostname using the hostnamectl command, type the following command:

hostnamectl set-hostname your-new-hostname

For example, i will set the new hostname is writebash:

hostnamectl set-hostname writebash

After you run the command, you must exit the current ssh session or logout in the console window. You can then login and check the new hostname.


Change hostname in older Ubuntu

For older Ubuntu OSs, do not use systemd. You must change the hostname in the following two files:

nano /etc/hostname

In the /etc/hostname file, there is only one line. You delete the old hostname in the file and replace the new hostname.

nano /etc/hosts
How to change hostname in Ubuntu 16
Change hostname in /etc/hosts file.

After changing the hostname in the two files above, you reboot the system.



This article is about how to change the hostname in the Ubuntu operating system in general and the operating system Ubuntu server 16 in particular. To note with the Ubuntu operating system older than 16, you should change and reboot the system without installing anything.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.