I'm running a local server on my Android phone through Termux. It works when I open it on the phone using localhost, but I can't reach it from my PC, even after trying the phone's IP address and binding the server to 0.0.0.0. The PC is connected to the internet through the phone's mobile hotspot. What's the correct way to make the server accessible from the PC?
3 Answers
`localhost` always refers to the device where the request is made—127.0.0.1 or ::1—so entering localhost on the PC only checks the PC itself. Binding to 0.0.0.0 allows other interfaces to accept connections, but the network still has to route traffic to the phone. A VPN mesh such as Tailscale or a WireGuard connection can give both devices reachable private addresses, after which you can use the phone’s VPN IP and server port.
If you only need temporary access and the hotspot blocks device-to-device traffic, use a tunneling tool such as ngrok or another equivalent. It creates a publicly reachable URL that forwards to the Termux server, though you should protect the service because anyone with that URL may be able to reach it.
First, make sure the server is listening on 0.0.0.0 rather than only 127.0.0.1, and note the port it uses. Then find the phone’s hotspot-side IP address with `ip addr` or `ip route` and connect from the PC using `http://PHONE_IP:PORT`. Also check whether Android’s hotspot uses client isolation or prevents connections from the connected PC back to the phone. If it does, direct access won’t work even with the correct binding.

Another option is an SSH tunnel. For example, forwarding a local PC port to the Termux service lets the PC access it through its own localhost, without exposing the service on the hotspot network.