This article covers both the CLI and GUI based methods of changing the hostname on Ubuntu 20.04.
To change the hostname on Ubuntu Linux:
1. Type the following command to edit /etc/hostname using nano or vi text editor: $ sudo nano /etc/hostname. Delete the old name and setup new name.
2. Next Edit the /etc/hosts file: sudo nano /etc/hosts.
3. Reboot the system to changes take effect: sudo reboot.
To change the hostname on Ubuntu:
1. To change the hostname invoke the hostnamectl command with the set-hostname argument followed by the new hostname.
2. Only the root or a user with sudo privileges can change the system hostname.
3. The hostnamectl command does not produce output.
To change the localhost hostname (static name in the hostname file)?
1. You can also set the static hostname manually by editing /etc/hostname .
2. This file contains exactly one line by default.
3. If you have not changed the hostname yet, then that line probably reads localhost. localdomain .
To display the current Ubuntu hostname:
Simply type the following command:
To change Ubuntu LTS hostname permanently:
1. Type the hostnamectl command :
$ sudo hostnamectl set-hostname newNameHere
2. Delete the old name and setup new name.
3. Next Edit the /etc/hosts file:
$ sudo nano /etc/hosts
Replace any occurrence of the existing computer name with your new one.
4. Reboot the system to changes take effect:
$ sudo reboot
To change hostname on Ubuntu without a system restart:
1. Let us see current setting just type the following command:
2. Next change hostname from localhost to linuxapt, enter:
$ hostnamectl set-hostname linuxapt
3. Verify new changes: