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?).
Two implementations of Gnirehtet are available:
- one in Java;
- one in Rust.
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.
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
.
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).
If you use Homebrew, getting up and running is very quick. To install the Rust version:
brew install gnirehtet
Download the latest release in the flavor you want.
- Linux:
gnirehtet-rust-linux64-v2.5.zip
(SHA-256: 2b1ce04540e8de5df5ddbebb64bb01e27c13d556b3a04a8563dcce3786765705) - Windows:
gnirehtet-rust-win64-v2.5.zip
(SHA-256: 9f6d7700368f45d2fa43923324660eca9f879e837e10fc45d8d975273eae4755) - MacOS:
gnirehtet-rust-macos64-v2.2.1.zip
(old release)
(SHA-256: 902103e6497f995e1e9b92421be212559950cca4a8b557e1f0403769aee06fc8)
Then extract it.
The Linux and MacOS archives contain:
gnirehtet.apk
gnirehtet
The Windows archive contains:
gnirehtet.apk
gnirehtet.exe
gnirehtet-run.cmd
- All platforms:
gnirehtet-java-v2.5.zip
(SHA-256: c65fc1a35e6b169ab6aa45e695c043e933f6fd650363aea7c2add0ecb0db27ca)
Then extract it. The archive contains:
gnirehtet.apk
gnirehtet.jar
gnirehtet
gnirehtet.cmd
gnirehtet-run.cmd
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:
A "key" logo appears in the status bar whenever Gnirehtet is active:
Alternatively, you can enable reverse tethering for all connected devices (present and future) by calling:
./gnirehtet autorun
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.
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
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
rev <<< tethering
(in Bash)
Read the developers page.
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.
- Introducing “gnirehtet”, a reverse tethering tool for Android (French version)
- Gnirehtet 2: our reverse tethering tool for Android now available in Rust
- Gnirehtet rewritten in Rust (French version)
最近我发现了一款开源软件 Gnirehtet,作者是 GitHub 上的 Genymobile。
软件在电脑端运行之后可以用数据线共享电脑网络,这样手机无需连接 WiFi 无需数据流量,一样可以高速上网。
它的原理就是通过 adb 为 Android 设备提供 reverse tethering(反向网络连接),允许设备在插入计算机后,通过建立一个虚拟专用网络(VPN),使用电脑的网络而不用消耗自身的流量。
它有一些使用限制条件,只能是安卓手机,还要求是安卓 5.1 以上系统,当然无需 root,软件支持 Windows 系统,但是不支持 Windows XP 系统。
其实这些限制基本上对大部分用户来说都不是问题,现在就教大家如何来设置。
设置方法
在手机设置中打开开发者选项,并勾选允许 USB 调试。
如果手机设置找不到开发者选项的打开方式,那就说明之前还没开启过,由于各个牌子手机开启的方式不同,大家简单去搜一下就能解决。
在用数据线连接电脑时选择传输文件。
在后台获取电脑端的软件,解压后打开 ,双击打开 gnirehtet-run 启动软件。
这时电脑会有一个黑色命令窗口弹出。如果出现以下界面说明连接成功了。
手机端也会出现以下提示,分别点击继续安装和确定。
在手机上开启飞行模式测试一下,确实不需要数据流量也可以正常上网了。
不过使用时也不要不要关闭电脑上的命令窗口。
想要断开连接时,在手机上通知栏中点击 Stop Gnirehtet 就可以了。
如此以来,终于让手机可以享用高速上网了。
为了检验速度,我在家里的网络环境下进行了测速比较,用这个方法比之前的连 WiFi 时的速度还快了不少。
最近这两天不是一直在玩《使命召唤》嘛,昨晚还和小伙伴们开黑,玩网游的话一定得保证网速稳定,大家可以试试看用这种方式连接上网,速度还是非常给力的。
结语