设置host为0.0.0.0后Flask应用仍无法被同一校园网设备访问
Let's walk through the most likely reasons your Flask app isn't reachable from another laptop on the same campus WiFi, plus actionable fixes for each scenario:
1. Campus WiFi has AP Isolation enabled
This is the most common culprit here. Many campus networks turn on AP (Access Point) Isolation as a security measure—this blocks devices on the same WiFi from communicating directly with each other, which explains why your app works locally but not from another device.
- Test this theory: Switch both your Flask machine and the other laptop to a personal hotspot (like your phone's) instead of campus WiFi. If you can access the app successfully over the hotspot, AP isolation is definitely the issue on the campus network.
- Fix: Reach out to your campus IT support to ask if they can disable isolation for your device, or if there's a wired network alternative you can use (wired connections usually bypass AP isolation).
2. Your local firewall is blocking incoming connections
Even though you've bound your app to 0.0.0.0 (which is correct for allowing external access), your machine's firewall might be refusing connections to port 3000 from other devices.
For Windows:
- Open Windows Defender Firewall > Allow an app or feature through Windows Defender Firewall.
- Click Change settings, then look for your Python executable or the Flask app in the list.
- Check both Private and Public boxes (match the network type of your campus WiFi).
- If you don't see it, click Allow another app... and browse to your Python installation's
python.exefile.
For Linux (Ubuntu/Debian):
- Run this command to allow incoming TCP traffic on port 3000:
sudo ufw allow 3000/tcp
For macOS:
- Open System Preferences > Security & Privacy > Firewall > Firewall Options.
- Click the + button, add your Python app, and set it to Allow incoming connections.
- Alternatively, run this in Terminal to temporarily open the port:
sudo pfctl -e echo "pass in proto tcp from any to any port 3000" | sudo pfctl -f -
3. Double-check your local IP address
Make sure the IP you're using (10.10.228.169) is actually the correct internal IP of your Flask machine:
- On Windows: Run
ipconfigin Command Prompt, look for the "IPv4 Address" under your WiFi adapter. - On Linux/macOS: Run
ip addr(Linux) orifconfig(macOS) and find theinetaddress for your WiFi interface.
If the IP doesn't match, update the address you use to access the app from the other laptop.
4. Campus network restricts non-standard ports
Some campus networks block access to non-standard ports like 3000. Try switching to a more common port like 80 or 8080:
- Modify your Flask code:
if __name__ == '__main__': app.run(host='0.0.0.0', port=80) # Use port 80 instead - Note: Port 80 is a privileged port, so you'll need to run the script with admin/root permissions (e.g.,
sudo python3 your_script.pyon Linux/macOS, or run Command Prompt as Administrator on Windows). - Then try accessing
10.10.228.169(no port needed, since 80 is the default HTTP port) from the other laptop.
内容的提问来源于stack exchange,提问作者fahadh4ilyas




