Software⏱️ 3 min readπŸ“… 2026-06-11

How to Fix: Windows 10 WSL cURL can't access localhost with error (Failed to connect to localhost port 80: Connection refused)

How to fix WSL cURL connection refused error on Windows 10. Learn how to resolve the issue and make successful cURL requests to localhost in WSL.

Quick Answer: Try running the cURL command from within the WSL terminal, or use the `--proxy` option to bypass the proxy settings.

The issue with WSL on Windows 10 is that it cannot make a cURL request to localhost, resulting in a Connection refused error. This affects users who have created a server or application running on WSL and are trying to access it using cURL.

This error can be frustrating for developers and system administrators who rely on cURL for testing and debugging purposes. In this guide, we will walk you through the root causes of this issue and provide two primary fix methods to resolve the problem.

⚠️ Common Causes

  • The primary reason for this issue is that WSL uses a different networking configuration than the host machine. By default, WSL uses a private IP address (usually 10.0.2.14) to access services running on the host machine, but cURL is configured to use localhost, which is not a valid IP address in WSL.
  • Another possible cause is that the Windows Firewall or other security software on the host machine is blocking the connection from WSL to localhost.

πŸ”§ Proven Troubleshooting Steps

Using the `--proxy` option with cURL

  1. Step 1: Open a new terminal window in WSL and run the following command: curl --proxy http://localhost:8080 -vvv localhost:80/hello_world.html
  2. Step 2: This tells cURL to use a proxy server running on the host machine, which can bypass the private IP address limitation in WSL.
  3. Step 3: Make sure that the `http` port is open and configured correctly on the host machine.

Configuring WSL networking settings

  1. Step 1: Open a new terminal window in Windows and run the following command: wsl --set-ipv4 0.0.0.0
  2. Step 2: This configures WSL to use the host machine's IP address range, which allows cURL to access localhost correctly.
  3. Step 3: Restart the WSL instance or reload the network settings to apply the changes.

✨ Wrapping Up

By following one of these two fix methods, you should be able to resolve the Connection refused error when trying to make a cURL request to localhost in WSL. Remember to restart your WSL instance or reload the network settings after making any changes to ensure that the new configuration takes effect.

Did this fix your problem?

If not, try searching for specific error codes.

πŸ” Search Error Database

❓ Frequently Asked Questions