Raspberry Pi as 4G LTE Router
Previous
We have established connection to 4G LTE network
Goal
We are going to turn the Raspberry Pi into a Router for our devices, pick your need:
Wireless Router
Instead of reinventing the wheel, we follow the guide Sixfab tutorial
If you are using Raspberry Pi 2 or earlier, you will need a USB WiFi adaptor.
Backup wireless configurations
Not a must but you may want to do this, in case later you changed your mind.
1 | $ sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.backup.conf |
Configure wireless device
Clear the configuration file
1 | $ sudo cp /dev/null /etc/wpa_supplicant/wpa_supplicant.conf |
Add configurations into /etc/wpa_supplicant/wpa_supplicant.conf
:
1 | ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev |
Install RaspAP
Use a quick installer of RaspAP and follow the questions to setup the wireless network
1 | $ wget -q https://git.io/voEUQ -O /tmp/raspap && bash /tmp/raspap -y |
I did not tested this, so any problem or question (default password etc.), please refer to the Sixfab tutorial and the toubleshooting in the original tutorial
Wired Router
We are going to use network address translation (NAT) to bridge ppp0
with eth0
This tutorial was adopting sharing wifi through the ethernet and change it to share PPP connection to ethernet
DHCP and DNS server
I used dnsmasq
for DHCP + DNS.
1 | $ sudo apt-get install dnsmasq |
Configurate interfaces
Edit the eth0
section in file /etc/network/interfaces
:
1 | allow-hotplug eth0 |
Configure forwarding
Edit /etc/sysctl.conf
to enable packet forwarding.
1 | $ sudo nano /etc/sysctl.conf |
Find the line #net.ipv4.ip_forwarding=1
and remove the #
at the beginning to make it net.ipv4.ip_forwarding=1
. This will enable packet forwarding once the system reboot.
Configure dnsmasq
Backup dnsmasq configuration
1 | $ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig |
Edit /etc/dnsmasq.conf
1 | interface=eth0 # Use interface eth0 |
Enable
bind-interfaces
cause me unable to share the internet. You may need to test it.
NAT configuration
1 | $ sudo iptables -t nat -A POSTROUTING -o wwan0 -j MASQUERADE |
Make the rules persistent.
1 | $ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" |
Edit /etc/rc.local
1 | # Add this line above exit 0 |
DONE
Connect my laptop to Raspberry Pi
1 | $ ping 8.8.8.8 |