Question: How can we mask/unmask a service in CentOS/RHEL 7 and 8?
Masking a Service
To prevent conflict between similar types of services that perform a certain function, masking is used. For example, for a firewall, CentOS 7 has both iptables and firewalld services; however, it is recommended to use only one at a time. Hence, one of the two firewall services is masked to prevent conflict between the two services. Masks prevent the accidental startup of a service by creating a symlink of the service file to /dev/null as shown in the example below.
In this example the sendmail service is masked:
# systemctl restart sendmail Failed to restart sendmail.service: Unit is masked #
Also you can check the masked services using this command:
# systemctl list-unit-files | grep -i mask mdmonitor.service masked sendmail.service masked smartd.service masked uptrack-late.service masked #
Masking a Service
The command “systemctl mask [service]” is used to mask the service avoid to start it:
# systemctl mask firewalld Created symlink from /etc/systemd/system/firewalld.service to /dev/null. #
UnMasking a Service
The command “systemctl unmask [service]” is used to unmask the service and be able to start it:
For example:
# systemctl unmask firewalld Removed symlink /etc/systemd/system/firewalld.service. #