[Solved] dnsmasq and 2 NICs on RPi 2 B DietPi

Hello, friends.

Maybe this is not adequated to this forum, but I will share this info with you all. If Pilovali or Fourdee thinks this is not for here, kill this post, I understand.

My goal is having my DietPi RPI2 being my router-firewall-DHCP server-DNS server-squid proxy-dansguardian filter.
eth0-internal ethernet to my ADSL-modem-DHCP router, and eth1-external-usb-asix-88772-ethernet to a switch to the rest of the network( others computer and tablet at home).

I’ve tried it with DietPi Wheezy, Jessie, v102, v103… and Jessie minimal official image… and it doesn’t work.

My DietPi Jessie v103 RPI 2 B hangs out after 2 or 3 minutes, just after 3-4 DNS queries (it seems to work, DHCP and DNS, but just for 2 or 3 queries from my Macbook), it gets disconnect from eth0 and eth1 and I have to hard-reboot. The same happens with DietPi Wheezie or whatever.

I’ve tried tones of options, last I tried is this, and it’s supposed to work: http://qcktech.blogspot.co.uk/2012/08/raspberry-pi-as-router.html

I have a Raspbian image with a very similar config as I’m sharing, and it works like a charm on a RPI 1 B. But it doesn’t work on my RPI 2 B.
So, my project is creating this on DietPi (I love it!) Jessie or Wheezie for the RPI 2B.

My question: Could it be Raspberry Pi 2 B has a bug that makes the routing or NATting or Forwarding impossible? And has DietPi these same bugs because they are maybe firmware related or whatever? Or maybe Raspbian “boot” partition for the RPI 2 B has this bug?


Steps I’ve done:
1- As a root…
2- nano /etc/network/interfaces

auto lo 
iface lo inet loopback  

#Onboard NIC connecting to the Internet 
auto eth0 
iface eth0 inet dhcp  

#USB NIC serving as internal gateway 
auto eth1 
iface eth1 inet static 
address 192.168.50.1 
netmask 255.255.255.0 
network 192.168.50.0 
broadcast 192.168.50.255
#gateway 192.168.50.1

2- sudo apt-get update
sudo apt-get install dnsmasq
nano /etc/dnsmasq.conf

filterwin2k
no-resolv
server=87.216.1.65
server=87.216.1.66
interface=lo
interface=eth1
expand-hosts
domain=local
dhcp-range=192.168.50.100,192.168.50.150,255.255.255.0,12h
dhcp-option=3,192.168.50.1
dhcp-authoritative

3- sudo echo 1 > /proc/sys/net/ipv4/ip_forward
nano /etc/sysctl.conf
Uncomment line: net.ipv4.ip_forward=1
4- iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables-save > /etc/iptables.up.rules
5- Create a script sudo nano /etc/network/if-pre-up.d/iptables

#!/bin/sh

#This script restores iptables upon reboot  
iptables-restore < /etc/iptables.up.rules  

exit 0

Change ownership and permissions of the script so it will run at boot.

sudo chown root:root /etc/network/if-pre-up.d/iptables
sudo chmod +x /etc/network/if-pre-up.d/iptables
sudo chmod 755 /etc/network/if-pre-up.d/iptables
6- Reboot.
7- Check iptables is persistent: iptables –t nat -L
8- Connect a computer to eth1 (USB ASIX 88772).
9- In a Terminal ping 8.8.8.8 just to see when RPI2B hangs.
10- After browsing two or three webpages, pings don’t respond, and you cannot access to RPI2B with SSH, not from 192.168.1.x (connected to eth0-onboard LAN) neither from 192.168.50.1 (connected to eth1-USB LAN).

NOTE: I tried “step 2” doing it installing PiHole from DietPi-software, too, and adding the DHCP section to the file /etc/dnsmasq.conf but it didn’t work neither.

Please, can you help me? Am I doing something wrong? Is there any routing bug on RPI 2B?

I’m asking this last question because Michael Tremer, a main developer of IPFire distribution says about the Raspberry Pi 2 that it’s not very good for routing, and Arne.F, another core developer, talks about this, too, in http://forum.ipfire.org/viewtopic.php?t=12541

Thank you, than you very much!!

P.S. Should it be a good solution to forget the RPi 2 and buy an Odroid C1+ or XU4 and working with them with DietPi Debian distros?

Hi Skyfly,

I’ve never tried this myself, but i’ll try to assist you.

The only main difference with the RPiv1 and v2 (from my perspective) is:
RPiv2 = arm7 with backwards capability for armv6
RPiv1 = arm6
So unless the RPiv2 is somehow pulling in a faulty armv7 package, i’am not sure.

