There are a few reasons in the Helium world why you might want to turn a raspberry pi into an ethernet router. However, what I care about is a customizable approach to cell backhaul. As it stands right now all off the shelf Helium miners are essentially black boxes with no SSH, no USB, and no real interfaces except through the app and any bluetooth switches. So the goal with a DIY ethernet router is to create a machine which forwards internet from another location to the miner, from which you can load up with all sorts of customized solutions.
Now, a warning. Doing this is fraught with pitfalls and unexplained bugs. I have figured out a sequence of steps which works for my setup, but inevitably some things can change which screws up this carefully choreographed setup.
A few tips before starting
- Have another SD card with a fresh raspberry pi reflash ready to go. Starting from scratch is quicker than undoing whatever mess was made.
- You need local access to the raspberry pi. If you’re SSH’ing over wifi, its going to cause trouble.
- I have tried this on Raspberry Pi OS and OS Lite (32-bit) dated from late December 2020 to January 2021. Use the official Raspberry Pi SD card reflasher tool.
- Tested on Pi 3b+ only.
Routing usb0 to eth0
The behavior I want is that any device connected to the Pi via ethernet cable will view the Pi as a router. The Pi will assign IP an address and function just as a router, forwarding any source of internet to the connected device. To do this there are prerequisites and certain scripts must be run on the Pi.Step 1: install dnsmasq
This is a straight forward and easy step.sudo apt-get install dnsmasq
Step 2: install the internet routing script
This step is the most troublesome. There are many instructions to accomplish this on the internet, however, this is the only reliable way I have found to accomplish what I am after. Here is a list of instructions which didn’t work for me: [1][2][3][4]Back to what worked:
curl -O https://raw.githubusercontent.com/arpitjindal97/raspbian-recipes/master/wifi-to-eth-route.sh
Move it to /pi/home/
sudo mv /downloads/wifi-to-eth-route.sh /home/pi/wifi-to-eth-route.sh
Give the right permissions
sudo chmod 755 wifi-to-eth-route.sh
Step 3: modify for your needs
!! Important !! You need to change one line depending on your internet channel configuration. By default, wifi-to-eth-route.sh will forward wlan0 to eth0, in other words forward wifi to the ethernet port. I want to change that to forward usb0 to eth0. Usb0 will eventually be the name of the cell internet portal. Depending on your exact Pi Hat situation, it may also be called wwan0.With nano,
sudo nano /home/pi/wifi-to-eth-route.sh
Change this line:
wlan="wlan0"
To:
wlan="usb0"
Step 4: finish the config
This script needs to run at boot. To do this, run these commands:sudo nano /etc/rc.local
Add this command before exit 0
bash /home/pi/wifi-to-eth-route.sh
Test it by connecting a device by ethernet to your Pi. It should go straight into an automatically assigned IP address with internet connectivity.