You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何排查并修复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:

1. Make Sure the Server is Bound to All Network Interfaces

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:
    netstat -tulpn | grep 8000
    
    You should see 0.0.0.0:8000 in the output—if it shows 127.0.0.1:8000, that’s why external devices can’t reach it.
2. Check WSL Network Mode & Port Forwarding

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:
    hostname -I
    
    You’ll get something like 172.17.0.2. Test accessing http://<WSL_IP>:8000 from 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
    
3. Refine Windows Firewall Rules

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.
4. Confirm Cross-Device Network Connectivity

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.
5. Reset the WSL Network Stack

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 06:47:38