Oct 222017
 

My ADSL connection went down for quite a while recently, but I managed to use a Telstra 4G USB Stick with my Raspberry Pi as a secondary internet link to tide me over until my ADSL was restored.

The 4G

The 4G Modem was a ZTE MF823. These are actually little linux routers that are then connected to the Pi via the USB interface.
The Pi gets a usb0 interface when this is plugged in. I’ll expand on how I configured the networking further down.

The Raspberry Pi

I started off with a Raspbian Stretch Lite install on my Raspberry Pi. This was an older RPi 1 Model B. I needed a powered USB hub to power the 4G Modem, and to power the Pi. As this was an older model, I flashed Raspbian Lite onto an SD Card rather than a Micro SD card. The first flash ended up with some errors, so I had to flash it again.

Networking

As the 4G USB stick was actually a little router on a stick, the Pi needed some configuration for the usb interface as well as ethernet, as I was sharing the internet out through the Pi’s ethernet port.
I set up the Pi with a static IP address for the ethernet port, and set up the USB interface as DHCP so it would get an IP address from the 4G stick.
I also set up routes for the rest of the network at this point because I run a pfSense box as my normal router for the rest of my network.

I set all of the networking on my Pi up in the /etc/network/interfaces file as this is what I was used to. You can also set it up via dhcpcd.conf
In the configuration example below, my Pi has been assigned the address 10.1.1.1 and my pfSense router is 10.1.1.2.
There have also been 2 routes added to 2 separate networks behind the pfSense box.

auto eth0
iface eth0 inet static
address 10.1.1.1
netmask 255.255.255.0
post-up ip route add 192.168.12.0/24 via 10.1.1.2
post-up ip route add 192.168.10.0/24 via 10.1.1.2

auto usb0
iface usb0 inet dhcp

I also needed to add a rule to iptables to NAT all the traffic from my home network out to the 4G modem so that anything coming back would know where to go.
I used the iptables-persistent package/utility to save the rules, but this could also be done via the interfaces file similar to how the routes were added, or added to the rc.local file in the event that you cannot install iptables-persistent

iptables-persistent example:

# iptables -t nat -A POSTROUTING -j MASQUERADE
# iptables-save

/etc/network/interfaces example:

post-up iptables -t nat -A POSTROUTING -j MASQUERADE

/etc/rc.local example – add this line before exit 0:

iptables -t nat -A POSTROUTING -j MASQUERADE

The Home Network

Once the Pi was set up, I could now set up the rest of my home network to use the Pi rather than my normal ADSL link to connect to the Internet.
As the rest of my network is actually on a different subnet (192.168.12.0/24) behind the pfSense box, the pfSense box had to have another gateway set up so I could redirect traffic through to the 4G link rather than the ADSL Link.
I mostly followed the official Multi-WAN guide to set up my pfSense box, but this could have been achieved without setting up multi-wan and just setting the default gateway on pfSense to my 4G link.

Initially, I had to set up the DNS servers to point to 192.168.5.1 which is the DNS server that’s on the 4G USB stick while the ADSL was down. This was because the DNS server on pfSense would not resolve internet sites. However this messed with local name resolution, so I had to swap to dnsmasq on pfSense for both local and internet name resolution to work properly.

Further Expansion

Since my ADSL is now back up, this Pi with 4G is now serving as my backup internet connection in conjunction with my ADSL. However, with the addition of a power bank, and a USB WiFi adapter, this would serve as a very capable 4G hotspot.
An added Web interface (RaspAP perhaps? 😀), and Pi-Hole would make this whole setup much easier to manage as well as saving bandwidth for the 4G connection.

I also have a 3G stick that I could potentially use instead of the 4G stick as the 3G stick is a Huawei E353Tu-6 which doesn’t have the extra router element to it. This stick exposes a WWAN0 interface on the Pi which would make configuration slightly easier as I don’t need the usb configuration, but then would need to setup a dialer of some sort on the Pi…Something to ponder for later on.

Share

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.