Changing the hostname in Linux
We have already learned what a hostname is, but how to set or change such a hostname?
For the following steps you will need:
- Linux operating system
- The root user or a user with sudo command authority
Terminal
In the directory structure, we go to the /etc folder
cd /etc/
Editing the hostname
Let's open the hostname file in the editor. In our case, we will use the nano editor.
sudo nano hostname
note if the logged in user is root, we don't type sudo before the command.
When using the sudo command, the terminal will ask us for a password.
We delete the old one and write a new hostname.
We save the changes made with the keyboard shortcut ctrl + x
sudo reboot
After the restart, we have a changed hostname.
Done.