16 C
Texas

Reverse Tether from Linux to Android

We all have heard the name of tethering, right? It’s the method using which an Android device can work as the source of internet connection to a system. It’s super useful for situations when your system doesn’t have a Wi-Fi adapter (rare case, of course) or for some other reasons, you need your phone’s connectivity on your desktop/laptop/notebook etc.

Reverse tethering, as the name suggests, is the opposite of tethering. In this scenario, the Android phone is there to enjoy the internet connectivity from the desktop/laptop. Previously, it was super difficult as we had to undergo a seriously complex procedures using iptables, bridged connections etc. Thanks to the hard work of a developer, there’s an easy tool for Linux systems to reverse tether without any of those complexities. The tool has a nice, difficult name – Gnirehtet.

Important – Before going further, make sure that your Android has root unlocked. This is a must or much of the tool’s functionalities won’t work. Rooting an Android device, in many cases, will cause warranty void and other possible issues like bricking the phone. Check out your phone model on XDA Developers forum for a reliable method to root.

Don’t forget to check out this Android threat ADB.Miner that uses the open ADB ports.

Preparing the system

- Advertisement -

It’s time to setup Gnirehtet. First, we need the essential Android tools. Run the following command –

  • Ubuntu
sudo apt install android-tools-adb android-tools-fastboot

  • Debian
sudo apt-get install android-tools-adb android-tools-fastboot
  • OpenSUSE
sudo zypper in android-tools-adb android-tools-fastboot
  • Fedora
sudo dnf install android-tools-adb android-tools-fastboot
  • Arch Linux
sudo pacman -S android-tools-adb android-tools-fastboot
  • Generic Linux instructions

If your system isn’t listed above, you have to get the compressed package of the command line tools only. Then, extract the folder to a suitable place and add the path to the system’s environment variable.

Check out your ADB version –

adb version

Installing Gnirehtet

It’s finally time to get the tool. Run the following command –

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

Note that there’s also a Java version, but it’s not recommended. It will cause higher CPU and memory usage and may not work properly.

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

After downloading, extract the archive.

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

Switch the working directory to the Gnirehtet directory.

cd gnirehtet-rust-linux64

Configuring Android for reverse tethering

At first, from the Android device, go to Settings >> Developer options and enable “USB Debugging”.

Connect the device via USB and run the command on Linux terminal –

su -
OR
sudo -s

adb start server

Once your device is unlocked, return to the terminal and run this command –

adb kill-server

Using Gnirehtet

Start the terminal and run the following commands –

su -
OR
sudo -s

./gnirehtet autorun

You’ll get this notification in the Android phone. Allow the connection.

You’ll notice this icon at the top.

Re-connecting Android

Sometimes, the USB port may disconnect without warning or you may have to disconnect it as well. In that case, reconnect the device via USB and run these commands –

cd ~/gnirehtet
sudo ./gnirehtet restart

Stopping Gnirehtet

If you want to stop the reverse tethering connection, run this command –

cd ~/gnirehtet-*

sudo ./gnirehtet stop

Sometimes, this command won’t kill the reverse tethering programs properly. You have to run the following commands for properly killing the tool –

pidof ./gnirehtet

sudo kill -9 <process_number>

Enjoy!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article