Connection Refused to WSL(Linux) Host - Troubleshooting Guide

Abstract: Resolve WSL2 connection refused errors by binding services to 0.0.0.0 and configuring Windows Firewall rules for the virtual adapter.

Created: 2026-08-08 by

Resolving a connection refused error to your WSL Linux host typically involves verifying that the service is actively listening on the correct interface, ensuring Windows Firewall rules permit inbound traffic, and confirming that the WSL network adapter IP address has not changed. Most issues stem from services binding only to localhost or missing firewall exceptions for the private network profile.

Understanding the WSL2 Network Architecture

WSL2 operates as a lightweight virtual machine rather than a native container. This architectural shift means it utilizes Hyper-V networking, which assigns the Linux instance a dynamic IP address within a NAT (Network Address Translation) environment. Unlike WSL1, where Linux components ran directly on the Windows kernel, WSL2 requires explicit port forwarding or proper network configuration to allow external connections from the Windows host or other devices on your local network. When you attempt to connect to a service running inside WSL2 using localhost, Windows automatically forwards that traffic to the current IP address of the WSL2 VM. However, if the service inside Linux is not bound to all interfaces, or if the firewall blocks the entry point, the connection will be refused. It is crucial to distinguish between connecting from Windows versus connecting from another machine. Connecting from Windows usually works via localhost due to automatic port forwarding. Connecting from another device requires knowing the specific IP address of the WSL2 adapter and ensuring that device can route to it. If you are seeing "Connection Refused," it generally means the TCP handshake reached the target but was rejected by the application or the operating system's security layer, rather than being dropped entirely due to a routing failure. For deeper insights into related networking quirks, see our guide on Troubleshooting SSH WSL Machine: Can't Connect to Localhost.

Step 1: Verify the Service is Listening Correctly

The most common cause of this error is the application inside WSL2 binding strictly to 127.0.0.1 instead of 0.0.0.0. When a service binds to 127.0.0.1, it only accepts connections originating from within the same network stack. Since WSL2 has its own loopback interface, 127.0.0.1 inside Linux does not refer to 127.0.0.1 in Windows. Therefore, external requests forwarded via NAT may be rejected if the service ignores non-loopback addresses. To diagnose this, open your WSL terminal and use the netstat or ss command to check the listen state. Run the following command to see what addresses your service is listening on:
sudo ss -tlnp | grep :PORT_NUMBER
Replace :PORT_NUMBER with the actual port your application uses (e.g., :80 for HTTP or :22 for SSH). Look at the Local Address:Port column. If you see 127.0.0.1:PORT, the service is misconfigured for external access. You must modify your application’s configuration file to bind to 0.0.0.0 or :: (for IPv6). For example, in Nginx, you would change listen 80; to ensure it doesn't restrict to localhost. In Node.js applications, ensure the host parameter is set to '0.0.0.0' when calling app.listen(). After changing the binding, restart the service and test the connection again.

Step 2: Check Windows Firewall Rules

Even if the service is listening correctly, Windows Firewall may block incoming connections. By default, Windows often treats new network adapters as "Public" networks, which have strict inbound blocking rules. The WSL2 virtual Ethernet adapter might be classified incorrectly, causing the firewall to drop packets before they reach the forwarding logic. You can verify the network profile type by opening PowerShell as Administrator and running:
Get-NetConnectionProfile
If the WSL2 adapter shows a NetworkCategory of Public, you should change it to Private to allow trusted local connections. Use the following command, replacing NAME with the name of the WSL adapter (often something like vEthernet (WSL)):
Set-NetConnectionProfile -Name "vEthernet (WSL)" -NetworkCategory Private
Additionally, ensure that an inbound rule exists for the specific port you are trying to access. You can create a rule via the GUI or PowerShell. For PowerShell, run:
New-NetFirewallRule -DisplayName "Allow WSL Port" -Direction Inbound -LocalPort PORT_NUMBER -Protocol TCP -Action Allow
This step is critical because many users assume that since they can ping the WSL IP, the firewall is open. Ping uses ICMP, which might be allowed while TCP ports remain blocked. If you suspect permission issues with system resources, review how we handle WSL Distributions Stopping Computer Starts - Docker Desktop Error: Access Denied.

Step 3: Confirm the WSL2 IP Address

Because WSL2 IPs are dynamic, they can change every time the distribution stops and starts. Relying on a hardcoded IP address from a previous session will lead to connection failures. To find the current IP, run this command inside your WSL terminal:
hostname -I
This returns one or more IP addresses assigned to the VM. Try connecting to this specific IP address from your Windows host using telnet or Test-NetConnection in PowerShell:
Test-NetConnection -ComputerName WSL_IP_ADDRESS -Port PORT_NUMBER
If this fails, the issue is likely within the Linux firewall (iptables/nftables) or the application itself. If it succeeds, the problem is isolated to how you were attempting to connect previously (e.g., using an outdated IP). Note that accessing this IP from outside your local machine requires port forwarding on your physical router, which is beyond the scope of local troubleshooting.

Step 4: Inspect Linux Internal Firewalls

Linux distributions come with their own firewall utilities, such as ufw (Uncomplicated Firewall) or iptables. Even if Windows allows the traffic through, the internal Linux firewall might reject it. Check the status of UFW by running:
sudo ufw status
If the status is active, ensure that the port you need is listed as ALLOWED. If it is not, add a rule:
sudo ufw allow PORT_NUMBER/tcp
For systems using iptables directly, you can list input rules with sudo iptables -L -n. Look for any DROP or REJECT statements affecting your port. If you find restrictive rules, you may need to flush them or adjust the chain policies. Remember that modifying these settings requires root privileges, so always prefix commands with sudo. If you encounter permission errors during these steps, refer to our article on Lost Sudo Privileges in WSL Ubuntu: Re-enabling Sudo Access.

Frequently Asked Questions

Why does localhost work but the IP address does not?

This usually happens because Windows automatically forwards localhost traffic to the WSL2 VM via NAT, bypassing some network checks. Direct IP access goes through the standard network stack, which may be blocked by firewalls or require different binding configurations. Ensure your service binds to 0.0.0.0 to accept direct IP connections.

Can I make the WSL2 IP address static?

WSL2 does not natively support static IP assignment for the virtual adapter. However, you can automate the retrieval of the current IP using scripts or aliases in your bash profile. Alternatively, consider using port forwarding rules in .wslconfig to map specific host ports to container ports consistently.

Does Docker Desktop affect WSL2 networking?

Yes, Docker Desktop integrates deeply with WSL2 and can interfere with network adapters and permissions. If you recently installed Docker and started facing connection issues, check if Docker is monopolizing the network bridge. Reviewing common access denied errors in Docker can help isolate these conflicts.

How do I troubleshoot if the service is running but still refusing connections?

First, verify the process is actually listening on the expected port using netstat or ss. Second, check both Windows and Linux firewalls for blocking rules. Third, ensure the application is not configured to reject connections from remote hosts or specific IP ranges in its config files.

Is it safe to disable the Windows Firewall for WSL?

Disabling the entire Windows Firewall is not recommended due to security risks. Instead, create specific inbound rules for the ports your WSL services use. This allows necessary traffic while keeping the rest of your system protected against unauthorized access attempts.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More