Skip to content

Plug-and-play LAN services on Windows boot ​

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:

  1. WSL uses the default NAT networking mode (if mirrored mode networkingMode=mirrored is enabled, port forwarding is not needed; access services directly via the host IP);
  2. The service you want to share listens on 0.0.0.0 rather than 127.0.0.1 (a common pitfall with MySQL's bind-address and Redis's bind).

1. Two-step configuration ​

Step 1: Start the distribution with Windows and auto-start business services ​

In the list of installed Linux distributions, click the "Settings" button of the target distribution:

  1. Check "Automatically start this distro when Windows start." — bring the Linux environment online together with Windows;
  2. In "Execute a script after the distro start (optional)", enter the absolute path of the startup script (for example, /home/dev/init-services.sh) — so services such as MySQL and Redis start along with Linux;
  3. Click Save.

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:

bash
#!/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.

Step 2: Add port forwarding rules ​

Go back to "Network" → "Port Forwarding", click "Add Rule", and fill in the "Add Port Forwarding Rule" dialog:

FieldExample valueDescription
Target DistroUbuntuWhich distribution the service actually runs in
Listen IP0.0.0.0Accessible from the LAN; if you enter 127.0.0.1, only the local machine can access it
Listen Port3306The port exposed to the outside on the Windows side
Target Port3306The port the service listens on inside the distribution; may differ from the listen port
Add Firewall RuleCheckedAutomatically 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.

Completion checklist ​

  • In the distribution settings, "Automatically start this distro when Windows start." is checked;
  • In the port forwarding list, the rules show as applied;
  • After rebooting Windows, services can still be reached from another machine on the LAN.

2. Verify that it works (optional) ​

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

powershell
Test-NetConnection 127.0.0.1 -Port 3306

If 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

powershell
Test-NetConnection 192.168.1.10 -Port 3306

If 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

bash
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

powershell
netsh interface portproxy show all

Expected 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

3. Common issues at a glance ​

SymptomMost likely causeWhat to do
Services are unavailable for a few minutes after bootOn 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 rebootThe distribution did not start with Windows, so rule synchronization was skippedConfirm that Step 1 is checked; then click "Apply all rules" again
Works locally but not from the LANThe Listen IP is set to 127.0.0.1, or Add Firewall Rule is not checkedChange the rule to 0.0.0.0 and apply it again
Does not work locally eitherThe service listens only on 127.0.0.1, or it never startedChange the service's listen address; check the startup script's log
The rule is applied but still connects to the old addresswsl --shutdown was run manually and the IP changedClick "Apply all rules" again
Port already in useA program on Windows is using the same listen portUse netstat -ano | findstr :3306 to locate it, then choose a different listen port
Elevation was deniedThe Windows authorization prompt was declined when saving settings or applying rulesSave the settings again and allow the authorization