Configuring Port Forwarding with WSL2 and IP Passthrough

Abstract: Resolve WSL2 external connectivity issues by configuring Hyper-V IP Passthrough to assign a unique LAN IP address.

Created: 2026-10-25 by

To enable external devices to access services running in WSL2, you must configure Hyper-V IP Passthrough. This feature assigns a unique physical IP address to the WSL2 virtual switch, bypassing NAT and allowing direct connectivity from your local network without manual port forwarding rules.

Understanding the Networking Limitation

By default, WSL2 runs inside a lightweight utility VM managed by Hyper-V. This VM is connected to an internal virtual switch that uses Network Address Translation (NAT). While this allows the Windows host to reach the Linux guest via localhost, it prevents other devices on your LAN from initiating connections to the WSL2 instance. The standard workaround involves complex PowerShell scripts to add netsh port proxy rules, but these are fragile and break when the dynamic IP of the WSL2 interface changes. The robust solution is to use Hyper-V's IP Passthrough mode. This feature, available in Windows 10 version 2004 and later, allows the WSL2 VM to obtain its own IP address directly from your DHCP server or through static configuration. Once configured, the WSL2 instance appears as a distinct device on your network, just like any other computer connected to your router. For more details on how Hyper-V handles network isolation, see Hyper-V: Accessing LAN Devices on Host.

Prerequisites and Verification

Before modifying network settings, ensure your system meets the requirements. You need Windows 10 Build 19041 or higher, or Windows 11. Additionally, you must have administrative privileges to modify Hyper-V settings. First, verify that the WSL2 virtual switch exists. Open PowerShell as Administrator and run:
Get-VMNetworkAdapter -ManagementOS | Select-Object Name, SwitchName
You should see an entry named "vEthernet (WSL)". Note the name of the management OS network adapter, as you will need it for the next steps. If you do not see this adapter, ensure WSL2 is installed and running by executing wsl --update and restarting your machine. It is also helpful to check the current state of your firewall. Ensure that inbound rules for the specific ports you intend to expose (such as HTTP port 80 or HTTPS port 443) are enabled in Windows Defender Firewall. Without these rules, even with correct networking, external requests will be dropped.

Configuring IP Passthrough

The core of this configuration involves enabling passthrough on the WSL2 virtual network adapter. This tells Hyper-V to allow traffic destined for the adapter to pass directly to the WSL2 VM rather than being translated by the host. Run the following command in an elevated PowerShell terminal:
Set-VMNetworkAdapter -ManagementOS -Name "vEthernet (WSL)" -IPPassThroughEnabled $true
If the command executes successfully, it returns no output. To verify the setting, run:
Get-VMNetworkAdapter -ManagementOS -Name "vEthernet (WSL)" | Select-Object IPPassThroughEnabled
The output should show $true. At this stage, the infrastructure is ready, but the WSL2 VM still needs an IP address. Since it is no longer behind NAT, it may not receive one automatically if your router does not support DHCP relay for virtual switches.

Assigning a Static IP to WSL2

With IP passthrough enabled, the most reliable method to ensure consistent connectivity is to assign a static IP address to the WSL2 instance. This avoids issues where the IP changes after every restart. Inside your WSL2 distribution (e.g., Ubuntu), edit the Netplan configuration file. For newer Ubuntu versions using Netplan, locate the file in /etc/netplan/. It might be named 50-cloud-init.yaml or similar. Open the file with a text editor:
sudo nano /etc/netplan/50-cloud-init.yaml
Modify the network configuration to include a static address. Replace the values below with an IP address that falls within your subnet but is outside your DHCP pool to avoid conflicts. For example, if your network is 192.168.1.x and your router is 192.168.1.1, you might choose 192.168.1.150.
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.150/24
      nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
      routes:
        - to: default
          via: 192.168.1.1
After saving the file, apply the changes:
sudo netplan apply
Your WSL2 instance now has a fixed IP address. You can verify it by running ip addr inside WSL2. The interface eth0 should display the new static IP.

Testing External Connectivity

Now that the network is configured, test the connection from another device on your LAN. Open a browser or use curl on a different computer and navigate to http://192.168.1.150:80 (or whatever port your service listens on). If the connection fails, check two things: 1. Firewall: Ensure Windows Firewall is not blocking the incoming connection on the specific port. You may need to create an inbound rule in Windows Defender Firewall Advanced Settings. 2. Service Binding: Ensure your web server inside WSL2 is binding to 0.0.0.0 rather than 127.0.0.1. Binding to localhost only accepts connections from within the VM. For related troubleshooting on WSL2 networking quirks, refer to WSL2: Localhost:8888 Stopped Working - Fixing the Issue.

Frequently Asked Questions

Does IP Passthrough work with Docker Desktop?

No, IP Passthrough is specific to the native WSL2 backend. Docker Desktop uses its own Hyper-V VM and networking stack, which requires separate configuration via Docker's network settings or bridge adapters. Mixing these configurations can lead to unpredictable behavior.

What happens to my WSL2 IP after a reboot?

If you have configured a static IP in Netplan as described above, the address will remain constant across reboots. However, if you rely on DHCP, the address may change. Always prefer static assignment for server-like scenarios to maintain stable remote access.

Can I use IPv6 with this setup?

Yes, WSL2 supports IPv6. You can configure IPv6 addresses in your Netplan YAML file similarly to IPv4. Ensure your router and network infrastructure support IPv6 routing to the WSL2 virtual switch for external devices to reach it.

Why can't I ping my WSL2 IP from the host?

Ping may be blocked by ICMP filtering rules in Windows Firewall or within the Linux kernel itself. By default, some distributions drop ICMP echo requests. Check your firewall rules and ensure ICMP is allowed if you need to troubleshoot connectivity.

Is there a risk of IP conflict?

Yes, if you manually assign an IP that is already in use by another device on your network. Always choose an IP outside your router's DHCP range to prevent conflicts. Consult your router's admin panel to determine the DHCP pool boundaries.

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