English
Appearance
English
Appearance
Expose any service running in WSL — MySQL (3306), Redis (6379), Nginx (80), and more — to colleagues on your LAN, and ensure the services are ready automatically the moment Windows boots: no desktop login, no terminal, no commands to memorize, and no need to reconfigure after every reboot.
The entire setup takes just two steps, and you only need to do it once; after that, on every boot the app brings up Linux, the business services, and port forwarding in sequence.
Before you start, confirm two small things:
networkingMode=mirrored is enabled, port forwarding is not needed; access services directly via the host IP);0.0.0.0 rather than 127.0.0.1 (a common pitfall with MySQL's bind-address and Redis's bind).In the list of installed Linux distributions, click the "Settings" button of the target distribution:
/home/dev/init-services.sh) — so services such as MySQL and Redis start along with Linux;The script must meet these requirements: the file must actually exist, have execute permission (chmod +x), and not use a system-reserved path. The script runs in the background as root; for writing tips and examples, see Auto-start Services in the Distribution. Here is a minimal working example:
#!/bin/bash
# /home/dev/init-services.sh
LOG_FILE="/var/log/wsl-services.log"
echo "$(date): boot hook start" >> "$LOG_FILE"
service mysql start >> "$LOG_FILE" 2>&1
service redis-server start >> "$LOG_FILE" 2>&1
nginx >> "$LOG_FILE" 2>&1
echo "$(date): boot hook done" >> "$LOG_FILE"TIP
The startup script's output is discarded by default, which is why the example writes to a log file. Later, when you want to confirm "whether the service actually started", checking this log is the most direct way.
Go back to "Network" → "Port Forwarding", click "Add Rule", and fill in the "Add Port Forwarding Rule" dialog:
| Field | Example value | Description |
|---|---|---|
| Target Distro | Ubuntu | Which distribution the service actually runs in |
| Listen IP | 0.0.0.0 | Accessible from the LAN; if you enter 127.0.0.1, only the local machine can access it |
| Listen Port | 3306 | The port exposed to the outside on the Windows side |
| Target Port | 3306 | The port the service listens on inside the distribution; may differ from the listen port |
| Add Firewall Rule | Checked | Automatically allow inbound traffic; otherwise LAN connections will be blocked |
Add another 6379 → 6379 rule for Redis. Once the rules are added, click "Apply Rule" on that row, or simply click "Apply all rules" at the bottom (a single elevation applies all the rules).
IMPORTANT
Do not let the listen port conflict with an existing program on Windows. If MySQL is already installed on the Windows host and occupies 3306, you can change the listen port to 13306 while keeping the target port at 3306; LAN users can then connect to 192.168.1.10:13306.
It is recommended to check in the order "local machine → LAN → client"; each step immediately tells you which layer the problem is on.
① Windows host: is the service really running inside WSL
Test-NetConnection 127.0.0.1 -Port 3306If it fails, the problem is inside WSL (service not started, listening only on 127.0.0.1, port mismatch) and has nothing to do with the forwarding rules.
② Another machine on the LAN: are forwarding and the firewall allowing traffic through
Test-NetConnection 192.168.1.10 -Port 3306If it works locally but not from the LAN, it is usually a missing firewall rule, a listen IP other than 0.0.0.0, or the two machines not being on the same subnet.
③ Connect with a real client
mysql -h 192.168.1.10 -P 3306 -u <user> -p
redis-cli -h 192.168.1.10 -p 6379④ View the currently effective forwarding rules
netsh interface portproxy show allExpected output (the address under Connect to ipv4 on the right is the current IP of the WSL distribution and will change after a reboot):
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
0.0.0.0 6379 172.28.78.41 6379
0.0.0.0 3306 172.28.78.41 3306| Symptom | Most likely cause | What to do |
|---|---|---|
| Services are unavailable for a few minutes after boot | On some machines, the WSL VM cold-starts unusually slowly (see #125) | Wait a few minutes; the automation will finish on its own, no manual intervention needed |
| Cannot connect from the LAN after a reboot | The distribution did not start with Windows, so rule synchronization was skipped | Confirm that Step 1 is checked; then click "Apply all rules" again |
| Works locally but not from the LAN | The Listen IP is set to 127.0.0.1, or Add Firewall Rule is not checked | Change the rule to 0.0.0.0 and apply it again |
| Does not work locally either | The service listens only on 127.0.0.1, or it never started | Change the service's listen address; check the startup script's log |
| The rule is applied but still connects to the old address | wsl --shutdown was run manually and the IP changed | Click "Apply all rules" again |
| Port already in use | A program on Windows is using the same listen port | Use netstat -ano | findstr :3306 to locate it, then choose a different listen port |
| Elevation was denied | The Windows authorization prompt was declined when saving settings or applying rules | Save the settings again and allow the authorization |