如何排查并修复Windows环境下本地Python Web服务器无法被同网段设备访问的问题
Got it, let’s walk through how to get your WSL Python server accessible from your mobile device again. You’ve already tried some basic steps, so let’s dig into more targeted troubleshooting:
First off, the default python3 -m http.server command might be binding only to WSL’s loopback address (127.0.0.1) instead of all available interfaces (0.0.0.0). Even if it worked before, WSL network changes or Python updates could have altered this behavior.
- Restart your server with explicit binding to all interfaces:
python3 -m http.server 8000 --bind 0.0.0.0 - Verify the binding in WSL by running:
You should seenetstat -tulpn | grep 80000.0.0.0:8000in the output—if it shows127.0.0.1:8000, that’s why external devices can’t reach it.
WSL uses NAT mode by default, which means it has its own internal IP address. Windows usually handles port forwarding automatically, but this can break unexpectedly.
- First, get your WSL internal IP:
You’ll get something likehostname -I172.17.0.2. Test accessinghttp://<WSL_IP>:8000from your Windows machine—if this works but your mobile device can’t reach your Windows IP, port forwarding is the issue. - Manually add a port forwarding rule in Windows PowerShell (run as administrator):
# Replace PORT with your server port (e.g., 8000) and WSL_IP with the address you got earlier netsh interface portproxy add v4tov4 listenport=PORT listenaddress=0.0.0.0 connectport=PORT connectaddress=WSL_IP - Verify the rule exists:
netsh interface portproxy show all
You tried toggling firewall protection, but let’s create a precise rule for your server:
- Open Windows Defender Firewall > Advanced Settings > Inbound Rules > New Rule
- Select Port → Next → Enter your server port (e.g., 8000) and choose TCP → Next
- Select Allow the connection → Check both Private and Public (since your Wi-Fi might be misclassified) → Next
- Name the rule (e.g., "WSL Python Static Server") → Finish
- Also, double-check for third-party firewall/antivirus software (like McAfee, 360 Security) — these often override Windows Firewall rules. Temporarily disable them to test.
Sometimes the issue isn’t with your server or firewall, but with network-level restrictions:
- On your mobile device, ping your Windows machine’s local IP (e.g.,
192.168.1.12). If the ping fails:- Ensure both devices are on the same Wi-Fi network (2.4GHz and 5GHz bands might be treated as separate subnets—stick to one).
- Check your router settings for AP Isolation (or Client Isolation) — this feature blocks devices on the same network from communicating with each other. Turn it off if enabled.
If all else fails, WSL’s network components might be corrupted:
- Close all WSL terminals, then run this in Windows PowerShell (as administrator):
wsl --shutdown - Restart WSL, launch your server again, and test connectivity.
- For a more drastic reset (note: this will erase all WSL data, so back up first):
wsl --reset
内容的提问来源于stack exchange,提问作者Nagev

