Convert Figma logo to code with AI

Genymobile logognirehtet

Gnirehtet provides reverse tethering for Android

6,331
580
6,331
294

Top Related Projects

Share your VPN connection over hotspot or repeater! (root required)

Mirror only. Official repository is at https://git.zx2c4.com/wireguard-android

A shadowsocks client for Android

Powerful and extensible proxy server with anti-censorship functionality for Android

Quick Overview

Gnirehtet is a reverse tethering tool for Android that allows sharing a computer's internet connection with an Android device over USB. It works without root access and supports both IPv4 and IPv6 traffic, making it useful for developers and users who need internet access on their Android devices in situations where Wi-Fi or mobile data is unavailable.

Pros

  • No root access required on the Android device
  • Supports both IPv4 and IPv6 traffic
  • Cross-platform support (Windows, macOS, Linux)
  • Easy to set up and use

Cons

  • Requires USB debugging to be enabled on the Android device
  • May not work with all Android devices or operating system versions
  • Performance may be slower compared to native Wi-Fi or mobile data connections
  • Requires the device to be physically connected to the computer via USB

Getting Started

  1. Download the latest release of Gnirehtet from the GitHub repository.
  2. Enable USB debugging on your Android device.
  3. Connect your Android device to your computer via USB.
  4. Run the following command on your computer:
./gnirehtet run
  1. On first run, you'll need to grant the app permission on your Android device.
  2. Your Android device should now have internet access through your computer's connection.

To stop the connection, press Ctrl+C in the terminal where Gnirehtet is running.

Competitor Comparisons

Share your VPN connection over hotspot or repeater! (root required)

Pros of VPNHotspot

  • Offers a user-friendly Android app interface for easy setup and management
  • Supports both Wi-Fi and USB tethering options
  • Includes additional features like client list management and data usage tracking

Cons of VPNHotspot

  • Limited to Android devices as the host platform
  • May require root access for certain features, potentially limiting accessibility
  • Might have higher battery consumption due to running on mobile devices

Code Comparison

VPNHotspot (Kotlin):

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    super.onStartCommand(intent, flags, startId)
    if (intent?.getBooleanExtra(EXTRA_CANCEL, false) == true) stopSelf()
    else BootReceiver.enqueueWork(this)
    return Service.START_STICKY
}

gnirehtet (Rust):

fn start_relay(&mut self) -> io::Result<()> {
    info!("Starting relay server...");
    self.selector.register(&self.server_socket, RELAY_SERVER, Ready::readable(), PollOpt::level())?;
    self.selector.register(&self.client_socket, RELAY_CLIENT, Ready::readable(), PollOpt::level())?;
    Ok(())
}

Both projects aim to provide internet sharing capabilities, but they differ in implementation and target platforms. VPNHotspot focuses on Android devices with a user-friendly interface, while gnirehtet offers a cross-platform solution using Rust for better performance and lower resource usage.

Mirror only. Official repository is at https://git.zx2c4.com/wireguard-android

Pros of wireguard-android

  • Offers a full VPN solution with strong encryption and better performance
  • Widely adopted and supported across multiple platforms
  • More feature-rich, including options for split tunneling and custom DNS

Cons of wireguard-android

  • More complex setup process compared to gnirehtet
  • Requires root access or VPN permission on Android devices
  • May have higher battery consumption due to continuous encryption

Code Comparison

gnirehtet (Java):

private void startClient() {
    if (client != null) {
        client.stop();
    }
    client = new Relay(this);
    client.start();
}

wireguard-android (Kotlin):

private fun startTunnel() {
    val config = getConfig()
    val tunnel = Tunnel.create(config)
    tunnel.start()
    setTunnelStatus(TunnelStatus.UP)
}

Both projects aim to provide network connectivity solutions for Android devices, but they serve different purposes. gnirehtet focuses on reverse tethering, allowing Android devices to use a computer's internet connection, while wireguard-android implements the WireGuard VPN protocol for secure, encrypted connections. The code snippets demonstrate the different approaches: gnirehtet uses a simple relay client, while wireguard-android creates and manages VPN tunnels.

A shadowsocks client for Android

Pros of shadowsocks-android

  • More established project with a larger user base and community support
  • Offers a wider range of encryption methods and protocols
  • Supports multiple server configurations and automatic server switching

Cons of shadowsocks-android

  • Requires server-side setup, which can be more complex for beginners
  • May be less effective in some heavily censored networks compared to gnirehtet
  • Potentially higher battery consumption due to continuous encryption processes

Code Comparison

shadowsocks-android:

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    if (BaseService.usingVirtualProcess) {
        stopSelf()
        return Service.START_NOT_STICKY
    }
    DataStore.connectingJob = Job()
    super.onStartCommand(intent, flags, startId)
    return Service.START_STICKY
}

gnirehtet:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    LOGGER.info("Starting");
    startForeground(NOTIFICATION_ID, createNotification());
    if (intent == null || intent.getAction() == null) {
        CommandLineArguments args = CommandLineArguments.parseFrom(intent);
        startGnirehtet(args);
    }
    return START_STICKY;
}

Both projects implement similar service start methods, but gnirehtet focuses on creating a foreground service and starting the main functionality, while shadowsocks-android includes additional checks and data store operations.

Powerful and extensible proxy server with anti-censorship functionality for Android

Pros of PowerTunnel-Android

  • Focuses on censorship circumvention and content unblocking
  • Supports custom DNS servers and DNS-over-HTTPS
  • Includes built-in ad blocking functionality

