Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure adb to listen on specific network interface?

My Android device has two network interfaces, one "public" and one "private". How to configure ADB (the Android Debug Bridge) to only listen on the "private" interface? I know there is service.adb.tcp.port prop, and it works. But an attempt to set service.adb.tcp.ip does not seem to have any effect...

like image 838
amkhlv Avatar asked Oct 24 '25 08:10

amkhlv


1 Answers

adbd listens on all interfaces and it cannot be configured right now, unfortunately.

Socket is created in adb/daemon/main.cpp by calling setup_port with the port defined in the property "service.adb.tcp.port". The function setup_port is defined here, which calls local_init defined here, which basically calls server_socket_thread (defined here). server_socket_thread calls network_inaddr_any_server until it succeeds.

The socket is finally created in the function network_inaddr_any_server, defined there. We can see that the address is hardcoded to zero, which means that it listens on all interfaces.

If you have a rooted device, it should be possible to add an iptables rule denying the port on the public interface. There are apps in the Play Store which install iptables. The rule would be something like

iptables -A INPUT -i eth1 -p tcp --dport 5555 -j DROP

where eth1 is the public interface.

Or, you could also try to edit the function network_inaddr_any_server, compile adbd and replace it on your device, this requires root as well.

like image 193
Nicolas Dusart Avatar answered Oct 27 '25 00:10

Nicolas Dusart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!