How to Change Hostname on Ubuntu 20.04

How to Change Hostname on Ubuntu 20.04

To change the hostname on an Ubuntu 20.04 system, you can use the hostnamectl command. This command is part of the systemd system and service manager, which is the default init system on Ubuntu 20.04.

To change the hostname, run the following command as root:

ref‮re‬ to:lautturi.com
hostnamectl set-hostname new_hostname

Where new_hostname is the desired hostname for the system.

For example, to set the hostname to myhost, you can run the following command:

hostnamectl set-hostname myhost

This will change the hostname of the system to myhost.

It's worth noting that the hostname change will only take effect temporarily. To make the change permanent, you will need to update the /etc/hostname file with the new hostname. You can do this by running the following command:

echo new_hostname > /etc/hostname

Where new_hostname is the desired hostname for the system.

For example, to set the hostname to myhost, you can run the following command:

echo myhost > /etc/hostname

You may also need to update the /etc/hosts file to reflect the new hostname. This file maps IP addresses to hostnames for the local system. To do this, open the /etc/hosts file in a text editor and update the hostname entry to reflect the new hostname.

It's also a good idea to restart the system after changing the hostname to ensure that all services are using the new hostname. You can do this by running the following command:

shutdown -r now

This will restart the system and apply the hostname change.

Alternatively, you can use the reboot command to restart the system:

reboot

It's worth noting that the exact steps for changing the hostname may vary depending on the specific version of Ubuntu and the init system in use. If you are using a different version of Ubuntu or a different init system, you may need to follow a different set of steps to change the hostname.

Created Time:2017-10-28 21:38:57  Author:lautturi