adb Verified current stable Not installed? System Operations

Adb / Remove Forwarding Rule

Remove Forwarding Rule

Use 'adb forward --remove tcp:{{local_port}}' to delete TCP port forwarding in Android development. Essential for debugging or reconfiguration.

$
Terminal
adb forward --remove tcp:<local_port>

When To Use

Employ 'adb forward --remove tcp:{{local_port}}' during development cycles when multiple services are competing for the same local ports, or after testing proxied connections using adb to ensure that port conflicts do not compromise testing environments or resource allocations on an Android device.

Pro Tip

Port forwarding rules might not clear if the adb server is not properly restarted. Terminate the adb server using 'adb kill-server' and then remove the rule to avoid ghost connections.

Warning

Destructive operation. Confirm the target path and keep a backup before executing.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Removing forward: tcp:8080
Successfully removed forwarding rule for tcp:8080.

Anatomy of Output

Understanding the result

Removing port forwarding rule for tcp:{{local_port}} Operation Initiation

Indicates the command has started executing.

Checking existing forwarding rules. Validation

Verifies the existence of the rule to be removed.

Rule found. Proceeding to removal. Pre-removal Confirmation

Confirms that the specified rule exists.

Rule successfully removed. Success Notification

Indicates successful deletion of the forwarding rule.

Refreshing adb daemon. Daemon Operation

Ensures adb daemon is updated after rule deletion.

Cleanup complete. Finalization

All changes have been applied and verified.

Power User Variants

Optimized versions

adb forward --remove-all

Use when clearing all forwarding rules in bulk is necessary. This directly impacts all active connections.

Troubleshooting

Common pitfalls

error: unknown local port

Solution: Double-check the port number and currently active forwarding rules with 'adb forward --list'.

error: device offline

Solution: Reconnect the device or restart the adb server with 'adb kill-server' and 'adb start-server'.

error: insufficient permissions for device

Solution: Make sure the device's USB debugging is enabled and authorized on the host machine.

Command Breakdown

What each part is doing

adb
Base Command
The executable that performs this operation. Here it runs Adb before the shell applies any redirect operators.
<local_port>
local port
The port value supplied to this command.
--remove
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run the command: adb forward --remove tcp:8080

  2. Step 2

    Verify removal by checking active forwards with: adb forward --list

  3. Step 3

    Ensure the rule tcp:8080 no longer appears in the list.

Alternative Approaches

Comparable commands in other tools

Alternative system operations tools for the same job.