How can I access a Termux localhost server from my PC?
Asked by
~13 stitches loose
I'm running a server on my Android phone through Termux. It works when I open it using localhost on the phone, but I can't reach it from my PC. I tried using the phone's IP address and binding the server to 0.0.0.0, but neither worked. 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
If you only need temporary access, use a tunnel service such as ngrok. It forwards a public or private endpoint to the Termux server, avoiding the hotspotโs routing restrictions. For a local-only solution, SSH port forwarding can also expose the phoneโs service to the PC, provided you have an SSH connection between them.
Reply to this answer
First, make sure the server is actually listening on the phoneโs network interface, not only on 127.0.0.1. Binding to 0.0.0.0 is usually correct, then find the phoneโs hotspot-facing IP with `ip addr` and connect to that address and the server port. You may also need to check Android or Termux firewall restrictions. Some phone hotspots isolate connected clients or prevent the PC from routing back to the phone, so this may fail even when the server is configured correctly.
Reply to this answer
The hotspot setup is probably the key issue. Depending on the phone and carrier, devices connected through its hotspot may not be able to initiate connections back to the phone itself. Check both devicesโ IP addresses and whether they are on a usable local network. If the hotspot blocks this traffic, connect both devices to the same Wi-Fi router instead, or create a private link with a tool such as Tailscale or WireGuard and access the server through that linkโs address.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Giddy: Also remember that localhost means 127.0.0.1 or ::1 on the device where the browser or client is running. It never refers to another device. The PC must use the phoneโs reachable network IP instead.