fbpx

How to change the hostname on an Ubuntu 18.04 server

If you’re used to looking for /etc/hostname and /etc/hosts  and the hostname command to change your hostname, things are much more intricate with Ubuntu 18.04. Here are the various places you have to go and look to change the hostname:

hostnamectl display the current hostname

To change:

sudo hostnamectl set-hostname new-hostname

Then

/etc/hosts look for a line such the one below. Warning, do not change localhost. The localhost entry may be used and as convention localhost is always 127.0.0.1

127.0.0.1   localhost
127.0.0.1   old-hostname

You might also have a /etc/cloud/cloud.cfg file. If so, set the following entry:

preserve_hostname: true

In summary:

hostnamectl set-hostname new-hostname
/etc/hosts
/etc/cloud/cloud.cfg

Reference:
https://linuxize.com/post/how-to-change-hostname-on-ubuntu-18-04/

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

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

Scroll to Top