# Dnsmasq service - should it be disabled?

**URL:** <https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889>\
**Category:** General\
**Created:** [January 6, 2019, 8:57pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889 "2019-01-06T20:57:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 6, 2019, 8:57pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/1 "2019-01-06T20:57:09Z")

</div>

Just looking at my DietPi based PiHole install and I noticed that the dnsmasq service is dead. I've read around this and the FTL service seems to incorporate dnsmasq.

This answer seems to reinforce this [Dnsmasq failed to start](https://discourse.pi-hole.net/t/dnsmasq-failed-to-start/14731).

My question is therefore, should the dnsmasq service be disabled so it never tries to start?

```auto
DietPi-PiHole:~# systemctl status dnsmasq
● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
   Loaded: loaded (/lib/systemd/system/dnsmasq.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2019-01-06 20:43:11 GMT; 12s ago
  Process: 34511 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=2)
  Process: 34508 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCCESS)

Jan 06 20:43:11 DietPi-PiHole systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
Jan 06 20:43:11 DietPi-PiHole dnsmasq[34508]: dnsmasq: syntax check OK.
Jan 06 20:43:11 DietPi-PiHole dnsmasq[34511]: dnsmasq: failed to create listening socket for port 53: Address already in use
Jan 06 20:43:11 DietPi-PiHole systemd[1]: dnsmasq.service: Control process exited, code=exited status=2
Jan 06 20:43:11 DietPi-PiHole systemd[1]: Failed to start dnsmasq - A lightweight DHCP and caching DNS server.
Jan 06 20:43:11 DietPi-PiHole systemd[1]: dnsmasq.service: Unit entered failed state.
Jan 06 20:43:11 DietPi-PiHole systemd[1]: dnsmasq.service: Failed with result 'exit-code'.

DietPi-PiHole:~# systemctl status pihole-FTL.service
● pihole-FTL.service - LSB: pihole-FTL daemon
   Loaded: loaded (/etc/init.d/pihole-FTL; generated; vendor preset: enabled)
   Active: active (running) since Sun 2019-01-06 00:17:14 GMT; 20h ago
     Docs: man:systemd-sysv-generator(8)
  Process: 59209 ExecStop=/etc/init.d/pihole-FTL stop (code=exited, status=0/SUCCESS)
  Process: 59295 ExecStart=/etc/init.d/pihole-FTL start (code=exited, status=0/SUCCESS)
    Tasks: 7 (limit: 9830)
   CGroup: /system.slice/pihole-FTL.service
           └─59384 /usr/bin/pihole-FTL

```

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [January 6, 2019, 9:02pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/2 "2019-01-06T21:02:19Z")

</div>

> [@borpin](#):
>
> should the dnsmasq service be disabled so it never tries to start?

This is not required. If pihole-FTL loads first, dnsmasq will not load on that port, assuming something is trying to load it. If dnsmasq causes problems, then either disable it or uninstall it.

---

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 6, 2019, 9:09pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/3 "2019-01-06T21:09:25Z")

</div>

> [@jfb](#):
>
> If pihole-FTL loads first, dnsmasq will not load on that port

So strictly speaking dnsmasq should be disabled? Is the fact it is installed a legacy issue?

To rely on hope (pihole-FTL loads first) seems a little odd.

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [January 6, 2019, 9:15pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/4 "2019-01-06T21:15:06Z")

</div>

Dnsmasq is not installed by Pi-Hole, and Pi-Hole neither uninstalls or disables it.

**Edit - Pi-Hole does disable dnsmasq as of V4. See additional comment later in this thread.**

Since Pi-Hole does not use dnsmasq as a separate process, there is no call from Pi-Hole to start it. Unless you have other software loading dnsmasq, it won’t try to launch.

---

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 6, 2019, 9:25pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/5 "2019-01-06T21:25:06Z")

</div>

> [@jfb](#):
>
> Dnsmasq is not installed by Pi-Hole

Was dnsmasq installed by a previous version of Pi-Hole? As this DietPi instance only has Pi-Hole on it, it can only be that which installed it (I believe).

---

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 6, 2019, 9:37pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/7 "2019-01-06T21:37:48Z")

</div>

> [@anon55913113](#):
>
> Dnsmasq was installed and needed when the Pi-hole version lower than 4.x.

Ok great that explains the dead dnsmasq process - it is a legacy of previous versions of Pi-Hole.

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [January 7, 2019, 5:26am UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/9 "2019-01-07T05:26:06Z")

</div>

@borpin  
My apologies for a poorly researched reply. I did not look at the code in sufficient detail. In the install script (see link below), dnsmasq is stopped and disabled if it exists. This is the mechanism that prevents dnsmasq from running.

> <https://github.com/pi-hole/pi-hole/blob/8d85d46c1abf598d6f1b34fb2cfbed9c9ce1a29a/automated%20install/basic-install.sh#L2171-L2178>

---

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 7, 2019, 2:44pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/10 "2019-01-07T14:44:47Z")

</div>

Hi @jfb - no worries.

The issue I can see is that, as this is a service that is started via `update-rc.d` a normal 'disable' does not work as it leaves the various run level files hanging around as seen by `ls -l /etc/rc?.d/*dns*`

To remove those you need to execute `update-rc.d -f dnsmasq remove`.

Secondly, _disabling_ a service simply stops it from running at boot, but does leave open the possibility of it being initiated by another service. To stop the possibility of that happening, a

```auto
systemctl mask dnsmasq.service

```

is required.

This then removes it from the output of a `systemctl status` and avoids confusion.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![jfb](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jfb/32/4332_2.png) [@jfb](https://discourse.pi-hole.net/u/jfb)\
**Post date:** [January 7, 2019, 2:57pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/11 "2019-01-07T14:57:43Z")

</div>

If you choose, dnsmasq can be completely uninstalled and Pi-Hole will continue to function (as of V4).

---

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 7, 2019, 3:00pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/12 "2019-01-07T15:00:08Z")

</div>

Yes. I was just suggesting a more robust way to remove it from view for most users. 😄

---

<div class="post-metadata">

**Author:** ![mibere](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/mibere/32/18057_2.png) [@mibere](https://discourse.pi-hole.net/u/mibere)\
**Post date:** [January 7, 2019, 4:50pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/13 "2019-01-07T16:50:46Z")

</div>

I'm on v.4.1.2. Do I have to run this command to uninstall _dnsmasq_?

`sudo apt-get remove dnsmasq`

Without `--purge` option I think, to keep the current configuration files in `/etc/dnsmasq.d/`

---

<div class="post-metadata">

**Author:** ![mibere](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/mibere/32/18057_2.png) [@mibere](https://discourse.pi-hole.net/u/mibere)\
**Post date:** [January 8, 2019, 8:22pm UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/14 "2019-01-08T20:22:26Z")

</div>

Just dropped dnsmasq with

`sudo apt-get remove dnsmasq-base`

This will uninstall _dnsmasq_ and _dnsmasq-base_.  
After a system reboot all seems to work fine so far.

---

<div class="post-metadata">

**Author:** ![borpin](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/borpin/32/2648_2.png) [@borpin](https://discourse.pi-hole.net/u/borpin)\
**Post date:** [January 9, 2019, 7:57am UTC](https://discourse.pi-hole.net/t/dnsmasq-service-should-it-be-disabled/15889/16 "2019-01-09T07:57:27Z")

</div>

Just to avoid doubt (and this is plagiarised - how I learnt about it 😄) [edited to add some more clarity]

There are 4 different commands for removing packages.

**remove** - just removes the package from the os (i.e. uninstalls it) and not from the disk (the cached package).

**purge** - removes the _installed_ package and associated files like personal settings, configuration files etc

**auto-remove** - removes any packages that are no longer required as a result of removing packages that had previously caused other dependencies to be installed. If used with _purge_ will remove associated files as well.

**clean** - actually removes all of the above from disk, think emptying a recycle bin in windows.

What I do not know is if pi-hole expects any of the standard dnsmasq settings files that might be removed by a **purge** or **clean**. Ideally both of these commands could be used but without testing there is a distinct risk. However, by the fact the packages are still downloaded on disk, I think there is a risk of it being silently reinstalled if something is installed that lists dnsmasq as a dependency.
