Posted on Leave a comment

Off-Grid Internet: Build a 4G/5G modem with an Android phone and a Raspberry Pi

The solar generator has made its maiden voyage and performed spectacularly! Could it be better? Perhaps, if it had a 5G modem…

The Generator’s First Overnighter

I’ve since gone on my first overnight camping trip with the generator (if you missed it, you can read about the build here); It was able to power all of my telescope hardware, dew heaters, cameras, laptops, and keep the trailer’s propane heater fan running all night, for two straight nights with solar charging in between. The night that saw heaviest electricity usage drained the battery from 100% down to 35%, mostly because of the heater fan in the trailer. It should be good for any night, year-round. In terms of its capability as a power source, I couldn’t be happier.

Figure 1: Left, the generator stays in the bed of the truck, with trailer shore power connected to it (behind the trailer, out of view). Right, system charge state. The left display shows how much power is being produced by the panels (~330 Watts), and the display on the right shows how much is going to the battery (~290 Watts). The difference came mostly from electronic devices running in the trailer (we were charging a couple of iPads and a few camera batteries).

In addition to running my telescope gear, the generator also provided electricity for the movies that my boys and I watched as we settled into bed for our two nights out and for playing a couple hours of Minecraft after cutting firewood each day. It does require some planning, but I think after a couple more trips we’ll settle into a groove and power management will be second nature.

Figure 2: My two 200-Watt solar panels wired in series. Who needs a fancy metal stand when you can use firewood to get them off the ground?

Adding WiFi and Internet (not just a hotspot)

Now that we had a sustainable power source for these trips, I got to thinking about how we could do more with it. It’s always been a dream of mine to go camp in far-away places and still be able to do remote work during the day (as a software developer, I don’t need more than a laptop and the internet to do work). Being able to do so could dramatically extend our camping time, even if I can’t take vacation time. During the first trip with the generator, we did use my phone’s Wifi hotspot, but it had some major shortcomings; networking between devices didn’t always work, and it quickly wore down my phone’s battery.

I did, however, have an extra WiFi router at home that wasn’t being used, and with a background in Computer Science, I knew it had to be possible to create some kind of “modem” that could be tethered to a phone while connected to the router’s ethernet port. The Raspberry Pi already has a built-in Ethernet port and full-size USB ports. With some hacking, it’s just the thing I needed.

If you want to try to do this yourself, here’s everything I used on this project.

Tools/Parts Needed

  •  Netgear N300 Router ($19.99) – most importantly, it requires 12V DC power.
  • Raspberry Pi 3B+ with Clear Case by CanaKit ($59.99)
  • Drok 12V DC to 5V USB Converter ($12.99)
  • 32GB MicroSD ($7.59) – you could probably go smaller, but when it’s this cheap, who cares?
  • A computer to flash the SD card with a Raspberry Pi O/S image
  • An HDMI monitor and a USB keyboard for interacting with the Pi. I have a KVM switch at home for this, which makes this a lot easier.
  • 3/4″ Wood Screws to mount things to the generator lid
  • A USB A to Micro cable
  • Fuses, 2A and 3A
  • Wire cutters/strippers
  • Heat-shrink connectors, both butt and fork type
  • Small hacksaw
  • An Android phone with a data plan. I am certain there is a way to do this on an iPhone, but I don’t have one. Therefore, the following instructions will be written with Android users in mind.

Step 1 of 6: Set up the Raspberry Pi O/S

Before we get started, I want to make a quick shout-out to Michael Franzl, whose fantastic blog post got me most of the way to getting this modem project to work on my Raspberry Pi 3B+. I did make several modifications to his instructions in order to make things work for this particular setup, but much of what I got going on my end is owed to Michael for sharing his knowledge. Thanks for the fantastic instructions!

Now, to do this, we need a computer with a MicroSD card slot. Plug your MicroSD card into your computer, then visit Download and install the latest version of the Raspberry Pi Imager software. Once it’s installed, run the Imager and tell it which SD card slot to use, then choose the latest version of Raspberry Pi OS Lite. This will install the O/S, minus the graphical user-interface (GUI). We will only need the command line to set up the Raspberry anyway, so the GUI will only make startup take longer. The GUI also does some things with the Raspberry’s network card that may interfere with how we want to use it; as a modem, not a regular Desktop connection.

