40

I can't figure out how to restart dnsmasq.

service dnsmasq restart
dnsmasq: unrecognized service

SOLUTION

Restart the network manager (his parent)

sudo service network-manager restart
1
  • 1
    The solution should be posted as an answer instead of being on the question's body....
    – brasofilo
    Aug 21, 2019 at 23:41

4 Answers 4

33

In the normal Ubuntu destktop configuration, dnsmasq is invoked via the NetworkManager, and can be restarted by restarting the network-manager service instead i.e.

$ pstree -sp $(pidof dnsmasq)
init(1)───NetworkManager(7731)───dnsmasq(7743)
$ 
$ sudo service network-manager restart
network-manager stop/waiting
network-manager start/running, process 7940
$ 
$ pstree -sp $(pidof dnsmasq)
init(1)───NetworkManager(7940)───dnsmasq(7953)
5
  • 4
    Outdated answer... dnsmasq is ran by systemd on 16.04.
    – Calmarius
    Sep 27, 2017 at 13:36
  • 2
    Hence, it should now be: sudo systemctl restart network-manager.service.
    – Régis B.
    Jan 24, 2018 at 14:56
  • service network-manager restart still work though.. Because service can handle some of systemd commands. Mar 12, 2018 at 18:59
  • I'm on 18.0.4 using pi-hole and I get service not found
    – Shayan
    Sep 2, 2019 at 12:17
  • 2
    @Shayan it's systemd-networkd.service on ubuntu 18
    – Karl Pokus
    Sep 8, 2020 at 12:27
18

Just run this command:

sudo /etc/init.d/dnsmasq restart
2
  • Works on Ubuntu 14.04.1 LTS Nov 27, 2017 at 22:46
  • Works on Debian 11 and when one does not use NetworkManager
    – some user
    Sep 19, 2019 at 13:34
3

Simply restarting network manager does not work for me (as in new DNS setup is not used).

$ ps aux | grep dns
libvirt+  2217  0.0  0.0  28200   668 ?        S    May30   0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf
nobody   17685  0.1  0.0  32604  1560 ?        S    14:39   0:01 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.1.1 --conf-file=/var/run/NetworkManager/dnsmasq.conf --cache-size=0 --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d

Then so in here you need to run :
sudo kill 17685

Then finally sudo service network-manager restart

This applies new the dnsmasq settings as well.

0

I seem to have two instances of dnsmasq running on my Ubuntu 12.04. The following seems to work to restart both of them:

$ sudo service network-manager restart
$ sudo stop lxc-net; sudo start lxc-net

Example result:

$ for p in $(pgrep dnsmasq); do pstree -spu $p; done
init(1)───NetworkManager(19343)───dnsmasq(19417,nobody)
init(1)───dnsmasq(19623,lxc-dnsmasq)

$ sudo service network-manager restart
network-manager stop/waiting
network-manager start/running, process 20048

$ for p in $(pgrep dnsmasq); do pstree -spu $p; done
init(1)───dnsmasq(19623,lxc-dnsmasq)
init(1)───NetworkManager(20048)───dnsmasq(20066,nobody)

$ sudo stop lxc-net; sudo start lxc-net
lxc-net stop/waiting
lxc-net start/running

$ for p in $(pgrep dnsmasq); do pstree -spu $p; done
init(1)───NetworkManager(20048)───dnsmasq(20066,nobody)
init(1)───dnsmasq(20262,lxc-dnsmasq)

The lxc-net restart is discussed here:
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1043588

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.