How to connect to localhost from your phone via Wi-Fi

Developing web applications or testing server-side solutions often requires quickly testing the interface on a mobile device. Emulating smartphone behavior on a desktop is often insufficient, as actual rendering and network requests may differ. This is precisely where the need arises. connect to localhost, running on a computer using a wireless network.

By default, the local server is only accessible within the host operating system, that is, on the computer itself. Address 127.0.0.1 or localhost is an internal loop that is invisible to other devices on your local network. To ensure that your smartphone, connected to the same router, can "see" the running project, you need to configure a number of network security and routing settings.

In this guide, we'll explore how to turn your PC into a fully-fledged testing server accessible from Android or iOS. We'll cover the nuances of firewall configuration, the specifics of IPv4 and IPv6, and address common issues developers encounter when attempting to access a localhost from a mobile device.

Basic concept of LAN and IP addressing

For a successful connection, both devices—the computer and the smartphone—must be on the same subnet. This means they are connected to the same Wi-Fi router. Your computer acts as the server in this connection, and your phone is the client. The key here is to use the computer's actual IP address on the local network, not the abstract localhost address.

Each device on a local network is assigned a unique address by the router, usually starting with 192.168.x.x or 10.0.x.xThis is the address you'll need to enter into your phone's browser. It's important to understand that the standard port localhost:8080 transforms into 192.168.1.5:8080 (hypothetical example), where the numbers represent a specific machine on the network.

⚠️ Attention: If your computer is connected to a public Wi-Fi network (such as a cafe or airport), sharing may be blocked by your ISP's security policies or your router's settings. Use only trusted home or office networks.

There's also a nuance with protocols. Modern operating systems often prefer IPv6, but many older or specific server configurations only work correctly over IPv4. Make sure your router and network card support the required protocol.

📊 What operating system does your main computer use?
Windows 10/11
macOS
Linux (Ubuntu/Debian)
Other

Calculating the IP address of a computer on a local network

The first practical step is to obtain the exact IP address of your PC. Without this value, the phone simply won't know where to send the request. The procedure for obtaining this information varies depending on the operating system installed on the host.

For Windows users, the fastest way is to use the command line. Launch the console and enter the command ipconfigIn the list that appears, you need to find the active wireless or wired connection and copy the value indicated opposite the line IPv4 address.

C:\Users\User> ipconfig

Wireless LAN adapter Wi-Fi:

IPv4-Address...........: 192.168.1.45

Subnet Mask...........: 255.255.255.0

Default Gateway.........: 192.168.1.1

