Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adb port forwarding to listen on all interfaces

Tags:

android

adb

I'm trying to redirect/forward a TCP port from the local machine to the device (where I have a server listening on a given port). The command I'm using is the following:

adb forward -a tcp:5555 tcp:5555

However, when I check with netstat I see that adb is only listening on 127.0.0.1. I need adb to listen on any IP not only the local host. Is this possible?

like image 693
rkachach Avatar asked May 14 '19 12:05

rkachach


People also ask

What is adb port forwarding?

I'm developing an Android app as a side project and today I learned about adb forward and adb reverse . Basically, they allow you to forward or reverse traffic to specific ports between an Android device and your development machine.

How start adb with different ports?

Use option -P (Note: Caps P)to start adb server in a specific port. It will list the devices attached to this specific adb server. If the adb server is not running then it will start a new adb server with the given port number.

What is adb reverse?

$ adb reverse --list. Reverse a TCP port from an emulator or device to localhost.

What is the default TCP port on which the adb server listens?

When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server.


Video Answer


1 Answers

After a while looking around this issue I finally found the solution. It seems that for whatever reason adb is not processing the "-a" option (for me it seems like a bug in adb .. but I'm not sure). The alternative, is to start the daemon server and pass this option to it as following:

adb -a nodaemon server start

Once we start the server then the tcp forward now is listening in all the interfaces instead of localhost.

[EDIT]

Some times you may get an error like:

>  could not install smartsocket listener: Address already

This is because there's already an adb server running so you have to kill it before starting the new one.

like image 119
rkachach Avatar answered Oct 21 '22 13:10

rkachach