Causes of the Error
The system hostname is stored in two main files in Linux. The first file is the “/etc/hostname” file, and the other file is the “/etc/hosts” file. The former only consists of the hostname of your system, whereas the latter contains a mapping of the hostname onto a specific IP address. The “failed to start hostname.service unit hostname.service is masked” error arises when the contents of these two files are mismatched, i.e., the hostname mentioned in one of these files is different from the hostname in the other file. Due to this inconsistency between the contents of the “/etc/hostname” and “/etc/hosts” files, your system will fail to start the hostname.service, and the error will occur.
How to Resolve the Error
The simplest way to resolve this error in Linux is by ensuring that the hostname mentioned in both files is the same. To do so, you will need to check the contents of both these files. You can access the “/etc/hostname” file by executing the following command in the Linux terminal:
Our “/etc/hostname” file is shown in the image below:
The “/etc/hosts” file can be accessed with the following command:
Our “/etc/hosts” file is shown in the image below:
As you can see from the contents of both files, our hostname is the same in both files, i.e., kbuzdar-VirtualBox. Once you have ensured that the hostname in your respective files is exactly the same, then you can try restarting the hostname.service once again. This time, it should not render the error.
Conclusion
This article enlightened you about the causes of the “failed to start hostname.service unit hostname.service is masked” error. Moreover, it also shared with you the simplest method through which you can get rid of this error in Linux.