How to change the Linux computer hostnameFebruary 21, 2019
Systems like Linux, BSD, and many others, use hostnames to talk with one another. What is a hostname? It’s a special name which the user places. These titles may be anything, from a first name to a code-name to a series of numbers, your website’s domain , or whatever in between.When in regards to Linux, hostnames are often set during the first setup procedure. You can change the Linux pc hostname to something else if you re not pleased with it.
Modifying the hostname involves messing up with all the Root folder. It’ll demand Root accessibility, so earlier we start with this guide, please follow our tutorial on how to permit the main user on Linux.
Option 1 – The Hostname application
Linux operating systems called “Hostname. ” It’s s utility which enables users to efficiently swap out and modify the hostname of any Linux system quickly and easily. Additionally, it permits users to set alias titles, see the IP address of a specific hostname, and a whole lot more.
When most distributions ship with this program, it ’ therefore a fantastic idea to discuss how to set it anyways, as some might have uninstalled it or may not have it setup. Following that, follow the directions below that correspond with all the Linux OS you are using.
Sudo apt install hostname
sudo apt-get install hostname
Regrettably, the Hostname program is 1 tool that the Arch Linux operating system does not have. Thankfully, for app that was as useful as the Hostname is, it’s not required to utilize to change your hostname. If you’re on Arch and needing changing the hostname in your system, it s still possible to do by following option 2 in the next section of this article.
Sudo dnf set up hostname
sudo zypper set up hostname
Many Linux users will have access into this Hostname program. If for any reason you overlook ’t have a way to get access to it, then try Option 2 and it ’ s advisable to skip Choice 1. There’so no software to set up, and each Linux operating system however vague has an /etc/hostname file.
Change your hostname with the Hostname utility
Hostname necessitates Root privileges also works in the terminal. The reason why it requires Root is the hostname file on a Linux platform resides in the system directory, and users without superuser privileges cannot get this file. To gain root access, you can run the su command. Or sudo -so is possible when you’ve got the Root account disabled.
Once you’ve got Root access, you’ll be in a position to change the hostname on the machine with the control below.
Hostname -b new hostname
Following the change is made, it is possible to affirm your new hostname with the next command. Though, keep in mind: your new hostname will not show up in almost any Linux terminal till you restart your Linux PC or host.
Establish hostname with a document
The Hostname application allows users to set hostname data with a file. This feature is especially useful if is a lengthy one. To try it, open up a terminal window and gain a root shell using su or sudo -so .
Next, create the text file which will hold the hostname using the signature command.
Open the hostname record from the Nano text editor.
pre> Then, save it by pressing on Ctrl + O and exit with Ctrl + X.
Ultimately, change your hostname with:
Hostname -I hostname-file
Option 2 – Modify /etc/hostname document
Another way to modify the Linux computer hostname would be to directly change the document in which the machine saves the name of your computer, in the / / etc/hostname file. To access and edit the document, open a terminal window . After that, gain a root shell with su to log in as root, or by using sudo -so if you do not have access to superuser privileges.
Once you’ve got Root access from the terminal window, then open up the / / etc/hostname file in the Nano text editor.
Nano -w /etc/hostname
working with the computer keyboard, erase the present hostname from the document. Make certain that there are no spaces left over. Once the hostname is deleted, compose your new hostname that is desired.
After you’re satisfied with the new hostname alter, save Nano text editor by pressing the Ctrl + O keyboard mix. Then, close it with Ctrl + X.