0

I have configured my Rpi3 as an ethernet router. Rpi3 is running on Stretch Raspbian OS.

dnsmasq.conf

interface=eth1
listen-address=192.168.2.1
bind-interfaces
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv
dhcp-range=192.168.2.2,192.168.2.100,12h

eth1 static ip is defined in dhcpcd.conf file

interface eth1
static ip_address=192.168.2.1/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

But dnsmasq is failed to start at boot. Therefore i want to run dnsmasq manually using sudo service dnsmasq start after that Rpi work as ethernet router.

What will be the cause which prevent dnsmasq from start?

Please help me

1

This might be because dnsmasq is attempting to bind to the socket before it becomes available.

To verify, run systemctl status dnsmasq -l. Possible error messages:

dnsmasq: failed to create listening socket for 192.168.2.1 : Cannot assign requested address dnsmasq: unknown interface eth1

Solution 1a (easy): Do not use bind-interfaces

# Comment out this line
;bind-interfaces

Solution 1b (easy): Do not listen on specific address/interface

# Comment out these lines
;interface=eth1
;listen-address=192.168.2.1
;bind-interfaces

Solution 2 (harder): Find a way to start dnsmasq only after the network is ready

  • I am very interested in any information you can provide regarding "Solution 2". Looking at /etc/systemd/system/multi-user.target.wants/dnsmasq.service suggests that it runs after the network is up, but in my case I am trying to use it with hostapd which I think doesn't come up until later. – iX3 Apr 26 '18 at 18:02
  • What if we comment the line bind-interfaces only? – vishnu m c Mar 7 at 12:15
  • @vishnu m c If the failure comes from trying to listen on an address before your network is up, then solely removing bind-interfaces wouldn't work – akgren_soar Mar 7 at 12:32
  • But commenting bind-interface worked for me. Then what will be the reason for the error? – vishnu m c Mar 8 at 3:36
  • @akgren_soar Could you please tell me? How it happens? Its worked for me by just commenting the line bind-interfaces – vishnu m c Mar 11 at 5:17
0

I have made a wifi-ethernet bridge on Raspbian stretch. The trick for me was following the tips from SurferTim on this rasbperrypi forum post with a similar question to yours: https://www.raspberrypi.org/forums/viewtopic.php?t=192377

Anyhow, using those guidelines that worked for me and others, here is what I would do:

/etc/dnsmasq.conf

interface=eth1
dhcp-range=192.168.2.2,192.168.2.100,12h

/etc/dhcpcd.conf

interface eth1
static ip_address=192.168.2.2/24

/etc/sysctl.conf

net.ipv4.ip_forward=1

ip rules

sudo iptables -t nat -A  POSTROUTING -o wlan0 -j MASQUERADE

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

SurferTim says to sudo nano /etc/rc.local but I added here /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat => use a text editor

iptables-restore < /etc/iptables.ipv4.nat

In order to use normal interface names on boot edit /boot/config.txt

net.ifnames=0

Or...(achieves same as above) in /etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", 
ATTR{address}=="b8:ac:6f:65:31:e5", ATTR{dev_id}=="0x0", 
ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Do a reboot

sudo reboot

This worked for me and is the Raspbian stretch way to do things from what I understand. The raspberry pi forums are your friend :-) Happy Linuxing!

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.