WSL2 Network Settings and Configuration Guide

To configure WSL2 networking, edit %UserProfile%\.wslconfig on Windows. On Windows 11 22H2 or later, set networkingMode=mirrored under [wsl2] to share the Windows network interfaces, get LAN access and use localhost in both directions. Run wsl --shutdown to apply it. On Windows 10, keep the default NAT mode and forward ports with netsh.
Network configuration in WSL2 makes or breaks your development workflow. Below we set up and fine-tune the network settings that matter.
Short version
# %UserProfile%\.wslconfig (Windows 11 22H2 or later)
[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=trueSave the file, run wsl --shutdown in PowerShell, and start your distro again.
Table of Contents
- Short version
- Understanding WSL2's Network Setup
- Getting Started with Basic Settings
- Setting Up a Fixed IP
- Opening Ports and Access
- Fixing Common Network Issues
- DNS Problems
- Working Behind a Proxy
- Making It Faster
- Memory Settings
- Network Speed
- Fixing Network Problems
- Working with Development Tools
- Keeping Things Secure
- FAQ
- How do I enable mirrored networking in WSL2?
- Can WSL2 get an IP address from my LAN's DHCP server?
- How do I access a WSL2 service from another computer on my network?
- Why don't my .wslconfig changes take effect?
- Key Tips
Understanding WSL2’s Network Setup
WSL2 works differently from the original WSL. It runs a real Linux kernel in a lightweight VM and uses Hyper-V for networking. This means better compatibility but also some unique challenges.
By default WSL2 uses NAT mode: the VM gets its own private IP address behind a virtual NAT on your Windows host. The networkingMode key in .wslconfig accepts nat (the default), mirrored, none and consomme. The old bridged mode is deprecated since WSL 2.4.5. Mirrored mode copies your Windows network interfaces into Linux and adds IPv6 support, better VPN compatibility, multicast and direct LAN access.
Getting Started with Basic Settings
First, check your current network setup:
ip addr showYou’ll see two main interfaces:
- eth0: Your primary network connection
- lo: The local loopback
In mirrored mode you see copies of your Windows adapters instead. From PowerShell, wsl hostname -I prints the IP address of your default distro.
Setting Up a Fixed IP
WSL2 has no setting for a static IP in NAT mode. WSL assigns the VM address itself, and it can change after wsl --shutdown or a reboot. Older guides, including an earlier version of this one, edited netplan files inside the distro, but that does not give you a stable address.
Use one of these options instead:
- Connect from Windows to
localhost.localhostForwarding=trueis the default in NAT mode, so a server listening in WSL2 is reachable atlocalhost:porton Windows. - Switch to mirrored mode. WSL then uses the same IP addresses as Windows, so other devices reach WSL services at your Windows IP. If your router gives Windows a fixed DHCP lease, WSL gets it too.
- Look up the current address when you need it with
wsl hostname -Iand script around it.
Opening Ports and Access
In NAT mode, you need port forwarding to reach WSL2 services from other machines. Open PowerShell as admin:
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=(wsl hostname -I)And set up the firewall:
New-NetFirewallRule -DisplayName "WSL2 Port 3000" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 3000The portproxy rule points at the WSL IP from the moment you created it. Run the command again after the WSL IP changes.
In mirrored mode you don’t need portproxy. Bind your app to 0.0.0.0 and allow the port through the Hyper-V firewall, which filters WSL traffic by default on Windows 11 22H2 or later with WSL 2.0.9 or later:
New-NetFirewallHyperVRule -Name "WSL2-3000" -DisplayName "WSL2 Port 3000" -Direction Inbound -VMCreatorId '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -Protocol TCP -LocalPorts 3000Fixing Common Network Issues
DNS Problems
On Windows 11 22H2 or later, dnsTunneling is on by default and answers DNS requests from WSL through Windows. That fixes most VPN-related DNS failures. If websites still won’t load, stop WSL from generating its own resolver file. Edit /etc/wsl.conf inside the distro:
sudo nano /etc/wsl.confAdd these lines:
[network]
generateResolvConf = falseRun wsl --shutdown in PowerShell, start the distro again, and replace the resolver file:
sudo rm /etc/resolv.conf
sudo nano /etc/resolv.confAdd these DNS servers:
nameserver 8.8.8.8
nameserver 8.8.4.4Keep WSL2 from changing it:
sudo chattr +i /etc/resolv.confWorking Behind a Proxy
On Windows 11 22H2 or later, autoProxy=true under [wsl2] in .wslconfig makes WSL use the HTTP proxy configured in Windows. It is on by default. If you need a different proxy, or you are on Windows 10, add it to your shell config (~/.bashrc or ~/.zshrc):
export HTTP_PROXY="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"
export NO_PROXY="localhost,127.0.0.1"Making It Faster
Memory Settings
Edit %UserProfile%/.wslconfig in Windows:
[wsl2]
memory=8GB
processors=4
swap=2GB
localhostForwarding=truelocalhostForwarding is ignored when networkingMode=mirrored, because mirrored mode shares localhost with Windows anyway. Run wsl --shutdown after every change to .wslconfig.
Network Speed
Update /etc/sysctl.conf with:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15Load the new values with sudo sysctl -p. These settings tune TCP timeouts and keepalives, which helps with long-lived connections more than with raw throughput.
Fixing Network Problems
When things go wrong:
- Restart WSL2 from PowerShell, wait about 8 seconds, then start it again:
wsl --shutdown
wsl- Update WSL, since many networking fixes ship in WSL releases:
wsl --update- Check host networking (NAT mode, PowerShell as admin). The adapter is called
vEthernet (WSL)orvEthernet (WSL (Hyper-V firewall))depending on your version, so the filter matches both:
Get-NetIPInterface | Where-Object { $_.InterfaceAlias -like 'vEthernet (WSL*' } | Set-NetIPInterface -Forwarding EnabledWorking with Development Tools
For VS Code, update your settings:
{
"remote.WSL.fileWatcher.polling": true
}File watcher polling mainly fixes rename errors on WSL 1. It costs performance on large workspaces, so leave it off on WSL2 unless file changes go unnoticed.
Keeping Things Secure
Set up firewalls in both systems:
In WSL2:
sudo ufw enable
sudo ufw allow 3000In Windows:
New-NetFirewallRule -DisplayName "WSL2 Inbound" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 3000On Windows 11 22H2 or later, keep firewall=true in .wslconfig so Windows Firewall and Hyper-V firewall rules also filter WSL traffic. In mirrored mode, open ports with New-NetFirewallHyperVRule as shown above.
FAQ
How do I enable mirrored networking in WSL2?
Add networkingMode=mirrored under [wsl2] in %UserProfile%\.wslconfig, then run wsl --shutdown and start your distro again. Mirrored mode needs Windows 11 22H2 or later. You can also change WSL settings in the WSL Settings app from the Start menu.
Can WSL2 get an IP address from my LAN’s DHCP server?
Not in the default NAT mode, where WSL2 sits behind a virtual NAT with its own private address. The old bridged mode did this, but Microsoft marks it as deprecated since WSL 2.4.5. Use mirrored mode instead: WSL shares the Windows network interfaces, so other devices reach WSL services at the Windows IP.
How do I access a WSL2 service from another computer on my network?
In mirrored mode, bind the app to 0.0.0.0 and allow the port with New-NetFirewallHyperVRule. In NAT mode, add a netsh interface portproxy rule on Windows plus a Windows firewall rule for the port. Run the portproxy command again whenever the WSL IP changes.
Why don’t my .wslconfig changes take effect?
WSL reads .wslconfig only when the WSL 2 VM starts. Run wsl --shutdown, check with wsl --list --running that nothing is running, then start your distro again. Also check the section: networkingMode, dnsTunneling, firewall and autoProxy go under [wsl2], while hostAddressLoopback and ignoredPorts go under [experimental].
Key Tips
- Keep your system updated
- Write down your network settings
- Use environment variables for sensitive info
- Watch your network performance
- Keep security in mind
With these settings, your WSL2 network will run smoothly and securely. Remember to test everything thoroughly and adjust settings based on your needs.
One thought on “WSL2 Network Settings and Configuration Guide”
Comments are closed. I keep the discussion here because the answers still help.
More posts
All Linux


Why couldn't they have set it up so the virtual network adapter used by wsl got an address from the LAN DHCP server, just like every other device on the LAN?