Figure 3: Choosing the correct Raspberry OS.

Once you’ve chosen the Raspberry Pi OS Lite version, the Imager software will download the correct image and install it onto the SD card for you. You can then remove the MicroSD card from your computer and plug it into the Raspberry Pi. Connect the Pi to power, keyboard, and monitor, and fire it up. The first thing to do will be to change your password. The “Pi” account has root access, so you don’t want to keep the default password. Change it to something only you know by using the “passwd” utility. Next, connect your phone to the Pi with a USB cable and tether it.

Step 2 of 6: Set up a DNS Server

To the uninitiated, DNS stands for “Domain Name System”. In layman’s terms, it’s the decentralized system that translates names like “” into raw IP addresses like “”. Because our Raspberry Pi will act like a gateway to the internet, we need to set it up with a DNS Server so that it knows how to translate URLs into IP addresses to the sites we want to visit. To do this, we’ll  need to install some software called bind9 and configure it. From the command line on the Pi, run the following (for these and all subsequent commands, we’ll need to run them using “sudo”).

apt-get update
apt-get install bind9

Now that bind9 is installed, let’s configure it to point to Google’s DNS Servers.  Edit the file /etc/bind/named.conf.options so that its forwarders block looks like this:

forwarders {;;

To make the change take effect, restart bind9 with the following command.

systemctl restart bind9

Step 3 of 6: Give the Pi’s Ethernet Adapter a Static IP Address

Like the instructions in Michael Franzl’s blog post, we’ll be giving our Pi a Static IP. This is the IP address that we’ll later configure our Router to point to as the internet gateway in Step Y. To do this, edit the file /etc/systemd/network/ to look like the following.



Restart the Pi or restart the network interface by running the following to make this change take effect.

systemctl restart systemd-networkd

Step 4 of 6: Configure the phone for DHCP.

Edit the file /etc/systemd/network/ to look like the following.



Use the same “systemctl restart systemd-networkd” command as in Step 3 to enable this change.  This will allow the “usb0” interface that the phone installs on the Pi to obtain its IP address automatically. Next, we’ll “trick” the phone into handling all internet traffic requests from eth0 (meaning, our Wifi router).

Step 5 of 6: Configure Protocol Forwarding and Network Address Translation

To enable IP protocol forwarding, edit /etc/sysctl.d/30-ipforward.conf and add the following:

net.ipv4.ip_forward = 1

Enable this change by running “sysctl –system”. Forwarding will now be enabled even after rebooting the Pi. Now that IP protocol forwarding is enabled, we need to write a shell script that will forward all outbound internet traffic from the ethernet interface to the tethered phone interface, and then return the incoming responses to that traffic back to wherever on the LAN the original traffic came from. To do this, we’ll create a script and have systemd run it whenever the Pi starts up.

Create the script /usr/bin/ and make it executable by running “chmod a+x” on it. Then, edit the script so that it contains the following and save it.

iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o usb0 -j ACCEPT

Now, to make systemd run this script at startup, we need to create one more file. Edit /etc/systemd/system/startgateway.service to contain the following.

Description=Start Gateway



Now, reboot the Pi and all of these changes should take effect. We are almost ready to use our new modem.

Step 6 of 6: Configure the Router

The only thing left to do is set up our Wifi Router to connect to (the static IP of our Raspberry Pi) as the modem. Connect the Pi via Ethernet cable to the WAN port on the Wifi router. Connect a device (not your phone; it’s tethered!) to your wifi router and use it to access the router’s admin page.

Go to wherever the router’s internet settings are and give it a static IP of and a gateway address of This will allow it to “talk to” the Raspberry Pi as if it were a modem. You will also want to configure its DNS Servers the same way as how we did for the Pi itself with bind9. For reference, here’s what my Netgear N300 Internet setup page looks like.

Figure 4: Static internet IP settings that reflect the static IP we gave to the Raspberry Pi.

Optional: Enable SSH Server on Raspberry Pi

You don’t have to do this, but it makes for a very convenient way of updating your Raspberry Pi. All you need to do is run raspbi-configchoose Interface Options, then SSH. Choose Yes on the following screen to enable the SSH server and reboot. To SSH into the Pi, simply connect your computer to the same Wifi router that we just set up and SSH as the “pi” user into and voila! We now have terminal access to the Pi!

Figure 5: Running raspbi-config over SSH. PuTTy was used to make the SSH connection.


Getting everything to fit into the solar generator box was the fun part. There wasn’t a whole lot of extra space, but there was just enough between the fuse box and the solar charge controller.

Figure 6: The final setup. Netgear N300 is the black box to the left. The little box below and to the right of the Raspberry Pi is a 12v-to-5v-USB power adapter, wired directly to the fuse box.

The N300 had an annoying plastic stand that was integrated into the bottom of the plastic case; annoying because it extended beyond the sides of the unit and kept me from mounting it to the plywood. I ended up cutting this off with a hacksaw. The side of the case opposite the one you see above had the same triangular perforations all the way across the entire surface, so I mounted it to the plywood in the lid of the solar generator with four 3/4″ screws.

The Raspberry Pi’s case came with two screw holes in it, so I used two 3/4″ wood screws to mount it in place.

Figure 7: Mounting the Raspberry Pi case.

Fully assembled, there was barely enough room to insert the Pi’s SD card back into it. I did have to buy some special right-angle USB cables to run back into the bottom of the generator box to connect my phone to. I may extend these to the outside of the case with a USB passthrough port, but I’ll save that for a later project.

Figure 8: Inserting the SD card into the Raspberry Pi.

Unfortunately, I didn’t get any close-up photos of how I connected these two devices to the fuse box for power. For the Wireless router (Netgear N300), it came with an A/C adapter that put out 1000 milliamps of 12V DC, so I cut the end off and spliced the wires into some heatshrink fork connectors. A 2-amp fuse was added to the fuse block to protect the circuit. The Raspberry Pi uses a 5v USB power source, so I  bought  a 12V-to-5V-USB converter that the Pi plugs into. I spliced heatshrink fork connects into this USB power source as well and connected it directly to the fuse block. A 3-amp fuse is sufficient protection for this circuit.

Because both the router and the modem run directly off 12v power, we have no AC-to-DC conversion losses. The end result is an extremely efficient system. Running the Wifi router and Raspberry Pi modem at the same time consumes less than 4 Watts of power. On a 2KWh battery like the one I have in this generator box, it could run for up to 500 hours without recharging.

What Can It Do?

Well, your results may vary, but I currently tether using an aging Samsung Galaxy Note 8 on an unlimited 4G data plan from T-Mobile, and can get almost 50Mbps download and over 25Mbps upload speeds from my house. This phone isn’t 5G capable, so I suspect I’d get even better speed with a newer phone.

Figure 9: My results from a laptop connected to my Raspberry-Pi-Modem-enabled Wifi network.

This turns out to be almost 60% faster than my home internet connection from Comcast (although I admit, I’m a cheapskate and pay the least amount possible). Do I get data rates like this everywhere? Not by a longshot. But the cool thing is I can be on the road and still do my remote work, freeing up many more potential nights under dark skies, away from light pollution.

A second side effect to having this is that I can more easily work on this blog when I’m away. In fact, I wrote this entire article while connected to my Wifi-enabled solar generator box. It also makes my imaging sessions faster and easier because I can run all of my wireless imaging gear (cameras, intervalometer apps) on the same Wifi network in-the-field and from the comfort of my camper. I can pre-configure everything at home so it’s ready to connect up when I get to my favorite dark sky sites. And there will be much less checking on the autoguider outside in the cold; I can just remote into it from my laptop in the trailer and make sure everything is running smoothly from there, and only freeze myself outside if something goes wrong.

One negative aspect of having something like this is that it does make “staying connected” while away harder to get away from. I’m not sure about you guys, but much of the reason why I go camping is to leave the internet behind and spend more time on the “outernet.” I’m hoping that this new tool for my photography doesn’t become another tether to the busy-ness that is my professional life. Time will tell.

Final Thoughts

I am looking forward to getting into a new rhythm this year, both for my photography and the ability to seamlessly blend the technology it requires with my need to be outside and exploring. I’m going to try my best to keep the internet at bay while I’m out shooting the stars, but I’ll be able to keep you posted more often while I’m still “in the field”, and that makes me happy.

What do you think of this system? What could you do with one if you built one? How would you improve it? Let me know in the comments below!

Leave a Reply

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