This simple tutorial shows you how to change the hostname (also known as computer name) in Ubuntu 21.10 Impish Idri.
The computer name is a unique identifier given to each computer. It’s not a big deal for small home networks or single use home computers. It matters however in larger organizations where you need to be able to identify servers. The name is a single word with no spaces, it has only letters, numbers or a hyphen with up to 253 characters.
The default name was set during installing the Ubuntu system. You can however change it at anytime as you want. And here’s the universal way to do the trick in either Ubuntu desktop or server editions.
Tutorial Objectives:
- Change Computer Name / Hostname in Ubuntu 21.10
- Enjoy!
Change computer name until reboot:
To get started, first either connect to your Ubuntu server or open terminal by pressing Ctrl+Alt+T on keyboard or searching from the overview screen. When it opens, run command:
sudo hostname NEW_NAME
Replace ‘NEW_NAME’ in command with your desired computer name. And it will take place until reboot.
NOTE: the new name takes effect immediately but not visible until you start a new terminal window.
Change computer name permanently:
In most Linux distributions, you can edit the “/etc/hostname” configuration file to set new computer name.
1.) To do so, open terminal from start menu or connect to the command console of remote server, then run command:
sudo nano /etc/hostname
This command will edit the config file via nano
, the universal command line text editor. You may replace it with your favorite text editor, such as gedit for GNOME desktop.
When the file opens, delete the old name and type a new one. And press Ctrl+X, then type y, and hit Enter to save changes!
2.) It’s important to edit /etc/hosts file to map the new name to 127.0.1.1 and/or the permanent IP address if any.
sudo nano /etc/hosts
NOTE: you have to set same name in both /etc/hosts and /etc/hostname to avoid networking issues. And save file by pressing Ctrl+X, type y, and hit Enter.
Finally reboot to apply change and enjoy!