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
  • 19,615
  • 55
  • 79
  • 83

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
  • 1
    What is the purpose of deleting the service file? – RomanK Nov 02 '20 at 15:54
  • @RomanK unmask didn't worked in my case, so I deleted the service first and then restarted it, and that worked! so I shared that here. – sheetal Nov 05 '20 at 16:16
  • If you will delete that Unit, the service cannot start unless you have drop-in in /etc/systemd/system/ or in other paths as per documentation. Removing the file is a bad advice. – RomanK Nov 05 '20 at 19:03
  • @RomanK But that was created by itself when i started the service. I don't have explored it that much, but after grinding for two days, this method worked for me and I shared it. I'll keep your advice in mind, thanks! – sheetal Nov 06 '20 at 04:18
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
  • 131