Whenever you bring in a new computer system, there is a default hostname associated with it that is mapped onto a specific IP address. However, you can always change this hostname for your convenience. Once you change the hostname of your Linux-based system, you should always restart the “hostname.service” module for the new changes to take effect. Sometimes, when restarting this service, you may encounter the “failed to start hostname.service unit hostname.service is masked” error. This article highlights the root cause of this error and shows you how to resolve this error.

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:

$ sudo nano /etc/hostname

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Fix-failed-to-start-hostname.service-unit-hostname.service-is-masked-Error_1.jpg" data-lazy- height="25" src="data:image/svg xml,” width=”431″>

Our “/etc/hostname” file is shown in the image below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Fix-failed-to-start-hostname.service-unit-hostname.service-is-masked-Error_2.jpg" data-lazy- height="412" src="data:image/svg xml,” width=”647″>

The “/etc/hosts” file can be accessed with the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Fix-failed-to-start-hostname.service-unit-hostname.service-is-masked-Error_3.jpg" data-lazy- height="25" src="data:image/svg xml,” width=”407″>

Our “/etc/hosts” file is shown in the image below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/How-to-Fix-failed-to-start-hostname.service-unit-hostname.service-is-masked-Error_4.jpg" data-lazy- height="411" src="data:image/svg xml,” width=”648″>

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.

About the author

<img alt="Karim Buzdar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/03/echo/karim-150×150.png604bd51f35e70.jpg" height="112" src="data:image/svg xml,” width=”112″>

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.