LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

dnsmasq, 2 Ethernet

Fri Sep 08, 2017 1:17 am

I've scoured Raspberry Pi, Debian, Ubuntu, and just about every other forum I can find, and I'm stumped.

Here's the setup: I have 1 RPi acting as a master node for a cluster. This Pi connects to my home network using a USB-Ethernet adapter, and has a static IP in the 192.168 range. No problems there. The Pi's onboard Ethernet connects to a switch, which connects to 4 slave nodes, all set up for DHCP (with the goal that the master node will assign specific IPs to each node based on the naming convention, 10.0.0.11 for the first slave, 10.0.0.12 for the second, etc.) Ignoring the new naming scheme in Stretch, Eth0 is connected to the Internet/Home and Eth1 is connected to the slave nodes.

I want the slave nodes to be able to talk to each other, as well as the Internet, but I want the master node to act as a DHCPServer and DNS for the other nodes, so the rest of the home network (192.168) can only see the master node.

Every guide/question/help I can find seems to still use /etc/network/interfaces, and it's my understanding that it's basically been deprecated for dhcpcd. If it hasn't I can't figure out how interfaces relates to dhcpcd and dnsmasq.

Can anyone point me in the right direction?

Thank you.

beta-tester
Posts: 1372
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: dnsmasq, 2 Ethernet

Fri Sep 08, 2017 7:00 am

i am not a professional...

but i know, that you can do separate definitions/settings in dnsmasq.

Code: Select all

########################################
#/etc/dnsmasq.conf
...
# interface selection
interface=eth0
interface=eth1

# DHCP
dhcp-range=eth0, 192.168.1.100, 192.168.1.200, 24h
dhcp-range=eth1, 10.0.0.100, 10.0.0.200, 24h

# DNS (enabled)
port=53
dns-loop-detect

# optional TFTP (enabled)
enable-tftp
tftp-lowercase
tftp-root=/srv/tftp_for_eth0/, eth0
tftp-root=/srv/tftp_for_eth1/, eth1
to act as NAT, you have to tell the kernel to forward the network traffic

Code: Select all

########################################
# /etc/sysctl.conf
...
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
and the firewall modifies the headers to act as NAT - so the traffic from one network looks like as it was requested from the RPi itself and not from the network behind.

Code: Select all

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo dpkg-reconfigure iptables-persistent
and to give the RPi static ip addresses to both sides (without use of /etc/network/interfaces)

Code: Select all

########################################
# /etc/dhcpcd.conf
...
interface eth0
static ip_address=192.168.1.10/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

interface eth1
static ip_address=10.0.0.10/24
i hope it is complete and correct.

BTW: you can force Rspbian Stretch to use/keep the old network interface naming style, by adding " net.ifnames=0" to the end of /boot/cmdline.txt content
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

Re: dnsmasq, 2 Ethernet

Fri Sep 08, 2017 12:03 pm

Thanks for the reply, I'll take another crack at it tonight.

The new naming convention doesn't bother me, but I appreciate the reminder on how to turn it off.

As far as dnsmasq goes, it looks like what you provided has both interfaces providing DHCP. I only want DHCP to the cluster, so I assume I can remove those lines?

Also, I should set dnsmasq to listen for DHCP requests on the eth1 interface, right?

Thanks again. Will report back tonight. I know what I'm doing isn't hard, but I'm getting hung up on something.

LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

Re: dnsmasq, 2 Ethernet

Fri Sep 08, 2017 7:58 pm

That got me going, everything's working now!

Thanks!

LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

Re: dnsmasq, 2 Ethernet

Fri Sep 08, 2017 8:36 pm

Ok, new problem, then I'll be done.

dnsmasq is starting before dhcpcd sets the static IPs for the master node, so it fails at boot, and I have to start it again.

What's the best way to fix this? Ideally dnsmasq service starts last

LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

Re: dnsmasq, 2 Ethernet

Fri Sep 08, 2017 9:10 pm

I just set a crontab to run 20 seconds after reboot. Seems to be good to go now.

Thanks!

beta-tester
Posts: 1372
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: dnsmasq, 2 Ethernet

Sat Sep 09, 2017 9:14 am

LtKen wrote:
Fri Sep 08, 2017 8:36 pm
Ok, new problem, then I'll be done.

dnsmasq is starting before dhcpcd sets the static IPs for the master node, so it fails at boot, and I have to start it again.

What's the best way to fix this? Ideally dnsmasq service starts last
but this i don't understand...
the file /lib/systemd/system/dnsmasq.service is set up with After=network.target.
and the file /lib/systemd/system/dhcpcd.service is set up with Before=network.target.
i read it as dnsmasq service will never start before dhcpcd service was started.

maybe the order is broken for some reason.
what you can try is to rearm those services.

Code: Select all

sudo systemctl stop dnsmasq.service
sudo systemctl disable dnsmasq.service
sudo systemctl stop dhcpcd.service
sudo systemctl disable dhcpcd.service

sudo systemctl start dhcpcd.service
sudo systemctl enable dhcpcd.service
sudo systemctl start dnsmasq.service
sudo systemctl enable dnsmasq.service
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

Re: dnsmasq, 2 Ethernet

Sat Sep 09, 2017 8:34 pm

I'll try that tonight and see what happens.

Starting the service again with cron works, so if nothing else, i'll go back to that.

LtKen
Posts: 7
Joined: Fri Sep 08, 2017 1:09 am

Re: dnsmasq, 2 Ethernet

Sat Sep 09, 2017 11:46 pm

Rearming the services didn't work. Just going back to the crontab.

Return to “Advanced users”