It may also be worth trying a kernel update on the RPiv2:

rpi-update



10- After browsing two or three webpages, pings don’t respond, and you cannot access to RPI2B with SSH, not from 192.168.1.x (connected to eth0-onboard LAN) neither from 192.168.50.1 (connected to eth1-USB LAN).

It might be worth installing rsyslog, then checking the logfiles on the system (eg: dnsmasq) when this occurs. They may hold some information.

I’m asking this last question because Michael Tremer, a main developer of IPFire distribution says about the Raspberry Pi 2 that it’s not very good for routing, and Arne.F, another core developer, talks about this, too, in > IPFire Community

I wouldn’t read too much into that. Sounds more like a development time issue, rather than an issue unique to the RPiv2.

P.S. Should it be a good solution to forget the RPi 2 and buy an Odroid C1+ or XU4 and working with them with DietPi Debian distros?

The only routing i’ve done is with dnsmasq and Pihole, nothing else.

However, the C1+ is a great board (my favourite), so much faster than the RPiv2 as it has a dedicated network chip (rather than usb routing) and 1.5ghz clock. It makes the RPiv2 feel like a snail. I used to run Pihole on it before I got my XU4.

The XU4 is a performance beast, but it has issues with CPU/ARM temperature. Even with the pre-installed heatsink, after 5 seconds at full load, the CPU will reach 95’c and force a downclock to reduce temperature and prevent damage. I run mine capped at 1.4ghz on all cores, max 60’c.
Also, the cloudshell for XU4 is brilliant, if you want a ARM based server/NAS with some onscreen stats, its worth it. https://dietpi.com/forum/t/dietpi-survey-information/32/1

Thank you very much for your help, Fourdee.

I’ve activated logs but finally I could use the RPI attached to the TV (this afternoon it was Kodi-occupied at home).

I have made 2 photos of the screen, it seems to be USB-NIC related.
Kernel Panic!



I’ll buy another different USB NIC.

It’s not the Asix USB dongle.

I’m using it (RPI 1 B and the USB Asix Ethernet dongle) with the image provided by a man called ElWilliaM in this forum (https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=24557) two years ago, and it works like a charm.

This is the image he shared in that forum:
https://www.dropbox.com/s/uq4ezoq2hurn69r/FruitGuard-transparent-alpha2.img.7z

So, I suppose that the version he’s using of Raspbian (or firmware?) doesn’t have the bug that the actual version of Raspbian has. Can this supposition be correct?

I’am not sure.

Looking at the kernel panic. It appears the error originates from the bcm2708 (your RPiv1 ARM). It could really be anything causing this and other issues, so I can’t comment just yet, we need to do more testing.

Some points worth checking:

  • Are you overclocking your system?
  • What’s the PSU used for both this and your RPiv2 (eg: official 5v 2amp)?
  • Your SD card used?

So just to clarify, can you list all the devices/distros you have tested and their results. eg:

  • RPiv1 + Raspbian Jessie = Kernel Panic.
  • RPiv2 + DietPi Wheezy = Hangs after 2 minutes

Thany you very much, Fourdee.

root@DietPi:~# lsusb
Bus 001 Device 004: ID 0fe6:9700 Kontron (Industrial Computer Source / ICS Advent) DM9601 Fast Ethernet Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The reality is that this USB dongle was listed simply as a ASIX88772 on my Macbook but I don’t know if it was misidentified or what happened!
Finally, listing USB devices on DietPi, the USB dongle I’m using works under the DM9601 driver, that seems to hangs very randomly, so it’s difficult to know what happens. Maybe one day it will seem to be Wheezy the trouble, another day dnsmasq, another day the USB port, another day…

Looking at http://elinux.org/RPi_USB_Ethernet_adapters I’ve seen clear not to waste more time and I have bought a TP-LINK UE300, in a few days I’ll have it at home and give it a try.

Thank you again, Fourdee, for your help, I really appreciate it.
Now I’m happy to have found the problem, and having some days to rest and simply enjoy DietPi (until the Usb dongle come home :smiley: )

Great to hear you found a solution. :slight_smile:

RPi USB Ethernet adapters - eLinux.org Great find, thanks for sharing. This is great information for users wanting to purchase a supported USBtoETH adapter for their RPi.

I need to purchase one for my PRi Zero. I’ll be using that page to pick one. :smiley:

This afternoon I received the TPLINK UE-300, USB 3.0 Gigabit Ethernet (Maybe you want to know this detail, I paid for it 16 € on Amazon).

Recognized by RPi 2 B out-of-the-box (now using the Wheezy v103 version) and working great with the configuration I’ve shared with you all.

Thanks for your help, Fourdee!