# What's going on with dnsmasq?

## Princess Nell

While trying to figure out why NetworkManager is so horribly slow, I came across another tool that's behaving in funny ways. Any explanations?

```

localhost ~ # /etc/init.d/dnsmasq stop

 * Stopping dnsmasq ...

 * start-stop-daemon: 1 process refused to stop

 * Failed to stop dnsmasq                                                                                                                              [ !! ]

 * ERROR: dnsmasq failed to stop

localhost ~ # grep dnsmasq /var/log/messages|tail -2

Nov 11 23:11:16 jeanie /etc/init.d/dnsmasq[7788]: start-stop-daemon: 1 process refused to stop

Nov 11 23:11:16 jeanie /etc/init.d/dnsmasq[7780]: ERROR: dnsmasq failed to stop

localhost ~ #      

```

The changes to the default config are quite limited.

```

domain-needed

bogus-priv

resolv-file=/etc/dnsmasq-resolv.conf

interface=lo

conf-file=/etc/dnsmasq-conf.conf

```

It is possible this only started with version 2.63, but I don't remember when exactly I noticed this first.

----------

## Bones McCracker

I can't replicate the error.  It stops and starts fine for me.  I'm using 2.63.

See what happens when you try:

```
/etc/init.d/dnsmasq --nodeps stop
```

----------

## depontius

I've been having troubles with dnsmasq on one of my home systems.  The problems appear to be intermittent, but they really drive mythbackend nuts.  For the time being, I've shut it down on that system.  I'm still using it on other systems with no problems.  I haven't had time to diagnose further or debug.

----------

## Bones McCracker

I've been using it to manage a two-subnet LAN for four years without any problems.  I've never considered using it on a single end-user machine.

----------

## Princess Nell

I've used it for years without problems, this is recent.

Once I've kill -KILL'd dnsmasq, I can start, stop and restart it with no problems. But the behaviour I described is somehow related to the interaction with (the train wreck that is) NetworkManager. E.g. when I open, use and close a vpn connection through NM, it becomes un-stoppable after.

```

Nov 12 20:01:52 loalhost dnsmasq[11179]: using nameserver 192.168.1.254#53

Nov 12 20:01:52 loalhost NetworkManager[3001]: <info> Clearing nscd hosts cache.

Nov 12 20:01:52 loalhost NetworkManager[3001]: <info> VPN plugin state changed: started (4)

Nov 12 20:01:52 loalhost dbus[2950]: [system] Activating service name='org.freedesktop.nm_dispatcher' (using servicehelper)

Nov 12 20:01:52 loalhost dbus[2950]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'

Nov 12 20:01:53 loalhost ntpd[3395]: Listen normally on 10 tun0 172.16.123.45 UDP 123

Nov 12 20:01:53 loalhost ntpd[3395]: 46.51.185.173 interface 192.168.1.20 -> 172.16.123.45

Nov 12 20:01:53 loalhost ntpd[3395]: 46.137.159.146 interface 192.168.1.20 -> 172.16.123.45

Nov 12 20:01:53 loalhost ntpd[3395]: 193.1.193.157 interface 192.168.1.20 -> 172.16.123.45

Nov 12 20:01:53 loalhost ntpd[3395]: 134.226.32.57 interface 192.168.1.20 -> 172.16.123.45

Nov 12 20:01:53 loalhost ntpd[3395]: peers refreshed

Nov 12 20:01:57 loalhost NetworkManager[3001]: <info> Policy set 'Auto eth0' (eth0) as default for IPv4 routing and DNS.

Nov 12 20:01:57 loalhost NetworkManager[3001]: <info> ((null)): writing resolv.conf to /sbin/resolvconf

Nov 12 20:02:02 loalhost /etc/init.d/dnsmasq[11279]: start-stop-daemon: 1 process refused to stop

Nov 12 20:02:02 loalhost /etc/init.d/dnsmasq[11273]: ERROR: dnsmasq failed to stop

Nov 12 20:02:02 loalhost dnsmasq[11179]: reading /etc/dnsmasq-resolv.conf

Nov 12 20:02:02 loalhost dnsmasq[11179]: using nameserver 192.168.1.254#53

```

----------

## depontius

My main use has been to redirect DNS requests when my VPN to my employer is active.  Regular DNS is a rather either/or kind of thing, either I can resolve my LAN or my work network.  With dnsmasq I can get both.

