Home > Software design >  How to access localhost running on local centos VM from android phone?
How to access localhost running on local centos VM from android phone?

Time:12-02

I have local VM (OS centos 7) running on my laptop (OS windows). There is a server running on the VM at ip address localhost:xxxx where xxxx is the port number. Now I want to browse to this ip address on my android phone like browsing any other website.

I have tried using adb library and connecting the android phone to the VM via USB cable and following the answered question in that link [https://stackoverflow.com/questions/4779963/how-can-i-access-my-localhost-from-my-android-device] However, my adb version is 1.0.31 which doesn't support the command adb reverse tcp:4000 tcp:4000

Then I tried updating adb version using yum update adb but it states that adb is up to date.

Finally, I thought about installing android studio to install the updated adb , but the VM is already too slow and drains the laptop RAM, hence the android studio will slow the VM furthermore.

CodePudding user response:

Since adb worked fine on my windows laptop I followed those steps to connect the android phone to my local centos VM:

  1. Open puTTy

  2. Create new session and enter IP address of the local VM enter image description here

  3. Under SSH open Tunnels: In the source port: enter the port you want to connect to In the destination: enter IP address of the VM and the port (same as in source port) Press on OPEN enter image description here

4. A terminal will pop up and require you to connect to the local VM using credentials.

At this point you are connected to the local VM and whenever you type in the laptop localhost: port_number you will be redirected to the VM server running on that port

Since android phone is connected to same Wi-Fi as laptop this should work however, I did additional steps to access the server on the phone.

  1. connect phone to laptop using USB cable
  2. Open cmd terminal which is in same path as adb tools
  3. type command adb reverse tcp:xxxx tcp:xxxx where xxxx is the port number, the same as typed in puTTY in earlier steps

At this point whenever I type in localhost: port_number, the android phone now can access the server running on the VM

  • Related