Environment
Snapdragon X
WSL2 Ubuntu
NAT Networking
Port Forwarding
Keywords: WSL, mirrored mode, NAT, netsh portproxy, Task Scheduler, autoMemoryReclaim
Are you running WSL2 as a server? I’m running OpenClaw Gateway, Confluence, Jira, SSH, and more on WSL full-time. Let me share my experience escaping port conflict hell in mirrored mode and switching to NAT.
💥 TL;DR
1. If WSL is for server use, NEVER enable autoMemoryReclaim — it shuts down WSL itself when idle
2. NAT + port forwarding is more stable than mirrored mode — In mirrored mode, svchost holds ports and the only fix is wsl --shutdown
Why NAT? — The Pitfall of Mirrored Mode
networkingMode=mirrored is a convenient mode where Windows and WSL share the same network stack. But when you run servers, this happens:
⚠️ Repeated port 19876 conflicts
Even after stopping the OpenClaw Gateway, the Windows-side svchost (WSL port proxy) keeps holding the port. Restarting gives you another gateway instance is already listening error. The only fix? Full shutdown with wsl --shutdown.
In mirrored mode, even when the WSL process ends, the Windows-side proxy doesn’t release the port. Having to completely restart WSL every time is unacceptable for server operations.
Step 1 — Edit .wslconfig
File location: C:\Users\{username}\.wslconfig
The key is to remove these settings:
| Setting | Action | Reason |
|---|---|---|
networkingMode=mirrored |
❌ Remove | Revert to NAT (default) |
dnsTunneling=true |
❌ Remove | Not needed in NAT |
firewall=true |
❌ Remove | Not needed in NAT |
🚨 NEVER use autoMemoryReclaim!
# NEVER use this for server workloads!
autoMemoryReclaim=gradual
With this enabled, WSL reclaims memory when idle and shuts down WSL entirely. Your always-on services will die without warning. Every wsl.exe launch triggers a cold boot, and services get stuck in activating (start-pre) infinite loops.
You might see warnings due to .wslconfig encoding issues. Save as UTF-8 without BOM to fix it:
Restart WSL after editing:
Step 2 — Port Forwarding Setup
In NAT mode, WSL gets its own internal IP. To access it from outside, you need port forwarding from Windows to WSL.
Manual Setup (Admin PowerShell)
Forwarded Ports
| Port | Service | Note |
|---|---|---|
| 19876 | OpenClaw Gateway | WebSocket |
| 19877 | SSH (sshd) | Remote access |
| 5051 | Confluence | Atlassian |
| 8080 | Jira | Atlassian |
Step 3 — Automate with Task Scheduler
In NAT mode, the WSL IP changes on every boot. So I created a script that automatically refreshes port forwarding on each login.
Automation Script
File: C:\Temp\openclaw-portforward.ps1
Register with Task Scheduler
🔑 Key points: Auto-runs 30 seconds after login (waits for WSL boot), runs with admin privileges (required for netsh), log file: C:\Temp\openclaw-portforward.log
🔧 Troubleshooting
When port forwarding rules are empty
After wsl --shutdown, netsh portproxy rules get reset. Just manually trigger the Task Scheduler task:
When the gateway loops in start-pre
If you start a service before WSL is fully booted, it gets stuck in a cold boot loop. Wait long enough and then check the status:
Mirrored vs NAT — Comparison
| Mirrored | NAT + Port Forward | |
|---|---|---|
| Port release after process exit | ❌ svchost holds port | ✅ Clean release |
| Recovery without WSL restart | ❌ Impossible | ✅ Just restart service |
| Setup complexity | ✅ Zero config | ⚠️ Port forwarding needed |
| IP changes on reboot | ✅ Same as host | ⚠️ Yes (script handles it) |
| Server stability | ❌ Problematic | ✅ Stable |
Takeaway
If you’re only using WSL2 for development, mirrored mode is convenient. But if you’re running servers — gateways, databases, web servers, etc. always on — NAT + automated port forwarding is far more stable.
The initial setup is a bit tedious, but once you register it with Task Scheduler, everything is fully automatic from then on. And please, never use autoMemoryReclaim in a server environment. 🙏