1. Home
  2. Linux

How To Reverse Tether From Linux To Android With Gnirehtet

In the past, if you wanted to reverse tether from Linux to Android, you had to use IP tables, bridged connections, and other overly complex tools. However, thanks to the hard work of a developer, reverse-tethering has been made easier.

Introducing Gniretet! It’s an experimental program that works as a background service to create a working USB reverse-tethering system, allowing you to reverse tether from Linux to Android.

Note: before attempting to follow this guide, ensure your Android device has Root access. Without Root access, many of the operations that Gniretet needs will not work correctly.

Gaining Root access on Android is easier than ever, and many devices have detailed walkthroughs. Check out the XDA Forums for more information.

Install Android tools

Reverse tethering with GNirehtet works thanks to the Android development tools. Before continuing with this guide, you must install it on Linux. Luckily, most Linux distributions make this an easy process. Open up a terminal and follow the instructions based on your operating system.

Ubuntu

sudo apt install android-tools

Debian

sudo apt-get install android-tools

Arch Linux

sudo pacman -S android-tools

Fedora

sudo dnf install android-tools

OpenSUSE

sudo zypper in android-tools

Generic Linux

Google supports the Linux platform very well, and as a result, the Android SDK toolkit is readily available. To install it on your operating system, head over to the official page. Extract the downloaded archive and follow the instructions inside!

Install Gnirehtet

Gnirehtet is available on Github. The source code is downloadable and ready for compilation. However, it’s much easier to just head over to the release page and download a pre-compiled version of the software. On the release page, there is a Java version and a Rust version. For ease of use, we recommend downloading the Rust version as it doesn’t require installing a Java Runtime Environment.

Note: decide to use the Java version? You’ll need to install the Java Runtime Environment on Linux.

To download the latest version of Gnirehtet, open up a terminal and use the wget tool.

wget https://github.com/Genymobile/gnirehtet/releases/download/v2.2.1/gnirehtet-rust-linux64-v2.2.1.zip

Alternatively, download the Java version, with:

wget https://github.com/Genymobile/gnirehtet/releases/download/v2.2.1/gnirehtet-java-v2.2.1.zip

Once Gnirehtet is downloaded, use the unzip tool to extract the contents of the Zip archive.

unzip gnirehtet-rust-linux64-v2.2.1.zip

or

unzip gnirehtet-java-v2.2.1.zip

Open up the file manager, navigate to the “Gnirehtet” folder. Copy the gnirehtet.apk file over to your Android device, and install it.

Open up a terminal and use the CD command to move into the extracted Gnirehtet folder.

cd ~/gnirehtet-*

Configure Android For Tethering

The Gnirehtet tool will not work without a few tweaks to the Android operating system. Start off by opening “Settings”. Go to “About phone,” and tap on the build number till a notification that says “You are now a developer” appears.

Go to Developer options, look for “USB” debugging and enable it.

Open up a terminal and start an Adb server.

su -

or

sudo -s
adb start server

Unlock your Android device and check the box to “always accept” ADB connections. Then return to the terminal running the ADB server and kill it.

adb kill-server

Using Gnirehtet

Gnirehtet works by creating a connection between your Linux PC and the Android device over USB. To start a connection, open up a terminal and gain a root shell.

su -

or

sudo -s

With a root shell, the Gnirehtet app can work with the Linux system without issue, and communicate over ADB to the Android device. At  this point, start the connection:

./gnirehtet autorun

Upon starting the connection with Gnirehtet, a new VPN connection prompt will appear on your Android device. Unlock it and accept the connection.

After accepting the VPN connection, Gnirehtet will successfully start routing an internet connection over USB directly to the Android device.

Reconnecting

Sometimes, USB cables come unplugged. In the event that this happens while the Gnirehtet service is running, the connection will end. Thankfully, the program has a feature that users can execute to instantly restore a lost connection.

To restore a connection, open up a terminal, gain a root shell with su, or run with sudo.

cd ~/gnirehtet-*

Inside of the Gnirehtet folder, execute the program with the restart flag. This will restart the reverse tethering system.

sudo ./gnirehtet restart

When the command finishes running, unlock the Android device and re-accept the VPN connection to finalize the restart process.

Stop Connection

The reverse tether can be shut down at any time. To do it, open up a new terminal (leave the existing one running the connection open), and do the following:

cd ~/gnirehtet-*

sudo ./gnirehtet stop

Sometimes, running the stop command doesn’t always kill the reverse tether connection. If this happens, you’ll need to force Gnirehtet to quit.

To kill Gnirehtet, find the process ID using pidof, then stop the program with the kill command.

pidof ./gnirehtet

sudo kill -9 processnumber

Leave a comment