Lazy loaded image
Tech Sharing
2026 Deep Guide: Mirrored Mode + Auto-Activation for Instant Mac → WSL 2 Remote Dev
字数 555阅读时长 2 分钟
2026-5-1
2026-5-7
type
Post
status
Published
date
May 1, 2026
slug
mirrore-mode-mac-to-wsl2
summary
Build a click-to-use workflow for Mac-to-WSL 2 remote development using Windows 11 Mirrored Mode and an SSH wake-on-connect trigger.
tags
Tools
category
Tech Sharing
icon
password
URL
This article combines two key techniques—Mirrored Mode (mirrored networking) and Auto-Activation (wake-on-connect)—to build a “click-to-use” workflow for connecting from a Mac to WSL 2 inside a Windows desktop. This is widely considered the “ultimate setup” because it simplifies the network path and solves the problem that WSL is not always running in the background.

0. Introduction: stop manually starting WSL

When connecting from a Mac to WSL 2 via VS Code, the biggest blockers are usually:
  • Changing IPs and the hassle of port forwarding
  • WSL not always running
If you want a “just click and it works” experience, combining Windows 11 Mirrored Mode with an SSH auto-start trigger is one of the best solutions available today.

1. Why Mirrored Mode changes everything

In the default NAT mode, WSL lives on its own virtual subnet, which forces you to maintain netsh port forwarding rules. Mirrored Mode flips the table:
  • Shared IP: WSL mirrors the host’s network adapters. Accessing the Windows LAN IP becomes equivalent to accessing WSL.
  • No portproxy maintenance: You can completely drop netsh interface portproxy.
How to enable it:
Create or edit .wslconfig under your Windows user profile: %USERPROFILE%\\.wslconfig
Then run wsl --shutdown in PowerShell and restart WSL.

2. The remaining problem: what if WSL isn’t running?

Mirrored Mode solves “how traffic gets there,” but if WSL is stopped, the port is closed. The trick is to use SSH ProxyCommand to “kick” WSL awake right before the connection is established.
Step 1: enable silent SSH start inside WSL
We want Windows to be able to start WSL’s SSH service without prompting for a password.
  1. In WSL, run sudo visudo.
  1. Add this line at the end:
    1. %sudo ALL=(ALL) NOPASSWD: /usr/sbin/service ssh start
  1. Make sure openssh-server is installed and WSL SSH listens on 2222 to avoid colliding with Windows’ SSH.
Step 2: the “magic” config on macOS
Edit ~/.ssh/config on your Mac:

3. What actually happens (logic flow)

When you connect to wsl-dev in VS Code:
  1. Wake trigger: The Mac first connects to win-host to execute a remote command.
  1. Cold start: Windows receives wsl ... and starts the WSL instance if it isn’t running.
  1. Start sshd: sudo service ssh start runs silently thanks to NOPASSWD.
  1. Bridge traffic: nc forwards your SSH connection to WSL’s 2222.

4. Firewall: the last gatekeeper

Because Mirrored Mode exposes WSL ports on your LAN, Windows Firewall may block them by default. Run this once in an Administrator PowerShell:

5. Closing thoughts

With Mirrored Mode + ProxyCommand, you get a self-healing dev environment: you don’t care whether WSL is currently running, and you don’t care about NAT IP churn. From your Mac, it feels like connecting to an always-on Linux box.
This approach is also aligned with Microsoft’s recommendations (see the WSL September 2023 update post): https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/
上一篇
[2026] How to Connect from a Mac to WSL 2 on Windows with VS Code (Remote SSH)
下一篇
Deep Guide: Remote-Develop WSL 2 from a Mac with VS Code (Architecture + Best Practices)