How to change hostname on Ubuntu 18.04 Bionic Beaver Linux - LinuxConfig.org


#1

The objective is to change system's hostname on Ubuntu 18.04 Bionic Beaver Linux ( server or desktop ).

Use hostnamectl command to retrieve a current system hostname:

$ hostnamectl
   Static hostname: ubuntu
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ceb8b579410b472899a95049f8a61e05
           Boot ID: 3f73eea15fb34a38937488149143d9d3
    Virtualization: oracle
  Operating System: Ubuntu Bionic Beaver
            Kernel: Linux 4.13.0-32-generic
      Architecture: x86-64

This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-change-hostname-on-ubuntu-18-04-bionic-beaver-linux

NOTE: SOME OF THE POSTS BELOW ARE TRANSFERRED FROM LINUXCONFIG DISQUS COMMENTS.

#2

Anders Jackson

If you also get a static address, you should change 127.0.1.1 in /e/hosts to the proper address.
And you should use the full FQDN nsmr in /e/hosts as first name.


#3

Andy Madge

This is incomplete, you also need to update the file /etc/cloud/cloud.cfg otherwise it will revert the hostname on next reboot.

You need to change:
preserve_hostname: false

to:
preserve_hostname: true


#4

Lubos Rendek Mod -> Andy Madge
Hi Andy,

thank you for your input. I’m sure some of the readers will benefit from your comment. However, /etc/cloud/cloud.cfg does not seem to be a part of a default Ubuntu 18.04 Desktop/Server installation. From this reason /etc/cloud/cloud.cfg is not part of this guide as it not possible to cater for any possible custom configuration Ubuntu 18.04 users might have.


#5

Andy Madge -> Lubos Rendek

It’s definitely part of Ubuntu Server 18.04. I did a default install yesterday and then needed to change hostname, that’s why I ended up on this page in the first place.


#6

Lubos Rendek Mod -> Andy Madge

Hi Andy,

thank you for your persistence. It appears that this is a recent change and I have been using “old” 18.04 server image. Downloaded and installed new Ubuntu 18.04 Server and sure enough the cloud config was there. The article will be updated shortly.

thank you again for your input. Much appreciated…!

Lubos