How can I access a Termux server from my PC over a phone hotspot?
Asked by
circuit.path
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
`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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
cue+the lights!: 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.