LinuxCommandLibrary

adb-forward

Forward ports between host and Android device

TLDR

Forward a TCP port to the only connected emulator or device

$ adb forward tcp:[local_port] tcp:[remote_port]
copy

Forward a TCP port to a specific emulator or device (by device ID / [s]erial number)
$ adb -s [device_ID] forward tcp:[local_port] tcp:[remote_port]
copy

List all forwardings
$ adb forward --list
copy

Remove a forwarding rule
$ adb forward --remove tcp:[local_port]
copy

Remove all forwarding rules
$ adb forward --remove-all
copy

SYNOPSIS

adb forward [--list | --kill | --remove local | --no-rebind] [local] [remote]

PARAMETERS

--list
    List all active port forwards.

--kill
    Remove all port forwards.

--remove local
    Remove specific forward by local specifier (e.g., tcp:8080).

--no-rebind
    Forward without rebinding if port already in use.

local
    Host-side specifier: tcp:port, localabstract:name, localreserved:name, local:shellcmd, devicename:name.

remote
    Device-side specifier: tcp:port, localabstract:name, localreserved:name, jdwp:pid.

DESCRIPTION

adb forward is a key subcommand of the Android Debug Bridge (ADB) tool, used to create port forwarding tunnels from the host machine to an Android device or emulator. This allows developers to access services running on the device via localhost ports on the host, ideal for testing web apps, APIs, or debug servers without public exposure.

For instance, forwarding a device's HTTP server on port 8080 to the host's port 8080 enables browsing http://localhost:8080 in a host browser, which proxies to the device. Tunnels remain active until removed, adb restart, or disconnection.

It supports flexible socket specifiers: TCP ports (tcp:port), Unix abstract/reserved sockets (localabstract:name, localreserved:name), shell commands (local:command), device names (devicename:name), or JDWP processes (jdwp:pid for remote only). Use --no-rebind to reuse existing binds. Management options like --list, --remove, and --kill provide control.

Requires USB debugging enabled, authorized device, and adb server running. Essential for mobile development workflows.

CAVEATS

Forwards lost on device reboot, adb restart, or disconnect. Host ports must be free. Some specifiers require device permissions. TCP packet size optional via tcp:port/packetsize. Not for production; use VPNs for secure tunnels.

EXAMPLES

adb forward tcp:8080 tcp:8080
Access device port 8080 via host localhost:8080.
adb forward tcp:5005 jdwp:1234
Forward JDWP debugger.
adb forward --list
adb forward --kill

SPECIFIERS DETAILS

localany:packetsize binds any host port.
localreserved:name for filesystem Unix sockets.
Remote jdwp:pid for app debugging.

HISTORY

Introduced in Android SDK Platform-Tools ~2007 with Android 1.0. Evolved for better socket support; maintained by Google AOSP for developer tools.

SEE ALSO

adb(1), adb reverse, socat(1), nc(1)

Copied to clipboard