To identify a system when connected to a network or to make the identification of a system while connecting to any device or for any other purpose a unique name is assigned, usually known as hostname. Other than identification, the hostname removes the hassle of identifying the system based on its IP address as it can cause security issues, though in some scenarios the IP address is required for interacting with the system.
- How To Check Hostname on Arch Linux
- Types of Hostnames
- How To Change Hostname on Arch Linux
- Hostname command
- Hostnamectl Command
- Network Manager
- System Settings
How To Check Hostname on Arch Linux
To check the hostname of Arch Linux you can either use the hostnamectl command or look for the Device Name in the About section of system settings:
Types of Hostnames
Hostnames are further divided into different types, as it allow for more flexibility and adaptability in network environments. Further, it enables more clarity and organization in network identification. On the other hand, it facilitates the resolution of hostnames to IP addresses by the Domain Name System (DNS). So here are the three types of Hostnames that are used in almost every Linux Distribution:
Static hostname: This is the hostname that is set by the kernel and stored in the /etc/hostname file. It is used to identify the system on the network and can be changed by editing the file or using the hostname command. A static hostname is permanent unless the user changes it manually.
Transient hostname: This is the hostname that is obtained from the network configuration, such as DHCP or mDNS. This allows the system to change its fixed hostname depending on the network it is connected to. A transient hostname is not permanent and can change at runtime or after a system reboot.
Pretty hostname: This is a user-friendly hostname that can include special or locale characters. It is not used for network communication, but only for display purposes. It can be changed by using the hostnamectl command with the –pretty option.
A system can have multiple hostnames active at the same time, depending on the context and the source of the name. For example, a system can have a static hostname that is set by the user, a transient hostname that is assigned by the network, and a pretty hostname that is displayed by the graphical interface.
These hostnames can be different or the same, depending on the configuration and the preference of the user. However, only one hostname can be used as the primary identifier for the system on the network. This is usually a static hostname unless it is overridden by the transient hostname.
How To Change Hostname on Arch Linux
Just like the types of hostnames, there are multiple ways to change the hostname in Arch Linux and the method depends on what type of hostname you want to set:
1: Using hostname Command
If you are looking to change the hostname on Arch for the time being, then this method is recommended because if the hostname on Arch is changed using the hostname command it will revert the changes once the device is rebooted:
Once you have changed the hostname restart the terminal and confirm the change using:
The use of the hostname command for changing the Arch Linux hostname is a perfect example of setting a transient hostname.
2: Using hostnamectl Command
If you are looking to permanently change the hostname then this method is recommended as using the hostnamectl permanently changes the hostname and for that execute:
Now as in the image above you can see that the static hostname that was previously archlinux has been changed to linux.
Next to verify you can also read the hostname file as the static hostname saves in it automatically:
Now add the changed hostname in the host’s file on Arch, though it is not necessary to add 127.0.0.1 <hostname> in /etc/hosts after changing the hostname using hostnamectl. However, some applications may require a valid hostname to be saved on the host’s file.
If you want to add special characters to the hostname which will come under the type named pretty hostname then use the –pretty command with hostnamectl:
3: Using Network Manager
Devices or systems connected to a network are primarily identified by their hostnames and as from the name network manager on Arch serve the purpose of configuring and managing the network connections. The network manager on Arch can be operated using its GUI or through the command line interface.
This is the GUI version of the network manager and it is preinstalled on Arch so to change the hostname execute the below command and then click on Set system hostname:
Now type the desired hostname and then prompt the change by giving the root password after clicking on OK:
Now you can verify the change in the static hostname using the hostnamectl command:
Another way to change the static hostname on Arch Linux by using the network manager is by using its command line interface for that execute:
Once you have changed the hostname start a new terminal session and verify the changes by executing:
4: System Settings
If you want to set a hostname with a different character or in other words you want to set a pretty hostname then you can do it by changing the device name from the Arch Linux settings:
Note: You might get an error while executing the hostname command and this might be due to the missing inetutils tool which includes the hostname utility:
You need to install inetutils on Arch using the pacman to solve the issue of hostname command not found:
Hostnames not only on Arch Linux but on every other Linux distribution serve the purpose of giving them identity, which in turn helps in recognizing the system in a network. There are primarily three types of hostnames: static, transient, and pretty, but the method for changing each type differs. Overall, there are four ways to change hostnames on Arch Linux which include using the hostname command, hostnamectl, network manager, and Arch Linux about settings.
I’m Aaliyan javaid, an electrical engineer and a passionate tech enthusiast. I have been working with embedded systems, programming, and Linux operating systems for over 2 years. I love to explore new technologies and share my knowledge and experience with others.