6

I was trying to restart the systemd-resolved.service with the command:

sudo systemctl restart systemd-resolved

and got the error message:

Failed to restart systemd-resolved.service: Unit systemd-resolved.service is masked. 

File the systemd-resolved.service exists in the folder /lib/systemd/system.

The status of the service is:

/lib/systemd/system# systemctl status systemd-resolved.service
● systemd-resolved.service
   Loaded: masked (/dev/null; bad)
   Active: inactive (dead)

When I try to execute with:

/lib/systemd/system/systemd-resolved.service
-bash: /lib/systemd/system/systemd-resolved.service: Permission denied

What am I doing wrong?

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84

4 Answers4

8

If your service is masked it is symlinked to /dev/null
You can verify by:

ls -l /etc/systemd/system/systemd-resolved.service

To remove the mask simply run:

sudo systemctl unmask systemd-resolved

/lib/systemd/system/systemd-resolved.service is a text file and cannot be executed by bash. The service binary is located /lib/systemd/systemd-resolved

RomanK
  • 440
3

Try removing the systemd service file and then starting it again.

Remove the file-

sudo rm /lib/systemd/system/systemd-resolved.service

Reload the daemon

sudo systemctl daemon-reload

Once reloaded, start the service

sudo systemctl start systemd-resolved
sudo systemctl enable systemd-resolved

Note: For getting the location of systemd-resolved service you can use sudo systemctl enable systemd-resolved and further use the location for removing the file.

The masked systemd service made my system have issues with network manager and I was not being able to use internet on the system. When I checked further for errors or warnings using grep resolved /var/log/syslog command, I came across the error that this service is masked and unmasked it using the solution above.

sheetal
  • 131
0

use this command

$ sudo dpkg-reconfigure resolvconf
NinjaDev
  • 101
0

Adding to RomanK's answer above,
use the unmask command to unmask any service that is listed in the error,
for example:

If you get

...Unit systemd-networkd.service is masked...

then run the command

sudo systemctl unmask systemd-networkd.service

(see also this archived answer for ways to list masked services)

Gonen
  • 133