1

I have an ADB daemon running on localhost:5037 on my machine. I have a virtual machine running on my machine. Let's call my machine host and the virtual one guest.

The guest VM uses host's interface:

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

to connect to the internet. I need to access the ADB server at my host from inside guest. If I just call 192.168.122.1 from inside guest it does not work because adb on host is bound to localhost:5037, not 192.168.122.1:5037, therefore I need a way to map

192.168.122.1:5037 <-> localhost:5037

on the host machine in a bidirectional way.

If I just add a bridge between everything then it'll mess how my VM works because it depends on this interface to connect to the internet.

How can I create a TCP bridge between these 2 IPs? I found http://tcpreplay.synfin.net/wiki/tcpbridge but it's unclear how it works. Maybe iptables can solve this?

UPDATE:

as recommended in the answer, I used socat and now it works:

#on host machine:
socat tcp-listen:5037,bind=192.168.122.1,reuseaddr,fork tcp:localhost:5037

#on virtual machine:
socat tcp-listen:5037,bind=localhost,reuseaddr,fork tcp:192.168.122.1:5037

1 Answer 1

2

If the ADB demon is really only bound to the loopback interface, then no matter what tricks you use, it will only react to packets coming from host-local applications, because only those are routed via loopback.

So the first thing to do is to look at the ADB demon's configuration, and see if you can't make it drop the binding (then it will react to 192.168.122.1).

The second thing to check is how your VM is configured. Many VMs (you didn't tell us which kind of VM you use) allow the client to use the host interface without being able to access the host. If that is the case, reconfigure your VM, and test that ping 192.168.122.1 etc. works in the client.

If none of this works, the next thing I'd try is to use socat on the host to forward packets, because then it will look like a local application to the ADB demon.

1
  • Thanks, it worked. I edited the question to show the solution Mar 6, 2018 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .