Changing the hostname on Ubuntu 18.04 LTS
Changing the hostname on Ubuntu 18.04 LTS
February 4, 2020
Note
This post may be partially machine- or AI-translated. If there is any discrepancy, the Korean version takes precedence.
This is how to change the hostname on Ubuntu 18.04 LTS.
Check the current hostname
Check the currently configured hostname.
$ hostnamectlResult
The string after Static hostname: is the current hostname.
buffashe@ubuntu:~$ hostnamectl
Static hostname: ubuntu
Icon name: computer-vm
Chassis: vm
Machine ID: 90e7fb5479a64e678d0e81c987f49dd9
Boot ID: 4df6f5dd0fb64df2a7a876a3114a29c4
Virtualization: oracle
Operating System: Ubuntu 18.04.4 LTS
Kernel: Linux 4.15.0-76-generic
Architecture: x86-64
buffashe@ubuntu:~$Edit cloud.cfg
Edit /etc/cloud/cloud.cfg.
(This allows hostnamectl to run set-hostname.)
$ sudo nano /etc/cloud/cloud.cfgChange preserve_hostname: true to preserve_hostname: false, then save.
Restart systemd-logind.service.
$ sudo systemctl restart systemd-logind.serviceChange the hostname
Use hostnamectl to change the hostname.
$ sudo hostnamectl set-hostname [new hostname]Result
buffashe@ubuntu:~$ sudo hostnamectl set-hostname buffashe-vm
[sudo] password for buffashe:
buffashe@ubuntu:~$ hostnamectl
Static hostname: buffashe-vm
Icon name: computer-vm
Chassis: vm
Machine ID: 90e7fb5479a64e678d0e81c987f49dd9
Boot ID: 4df6f5dd0fb64df2a7a876a3114a29c4
Virtualization: oracle
Operating System: Ubuntu 18.04.4 LTS
Kernel: Linux 4.15.0-76-generic
Architecture: x86-64
buffashe@ubuntu:~$Reboot the system to finish changing the hostname.
$ sudo reboot nowLast updated on