Windows Subsystem for Linux (WSL) allows you to run Linux distributions directly on Windows 11 without a virtual machine. It’s widely used by developers to build, test, and run web applications, databases, containers, and development servers. Normally, services running inside WSL can be accessed from Windows using localhost, making it easy to interact with web servers, APIs, and other network applications. However, some users encounter the “Localhost connection refused” error when trying to access a service running in WSL, even though the application appears to be running normally.
This issue can occur due to services listening on the wrong network interface, incorrect port configuration, firewall restrictions, WSL networking problems, proxy settings, Hyper-V conflicts, or outdated WSL components. In some cases, the application may only be listening on the Linux loopback interface (127.0.0.1) instead of all network interfaces, preventing Windows from connecting to it.
Fortunately, you can usually resolve the problem by verifying that the service is running, checking the listening address and port, restarting WSL, updating WSL, and reviewing your Windows Firewall settings. In this guide, we’ll walk you through the most effective methods to fix the WSL localhost connection refused issue on Windows 11.
How to Fix WSL Localhost Connection Refused on Windows
Before you begin, verify that the application inside WSL is actually running and listening on the expected port. Also, note whether you’re using WSL 1 or WSL 2, as networking behaves differently between the two versions. Follow the troubleshooting methods below until Windows can successfully connect to the service.
1. Verify That the Service Is Running
A stopped service will naturally refuse incoming connections.
- Open your Linux distribution in WSL.
- Check whether your application is running.
- Restart the service if necessary.
- Try connecting again from Windows.
Ensure there are no startup errors before proceeding.
2. Confirm the Listening Port
Verify that your application is listening on the correct port.
Run the following command inside WSL:
ss -tuln
or
netstat -tuln
Check whether your application’s port appears in the output.
If the port isn’t listed, the service may have failed to start or may be configured incorrectly.
3. Bind the Service to All Network Interfaces
Many applications bind only to 127.0.0.1, preventing external connections.
Update your application’s configuration to listen on:
0.0.0.0
instead of:
127.0.0.1
Restart the application afterward.
Binding to 0.0.0.0 allows Windows to access the service running inside WSL.
4. Restart WSL
Temporary networking glitches can prevent localhost forwarding.
- Open Windows Terminal or Command Prompt.
- Run:
wsl --shutdown
- Launch your Linux distribution again.
- Restart the application.
Restarting WSL resets its virtual networking components.
5. Update WSL
Older WSL versions may contain networking bugs.
- Open Command Prompt as Administrator.
- Run:
wsl --update
- Restart your computer.
- Test the connection again.
Updating WSL installs the latest kernel and networking improvements.
6. Check Windows Firewall
Windows Firewall may be blocking incoming connections.
- Open Windows Defender Firewall.
- Select Allow an app through Windows Defender Firewall.
- Verify that your application is allowed.
- If necessary, create an inbound rule for the required port.
- Test the connection again.
Firewall rules can prevent Windows from accessing services running inside WSL.
7. Test the Service Inside WSL
Before troubleshooting Windows, verify that the application works within Linux.
Inside WSL, run:
curl http://localhost:PORT
Replace PORT with your application’s port number.
If this command fails, the issue lies with the application rather than Windows networking.
8. Check the WSL Version
WSL 1 and WSL 2 use different networking models.
Run:
wsl -l -v
Verify whether your distribution uses Version 1 or Version 2.
Understanding the WSL version helps determine which networking behavior applies.
9. Disable VPN or Proxy Software
VPNs and proxy applications can interfere with localhost routing.
- Disconnect your VPN.
- Disable any proxy configuration.
- Restart WSL.
- Test the connection again.
If the issue disappears, configure your VPN or proxy to allow local traffic.
10. Restart the Hyper-V Networking Services
WSL 2 relies on Hyper-V virtualization.
- Press Windows + R.
- Type services.msc.
- Restart services related to:
- Hyper-V
- Host Network Service
- Restart WSL.
Refreshing these services can resolve virtual networking issues.
11. Repair Corrupted System Files
Damaged Windows components can affect WSL networking.
- Open Command Prompt as Administrator.
- Run:
sfc /scannow
- After the scan completes, run:
DISM /Online /Cleanup-Image /RestoreHealth
- Restart your computer.
These tools repair Windows components used by WSL and virtual networking.
12. Reinstall WSL
If the problem persists, reinstalling WSL may resolve corrupted components.
- Back up your Linux files.
- Unregister the affected distribution if necessary.
- Remove the WSL feature.
- Restart your computer.
- Install WSL again.
- Reinstall your Linux distribution.
A clean WSL installation restores the networking configuration to its default state.
Conclusion
If you’re seeing a “Localhost connection refused” error when accessing services running in WSL, the issue is usually caused by applications listening on the wrong interface, incorrect port configuration, firewall restrictions, outdated WSL components, or virtual networking problems. In most cases, ensuring the service is running, binding it to 0.0.0.0, restarting WSL, and updating the WSL kernel will resolve the issue.
If the problem continues, review your firewall settings, test the service from within WSL, disable VPN or proxy software, and reinstall WSL if necessary. Keeping Windows 11, WSL, and your Linux distribution up to date will help ensure reliable networking between Windows and Linux applications.