----------

## truc

Did you check your configuration with: 

```
sudo dnsmasq --test
```

, the problem you're having may not be a syntax error, so try to start dnsmasq manually in debug mode(no daemon, stderr logging, no fork and so on)

```
sudo dnsmasq -d
```

HTH

----------

## Princess Nell

It passes the syntax check.

Running it in debug mode, vpn fails, no matter whether launched through NM or vpnc directly, and there is no output after the attempt to launch vpn. /var/log/messages says:

```

Nov 13 08:42:48 localhost NetworkManager[3001]: <warn> /sys/devices/virtual/net/tun0: couldn't determine device driver; ignoring...

```

Interesting. I have no idea why NM gets involved even when I run vpnc directly.

----------

## truc

So dnsmasq started correctly right? if the problem is not solved, it's probably wise to start all over again and explain what your problem really is, cause, you've just started dnsmasq in debug mode and the only output you showed in your post was something unrelated to dnsmasq. We can't really help you here!

----------

## Princess Nell

Running dnsmasq in debug mode gives me no additional information. When I run dnsmasq in debug mode and attempt to use vpn, vpn doesn't work, and all I get is the log I posted.

----------

## mirekm

If you use NetworkManager, why start dnsmasq via rc script?

Just remove the dnsmasq from your runlevels, and edit file

/etc/NetworkManager/NetworkManager.conf

Put in it following contents:

[main]

dns=dnsmasq

And then after restat, NetworkManager will start/stop dnsmasq by itself on activation/deactivation of connection.

----------

## Bones McCracker

A better question might be "why use NetworkManager, at all?"   :Razz: 

----------

## Princess Nell

That's a good point.

I switched to it a few years back for the convenience of having easy access to all networking functions on the desktop. Unfortunately, in the past year or so, it seems design decisions have been made in the software that, at least for me, had detrimental impact on my system. If there was a feature-compatible replacement, I'd certainly give it a try.

----------

## Hypnos

I have been using wicd quite effectively since switching from GNOME to XFCE a few years back.  It handles Ethernet and WiFi, which is all I need.

----------

## Princess Nell

Reviving old thread since problem remains unsolved.

Networkmanager does something funny with dnsmasq. When vpn is not being used, via networkmanager-vpnc, dnsmasq terminates normally on shutdown, and indeed can be terminated normally through its init script. If a vpn connection is established via networkmanager, and then terminated, the dnsmasq process cannot be killed with the init script.

I have verified that networkmanager restarts dnsmasq when vpn is invoked. I.e. the pid changes. And I've verified that /run/dnsmasq.pid is updated along with it, as it should. So it's not a matter of the init script trying to kill an outdated pid.

The init script for dnsmasq has no stop function, so I assume that, under openrc, start-stop-daemon is being used? When I try start-stop-daemon -v -K /usr/sbin/dnsmasq, at first a signal 15 is sent, and then 250 times signal 0. 15 = SIGTERM, and 0 is just a check whether the process exists. Then it exists with "1 process refused to stop".

SIGQUIT works (signal 3). There's no useful information gained from netstat -anp |grep dnsmasq, or strace -p `cat /run/dnsmasq.pid` while invoking the init script.

All this, btw., with a default configuration of dnsmasq. Removing it from runlevel default altogether and adding it to NetworkManager.conf, as suggested, has the effect that dnsmasq never gets killed on shutdown, vpn or not. As a networkmanager child process, it should get killed.

At a guess, networkmanager gets the signal handling wrong for dnsmasq processes launched from it. Maybe it wrongfully traps SIGTERM. I don't think I have the knowledge to figure out whether this speculation has merit by looking at the NM sources.

The environment: network-manager-1.0.0, dnsmasq-2.72, networkmanager-vpnc-0.9.10.0 (1.0.0 doesn't work, full stop).

----------

## e3k

got some strange issue today too. all pages opened by a browser (ff, links) did resolve very slow. dig was working normally. when i tried to restart dnsmasq it said it could not be restarted. did not respond to SIGTERM. after sending SIGKILL and restarting the service everything went back to normal. v2.72-r2

----

the only strange thing i have found was a double entry of the nameserver in /etc/resolve.conf:

```

# Generated by dhcpcd from net0.dhcp

nameserver 127.0.0.1

domain lan

nameserver 192.168.1.1

nameserver 192.168.1.1

```

----------

