Reverse tethering with Android

published on

You’ve most likely found yourself in situations where you needed internet on your computer but had no WiFi network close-by. What do you do? Fire up a hotspot from your smartphone and share its internet connection with the laptop. The technical term for sharing a phone’s internet connection with another device — be it over WiFi, Bluetooth or USB — is tethering.

Recently, however, I found myself in the opposite position: I had internet on my laptop but not on my phone! Reverse tethering to the rescue!

The Replicant Situation

In one of my experiments, I flashed Replicant — a fully free, Android-based operating system for mobile phones — onto an old Samsung Galaxy S2.

Now, since Replicant is fully free, it does not come with the proprietary drivers necessary to operate the WiFi module in that phone. That means, the only way to get an internet connection on the phone is through the mobile data (3G) on a SIM card. Now, in addition to the (for current standard) sluggishness of the processor, this rules the phone out as a daily driver for me1. Nonetheless, I was curious what I could do with Replicant running on the phone.

After the initial excitement that Free Software could power a phone where most functionalities are provided, the phone ended up unused in one of my drawers.

When writing the blog post on BOINC, where I call on people to use their computing devices as long as they work, my unused Samsung Galaxy S2 came to my mind.

I was fairly confident that I could install the BOINC Android client from the F-Droid store on the phone, too. But I had to get internet on it somehow… Especially as I also wanted to upload/download BOINC tasks completed on the S2 later on as well.

Reverse Tethering with gnirehtet

After some browsing, I found gnirehtet: a program which enables you to share your computer’s internet connection with your Android device over USB with adb.

Installation

To set up gnirehtet on your computer and Android phone, just follow the steps as outlined in the project’s README: this should get you up and running with reverse tethering.

Optional CLI parameters to gnirehtet

Now, gnirehtet’s README (understandably) does not list all command line options it supports. You can get this info by running gnirehtet --help.

In my case I needed to execute gnirehtet run on a different port because the default port of 31416 was used on my machine already. The -p option allows you to specify the port to run gnirehtet on.

Putting gnirehtet in $PATH

After experimenting with gnirehtet and convincing myself that it does the job, I decided to make the executable findable by my shell. Thus, I would not have to specify the full path to the gnirehtet executable every time I want to run it.

To that end, I first copied the folder containing the gnirehtet executable into /opt - a directory “reserved for the installation of add-on application software packages” according to the Filesystem Hierarchy Standard.

Then, I checked what my PATH environment variable looked like with echo $PATH. Since /usr/bin was on my $PATH, I decided to simply create a symlink in /usr/bin which points to the gnirehtet executable in /opt. Works like a charm.


  1. I have heard of people whose needs were satisfied with this setup, so it might work for you as well. ↩︎