Dnsmasq Ubuntu 18.04

Posted on  by 

In Ubuntu Bionic, I found that the dnsmasq package no longer creates a service for dnsmasq that you can control with service or systemctl. After a fair amount of experimenting and some help from the friendly folk at #systemd on irc.freenode.net , I ended up with a dnsmasq service file that does the right things, namely:

Dnsmasq Ubuntu 18.04Ubuntu

Ubuntu 18.04 Install Dnsmasq

If you're using a default Ubuntu 18.04 setup, this may be caused by a conflict between systemd-resolved (the default DNS server) and dnsmasq. If you installed dnsmasq yourself deliberately because you explicitly wanted it, then one of the other answers to this question, explaining how to disable systemd-resolved, will probably be good for you.

  • wait for the LAN interface to be online (since my dnsmasq listens only on LAN), and then start the dnsmasq service.
  • Are you using the latest version of Ubuntu and looking for a way using which you can flush your DNS Cache? Well, you are the right place. The following guide shows you how to Flush the DNS Cache in Ubuntu 18.04, alongside with it we will also educate you regarding why you should consider Flushing your DNS Cache once in a while.
  • Download dnsmasq2.79-1all.deb for 18.04 LTS from Ubuntu Universe repository.

Here goes the systemd unit file which you can place in /etc/systemd/system/dnsmasq.service :

Dnsmasq Ubuntu 18.04

Once you have created the service file, you must enable it with sudo systemctl enable dnsmasq.service . You of course need to make sure to use the correct device names for your system (my network device is listed by systemctl as sys-subsystem-net-devices-enp4s0.device). You can list all the devices systemd knows on your machine using systemctl -t device. Use grep to filter for your specific device (interface) name if you know what it’s called. Mine was called “enp4s0”.

The short summary of the above systemd unit file is that:

Dnsmasq-base Ubuntu 18.04

  • It is wanted by my LAN ethernet device, so it is launched when the device has been registered by udevd (or whatever subsystem handles this).
  • It’s of type “forking” because dnsmasq is a daemon which forks itself and you need this configuration for systemd to track it correctly.
  • In order to wait until the LAN is actually routable, I had to use the ExecStartPre (thanks #systemd) to use the systemd-networkd-wait-online application.
    • ExecStartPre just executes specified binary or script before it actually launches your desired process.
    • this application basically blocks until the specified interface is routable (which means it has an IP address).
    • You must use the full path to the executable.
    • Once it’s routable, then dnsmasq is executed (ExecStart), and dnsmasq by default will load the config file in /etc/dnsmasq.conf

Coments are closed