win10 排查curl: (7) Failed to connect to localhost port xx after 0 ms: Couldn’t connect to server
产生问题环境
windows 10 下 通过 wsl 安装的 ubuntu 24.04
ubuntu curl -v http://localhost:8080/hello 出现的问题
lutong@CHINAMI-JD614UJ:~$ curl -v http://localhost:8080/hello
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8080...
* connect to ::1 port 8080 from ::1 port 48296 failed: Connection refused
* Trying 127.0.0.1:8080...
* connect to 127.0.0.1 port 8080 from 127.0.0.1 port 56166 failed: Connection refused
* Failed to connect to localhost port 8080 after 5 ms: Couldn't connect to server
* Closing connection
curl: (7) Failed to connect to localhost port 8080 after 5 ms: Couldn't connect to server
首先浏览器和 windows cmd curl 都是能访问通的
浏览器访问正常
windows cmd curl 都是能访问通的
思路1 端口是否被占用 sudo netstat -tunlp | grep 8080
lutong@CHINAMI-JD614UJ:~$ sudo netstat -tunlp | grep 8080
[sudo] password for lutong:
lutong@CHINAMI-JD614UJ:~$ sudo netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.54:53 0.0.0.0:* LISTEN 135/systemd-resolve
tcp 0 0 127.0.0.1:6443 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 135/systemd-resolve
tcp6 0 0 :::6379 :::* LISTEN -
tcp6 0 0 :::13316 :::* LISTEN -
udp 0 0 127.0.0.54:53 0.0.0.0:* 135/systemd-resolve
udp 0 0 127.0.0.53:53 0.0.0.0:* 135/systemd-resolve
udp 0 0 127.0.0.1:323 0.0.0.0:* -
udp6 0 0 ::1:323 :::* -
lutong@CHINAMI-JD614UJ:~$ sudo netstat -tunlp | grep 8080
lutong@CHINAMI-JD614UJ:~$
没看到8080 端口被占用的信息,不是端口的问题
思路2 防火墙没有开放8080 端口不能访问
1.首先windows 防火墙 控制面板\系统和安全\Windows Defender 防火墙 我尝试了开启和关闭 ,我用浏览器直接访问 和cmd curl 访问直接就能访问 通过,和 这个防火墙没关系
2. ubuntu ufw 防火墙
lutong@CHINAMI-JD614UJ:~$ sudo ufw status
Status: inactive
Status: inactive 防火墙没有启动
#开启防火墙
lutong@CHINAMI-JD614UJ:~$ sudo ufw enable
[sudo] password for lutong:
Firewall is active and enabled on system startup
#重启防火墙
lutong@CHINAMI-JD614UJ:~$ sudo ufw reload
Firewall reloaded