Owners of macOS and Linux distributions will also need a terminal. Command ifconfig (or ip addr (in newer Linux systems) will provide detailed information about network interfaces. Look for the section corresponding to your Wi-Fi adapter (often called wlan0 or en0), and find the line inet.

Write down or remember this address. This is what we will use to connect. If the address starts with 169.254.x.x, this means that the device was unable to obtain an address from the router's DHCP server, and the connection will not work. In this case, check your Wi-Fi connection.

Configuring a firewall for incoming connections

Even if you know the correct IP address, you may encounter a connection timeout that prevents your access attempt. The most common culprit is the operating system's built-in firewall, which by default blocks all incoming connections from the local network to the developer ports.

In Windows, open Windows Defender Firewall and go to Advanced Settings. There, create a new inbound rule, specifying the specific port (e.g., 3000, 8080, or 5500) on which your local server is running. It's important to allow connections for both the "Private" and "Guest" profiles.

On macOS, the settings are located in System Preferences → Security & Privacy → Firewall. If it's enabled, you'll need to add your server application (such as Node.js, Python, or Docker) to the list of allowed programs or temporarily disable incoming connection blocking for testing.

☑️ Security Setup Checklist

Completed: 0 / 5

⚠️ Attention: Don't disable your firewall completely if you're on a public network. It's best to create an exception only for the specific port you're currently using. This minimizes the risk of attacks from the outside network.

It's also worth checking your antivirus settings. Third-party security solutions (Kaspersky, ESET, Avast) often have their own firewall modules that can ignore Windows system settings and block traffic regardless.

Connecting an Android device to a local server

After setting up the network and security, let's move on to the most interesting part: checking the connection. On your Android device, make sure Wi-Fi is enabled and the phone is connected to the same network as your computer. Open any browser (Chrome, Firefox, Samsung Internet).

In the address bar, enter the computer's IP address obtained earlier, followed by a colon and the port of your server. For example: http://192.168.1.45:3000. Please note that the protocol must be specified explicitly (http://), especially if you are not using the standard 80 port.

If the server is running on localhost or 127.0.0.1, it can only listen on the local interface. In such cases (for example, when using Django or some Node.js configurations), you need to start the server with a flag that allows external connections, usually 0.0.0.0.

# Example of starting a Django server for external access

python manage.py runserver 0.0.0.0:8000

Example of running a React app

npm start (usually already set to 0.0.0.0 in development)

Modern versions of Android can block unencrypted HTTP traffic (Cleartext Traffic) in apps, but this is usually enabled by default in the browser. If you're developing a native app, you'll need to add an exception in network_security_config.xml.

Features of connecting iOS devices (iPhone/iPad)

The Apple ecosystem has its own security features that can hinder connection. As with Android, the first requirement is being on the same Wi-Fi network. However, iOS may require you to verify your computer's trust or certificate if you're using HTTPS.

When attempting to open a local URL in Safari on iPhone, the device may warn you that the connection is not secure. This is normal for a development environment. You need to tap "Advanced" and confirm the transition to the secure protocol.

Client isolation on routers is important. Some routers, especially guest networks or mesh systems with isolation enabled, prevent devices within the same Wi-Fi network from exchanging data. Check your router's settings.

Parameter Windows PC macOS Linux
IP Team ipconfig ifconfig ip addr
Firewall Windows Defender System Preferences UFW / iptables
Network type Private network Local area network Trusted zone
Network reset netsh int ip reset Network Reset systemctl restart NetworkManager

For developers using Xcode and simulators, address localhost Internally, the simulator connects to the simulator itself, not to the host Mac. To access the server on a Mac, use a special address. host.docker.internal (if in Docker) or real IP of Mac.

Solving common connection problems and errors

Despite the correct setup, you may encounter an error ERR_CONNECTION_TIMED_OUT or ERR_CONNECTION_REFUSEDThe first error most often indicates firewall issues or an invalid IP address. The second indicates that the server is either not running or not listening on the external interface.

Check if your antivirus is blocking the connection. Often, smart firewalls in antivirus programs block incoming connections for unknown applications, even if you've allowed them in Windows. Try temporarily pausing protection.

Problem with dynamic IP

Your computer's IP address may change after rebooting your router. To avoid constant reconfiguration, you can assign the IP address to the MAC address of the network card in the router's DHCP settings.

Also, make sure you're not using a VPN on your computer or phone. A VPN creates a virtual network interface and reroutes traffic, which can cause local network 192.168.x.x may become unavailable to the device connected through the tunnel.

⚠️ Attention: If you're using Docker Desktop, containers are isolated by default. To access a container port from the outside (from a phone), you need to forward it when it starts (flag -p host_port:container_port) and make sure that Docker listens on all interfaces, not just localhost.

Alternative methods: tunneling and USB

If setting up a local network is difficult or IP addresses are constantly changing, tunneling tools can be used. Services like ngrok or localtunnel create a secure tunnel from the internet directly to your localhost by providing a temporary public URL.

This is convenient because your phone can be connected to mobile internet (4G/5G) rather than Wi-Fi and still see your local server. However, connection speed will depend on your upload channel and the intermediary's servers.

# Install and run ngrok on port 3000

npm install -g ngrok

ngrok http 3000

Another reliable method is connecting via a USB cable. Android Debug Bridge (ADB) allows for direct port forwarding. The command adb reverse tcp:3000 tcp:3000 will make it so that requests from the phone to localhost:3000 will be redirected to localhost:3000 on the computer.

In conclusion, the choice of method depends on your needs. Wi-Fi is suitable for quick layout edits, ngrok is suitable for demonstrating to clients without local network access, and USB tunneling is suitable for debugging native applications.

Why can't the phone see the computer, even though they are on the same network?

Most likely, the "AP Isolation" feature is enabled in your router settings. This prevents Wi-Fi devices from communicating with each other. Also, check your network profile in Windows: it should be "Private" and not "Public."

Is it possible to connect to localhost via mobile internet (4G)?

Directly, no, since the mobile network and your home Wi-Fi are on different internet segments. This would require port forwarding on the router (unsafe) or using tunnels like ngrok or Cloudflare Tunnel.

What port should I use for localhost?

The port depends on your server application. Standard web ports are 80 (HTTP) and 443 (HTTPS). Commonly used ports for development are: 3000 (React/Node), 8080 (Java/Tomcat), 5000 (Flask), and 8000 (Django). Make sure your firewall is open for this port.

Is it safe to open localhost ports to everyone?

On a home network with trusted devices, the risk is minimal. However, if you're connected to public Wi-Fi, opening ports could allow attackers on the same network to access your file system or running services. Always check your network profile.