adb-reverse
Forward ports from Android device to host
TLDR
List all reverse socket connections from emulators and devices
Reverse a TCP port from an emulator or device to localhost
Remove a reverse socket connections from an emulator or device
Remove all reverse socket connections from all emulators and devices
SYNOPSIS
adb reverse tcp:
PARAMETERS
tcp:
The TCP port on the Android device to which connections will be forwarded.
tcp:
The TCP port on the host machine to which connections from the device will be forwarded.
DESCRIPTION
The `adb reverse` command is a powerful tool within the Android Debug Bridge (ADB) that enables reverse port forwarding. Instead of forwarding ports from the host machine to the Android device (as `adb forward` does), `adb reverse` forwards connections from the Android device to the host machine. This is particularly useful when you need the Android device to access services running on your development machine, such as a web server, database, or other development tools, without needing to expose those services publicly or configure complex network settings on the device. This enables the Android application running on the device to easily connect with local services like a development web server without requiring the use of the development machines IP address. It is essential for debugging apps that communicate with local backends.
It provides a straightforward and reliable way to bridge the network gap between a physical Android device or emulator and your local development environment.
CAVEATS
Requires an active ADB connection and the Android device to be in debugging mode. The application running on the device must have the necessary permissions to establish network connections. Multiple `adb reverse` commands can be used to forward different ports, but you can only forward one host port to one device port at a time.
EXAMPLE USAGE
To forward port 8080 on the Android device to port 8000 on the host machine, you would use the command: `adb reverse tcp:8080 tcp:8000`. Then, within the Android application, you can connect to `localhost:8080` to reach the service running on `localhost:8000` on the host machine.
TROUBLESHOOTING
If `adb reverse` is not working as expected, verify that the ADB connection is established, the device is in debugging mode, and there are no firewall rules blocking the connection. Check `adb devices` to ensure your device is listed and authorized.
HISTORY
The `adb reverse` command was introduced to simplify the process of debugging Android applications that interact with services running on the developer's local machine. It allowed to bypass device network limitations and make localhost server accessible. It became indispensable for modern Android development due to the large use of APIs for application development. It's development was closely tied to the development of ADB itself, which has evolved alongside the Android platform.