Hey guys so I'm using my RaspberryPi with a 4g dongle as gateway for my wireless AP. The pi is connected to the AP through ethernet eht0 and the external internet comes from the dongle eth1. The dongle connects on boot and the internet works on the pi and other devices on the AP. The problem im having is that it doenst work on boot. I have to connect a screen to the pi and manually start dnsmasq on a terminal. Once it starts everything seems to work. I used dhcpcd and dnsmasq with iptables to forward everything from eth1(dongle internet) to eth0 wireless AP connected to the pi via ethernet cable. Is there a solution to the dnsmasq problem?


no-resolv server= # Use Google DNS interface=eth0 # Use interface eth0 no-dhcp-interface=eht1 dhcp-range=eth0,,,,24h


#Internet interface interface eth1 # Change to eth1 if using wired adapter static ip_address= # Set the Pi IP address address form eth1 connection static routers= # Eth1 default gateway

# Local network interface eth0 static ip_address=

I then ran some iptable rules and saved it to /etc/iptables/rules.v4

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE iptables -A FORWARD -i eth0 -j ACCEPT iptables-save > /etc/iptables/rules.v4

on boot all i have to do is run dnsmasq as root in a terminal. Is there a way I can check dnsmasq and make sure its running and run the command dnsmasq otherwise?

uname -a outputs:Linux raspberrypi 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux

systemctl status dnsmasq.service dnsmasq.service

Loaded: masked (Reason: Unit dnsmasq.service is masked.) Active: inactive (dead)

This is the result after i run dnsmasq as admin

sudo systemctl enable dnsmasq.service

When i run this I get the following output:

Synchronizing state of dnsmasq.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable dnsmasq Failed to enable unit: Unit file /etc/systemd/system/dnsmasq.service is masked.

Does this mean I have to unmask the file?

After boot if I run journalctl -e --unit dnsmasq.service Output:

-- Logs begin at Mon 2019-12-23 14:22:16 SAST, end at Mon 2019-12-23 14:27:18 SA Dec 23 14:22:20 raspberrypi systemd[1]: Starting LSB: DHCP and DNS server... Dec 23 14:22:21 raspberrypi systemd[1]: Started LSB: DHCP and DNS server.

If I run this command after i run dnsmasqI get the same result but the devices now get the correct ip address and can ping the pi and the AP

dnsmasq --test dnsmasq: syntax check OK.

systemctl cat dnsmasq.service

# /run/systemd/generator.late/dnsmasq.service

# Automatically generated by systemd-sysv-generator


Documentation=man:systemd-sysv-generator(8) SourcePath=/etc/init.d/dnsmasq Description=LSB: DHCP and DNS server Before=multi-user.target Before=multi-user.target Before=multi-user.target Before=graphical.target After=network-online.target After=remote-fs.target Wants=network-online.target

[Service] Type=forking Restart=no TimeoutSec=5min IgnoreSIGPIPE=no KillMode=process GuessMainPID=no RemainAfterExit=yes SuccessExitStatus=5 6 ExecStart=/etc/init.d/dnsmasq start ExecStop=/etc/init.d/dnsmasq stop

systemctl status dnsmasq.service

dnsmasq.service - LSB: DHCP and DNS server Loaded: loaded (/etc/init.d/dnsmasq; generated) Active: active (exited) since Mon 2019-12-23 14:47:50 SAST; 3min 34s ago Docs: man:systemd-sysv-generator(8) Process: 443 ExecStart=/etc/init.d/dnsmasq start (code=exited, status=0/SUCCESS)

Dec 23 14:47:50 raspberrypi systemd[1]: Starting LSB: DHCP and DNS server... Dec 23 14:47:50 raspberrypi systemd[1]: Started LSB: DHCP and DNS server.

  • Run systemctl status dnsmasq.service and add the output to the question. If it's not enabled run also sudo systemctl enable dnsmasq.service which might solve your problem then.
    – jake
    Dec 23, 2019 at 12:07
  • Updated my answer @jake
    – Zayd Bhyat
    Dec 23, 2019 at 12:07
  • Yes. It is masked by default (forgot about it). So run sudo systemctl unmask dnsmasq.service && sudo systemctl enable dnsmasq.service and everything will be fine.
    – jake
    Dec 23, 2019 at 12:13
  • Thanks Jake ill give it a shot and reboot, maybe add this as an answer
    – Zayd Bhyat
    Dec 23, 2019 at 12:14
  • Ok so it seems as though dnsmasq is active when I check its status but new devices connecting to the AP are still getting a random IP address.
    – Zayd Bhyat
    Dec 23, 2019 at 12:20

1 Answer 1


Your dnsmasq.service is masked and therefore cannot be enabled. You have to run these commands to unmaks and enable it:

sudo systemctl unmask dnsmasq.service && sudo systemctl enable dnsmasq.service

On my system (raspbian buster) the systemd-service looks different than yours:

# /lib/systemd/system/dnsmasq.service
Description=dnsmasq - A lightweight DHCP and caching DNS server


# Test the config file and refuse starting if it is not valid.
ExecStartPre=/usr/sbin/dnsmasq --test

# We run dnsmasq via the /etc/init.d/dnsmasq script which acts as a
# wrapper picking up extra configuration files and then execs dnsmasq
# itself, when called with the "systemd-exec" function.
ExecStart=/etc/init.d/dnsmasq systemd-exec

# The systemd-*-resolvconf functions configure (and deconfigure)
# resolvconf to work with the dnsmasq DNS server. They're called like
# this to get correct error handling (ie don't start-resolvconf if the 
# dnsmasq daemon fails to start.
ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf
ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf

ExecReload=/bin/kill -HUP $MAINPID


Try to reinstall dnsmasq:

sudo autoremove -y --purge dnsmasq && sudo apt install -y dnsmasq

Then I would try a configuration like this:

server= # Use Google DNS
interface=eth0 # Use interface eth0
  • Sorry jake, it seems as though the service is active when i run sudo systemctl status dnsmasq.service but new devices are still getting a random ip address. As soon as i run sudo dnsmasq all new devices connected get the correct ip address and allow me to ping the pi and the AP
    – Zayd Bhyat
    Dec 23, 2019 at 12:26
  • question updated
    – Zayd Bhyat
    Dec 23, 2019 at 12:41
  • Another note running systemctl start dnsmasq.service doesn't seem to do anything but simply running dnsmasq works. Im so confused, it seems as though there may be a broken symlink between the system services and my dnsmasq configuration
    – Zayd Bhyat
    Dec 23, 2019 at 12:48
  • Updated question. I also tried this: i created a bash script that runs dnsmasq as root. I then added the path to the script in the file rc.local. This seems to have temporarily solved the problem but I dont think this is best practice
    – Zayd Bhyat
    Dec 23, 2019 at 13:09
  • @ZaydBhyat Do you use raspbian? If so what version?
    – jake
    Dec 23, 2019 at 13:10

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.