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?
dnsmasq.conf
no-resolv
server=8.8.8.8 # Use Google DNS
interface=eth0 # Use interface eth0
no-dhcp-interface=eht1
dhcp-range=eth0,10.0.0.20,10.0.0.50,255.0.0.255,24h
dhcpcd.conf
#Internet interface
interface eth1 # Change to eth1 if using wired adapter
static ip_address=192.168.8.100 # Set the Pi IP address address form eth1 connection
static routers=192.168.8.1 # Eth1 default gateway
# Local network
interface eth0
static ip_address=10.0.0.1/24
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 dnsmasq
I 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
[Unit]
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.
sudo systemctl unmask dnsmasq.service && sudo systemctl enable dnsmasq.service
and everything will be fine. – jake Dec 23 '19 at 12:13dnsmasq
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 '19 at 12:20