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%\\.wslconfigThen 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.
- In WSL, run
sudo visudo.
- Add this line at the end:
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service ssh start- Make sure
openssh-serveris installed and WSL SSH listens on2222to 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:- Wake trigger: The Mac first connects to
win-hostto execute a remote command.
- Cold start: Windows receives
wsl ...and starts the WSL instance if it isn’t running.
- Start sshd:
sudo service ssh startruns silently thanks toNOPASSWD.
- Bridge traffic:
ncforwards your SSH connection to WSL’s2222.
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)
- 作者:airouter.me
- 链接:https://airouter.me/en/article/mirrore-mode-mac-to-wsl2
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。