Cons of PowerTunnel-Android

  • May have higher battery consumption due to additional features
  • Potentially more complex setup for basic users
  • Limited to HTTP/HTTPS traffic, unlike gnirehtet's full TCP/UDP support

Code Comparison

PowerTunnel-Android (Java):

@Override
protected void onStartCommand() {
    if (DNSOverHTTPSResolver.isEnabled(this)) {
        dohResolver = new DNSOverHTTPSResolver(this);
        dohResolver.start();
    }
}

gnirehtet (Rust):

fn run(config: Config) -> Result<(), Box<dyn Error>> {
    let event_loop = EventLoop::new()?;
    let relay_server = RelayServer::new(config.port)?;
    event_loop.run(relay_server)?;
    Ok(())
}

PowerTunnel-Android focuses on DNS manipulation and content unblocking, while gnirehtet provides a more general-purpose reverse tethering solution. The code snippets highlight their different approaches: PowerTunnel-Android initializes DNS-over-HTTPS, while gnirehtet sets up a relay server for network traffic.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Gnirehtet (v2.5.1)

This project provides reverse tethering over adb for Android: it allows devices to use the internet connection of the computer they are plugged on. It does not require any root access (neither on the device nor on the computer). It works on GNU/Linux, Windows and Mac OS.

Currently, it relays TCP and UDP over IPv4 traffic, but it does not support IPv6 (yet?).

This project is not actively maintained anymore, only major blockers (like build issues) are fixed. It should still work, though.

Flavors

Two implementations of Gnirehtet are available:

  • one in Java;
  • one in Rust.

Which one to choose?

Use the Rust implementation. The native binary consumes less CPU and memory, and does not require a Java runtime environment.

The relay server of Gnirehtet was initially only implemented in Java. As a benefit, the same "binary" runs on every platform having Java 8 runtime installed. It is still maintained to provide a working alternative in case of problems with the Rust version.

Requirements

The Android application requires at least API 21 (Android 5.0).

For the Java version only, Java 8 (JRE) is required on your computer. On Debian-based distros, install the package openjdk-8-jre.

adb

You need a recent version of adb (where adb reverse is implemented, it works with 1.0.36).

It is available in the Android SDK platform tools.

On Debian-based distros, you can alternatively install the package android-tools-adb.

On Windows, if you need adb only for this application, just download the platform-tools and extract the following files to the gnirehtet directory:

  • adb.exe
  • AdbWinApi.dll
  • AdbWinUsbApi.dll

Make sure you enabled adb debugging on your device(s).

Get the app

Homebrew

If you use Homebrew, getting up and running is very quick. To install the Rust version:

brew install gnirehtet

Download

Download the latest release in the flavor you want.

Rust

Then extract it.

The Linux and MacOS archives contain:

  • gnirehtet.apk
  • gnirehtet

The Windows archive contains:

  • gnirehtet.apk
  • gnirehtet.exe
  • gnirehtet-run.cmd

Java

Then extract it. The archive contains:

  • gnirehtet.apk
  • gnirehtet.jar
  • gnirehtet
  • gnirehtet.cmd
  • gnirehtet-run.cmd

Run (simple)

Note: On Windows, replace ./gnirehtet by gnirehtet in the following commands.

The application has no UI, and is intended to be controlled from the computer only.

If you want to activate reverse tethering for exactly one device, just execute:

./gnirehtet run

Reverse tethering remains active until you press Ctrl+C.

On Windows, for convenience, you can double-click on gnirehtet-run.cmd instead (it just executes gnirehtet run, without requiring to open a terminal).

The very first start should open a popup to request permission:

request

A "key" logo appears in the status bar whenever Gnirehtet is active:

key

Alternatively, you can enable reverse tethering for all connected devices (present and future) by calling:

./gnirehtet autorun

Run

You can execute the actions separately (it may be useful if you want to reverse tether several devices simultaneously).

Start the relay server and keep it open:

./gnirehtet relay

Install the apk on your Android device:

./gnirehtet install [serial]

In another terminal, for each client, execute:

./gnirehtet start [serial]

To stop a client:

./gnirehtet stop [serial]

To reset the tunnel (useful to get the connection back when a device is unplugged and plugged back while gnirehtet is active):

./gnirehtet tunnel [serial]

The serial parameter is required only if adb devices outputs more than one device.

For advanced options, call ./gnirehtet without arguments to get more details.

Run manually

The gnirehtet program exposes a simple command-line interface that executes lower-level commands. You can call them manually instead.

To start the relay server:

./gnirehtet relay

To install the apk:

adb install -r gnirehtet.apk

To start a client:

adb reverse localabstract:gnirehtet tcp:31416
adb shell am start -a com.genymobile.gnirehtet.START \
    -n com.genymobile.gnirehtet/.GnirehtetActivity

To stop a client:

adb shell am start -a com.genymobile.gnirehtet.STOP \
    -n com.genymobile.gnirehtet/.GnirehtetActivity

Environment variables

ADB defines a custom path to the adb executable:

ADB=/path/to/my/adb ./gnirehtet run

GNIREHTET_APK defines a custom path to gnirehtet.apk:

GNIREHTET_APK=/usr/share/gnirehtet/gnirehtet.apk ./gnirehtet run

Why gnirehtet?

rev <<< tethering

(in Bash)

Developers

Read the developers page.

Licence

Copyright (C) 2017 Genymobile

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Articles