Ubuntu Dektop 上的开放端口无法在机器外访问

Ubuntu Dektop 上的开放端口无法在机器外访问

我在 Ubuntu Dektop 机器上使用 0 0.0.0.0:9591 打开 9591 端口,

$ netstat -tulpn | grep 9591
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:9591            0.0.0.0:*               LISTEN      -

使用 :9591/api 进行卷曲调用,与 localhost 相同,127.0.0.1 在机器内工作正常。即使我尝试使用 IP 地址,curl 在机器内也能正常工作。

ssh 来托管 Ubuntu 桌面计算机在网络中也可以正常工作。

$ curl -vvv http://<IP>:9591/
*   Trying <IP>:9591...
* Connected to <IP> (<IP>) port 9591 (#0)
> GET / HTTP/1.1
> Host: <IP>:9591
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.3 Python/2.7.18
< Date: Fri, 13 Jan 2023 13:50:39 GMT
< Access-Control-Allow-Origin: *
< Content-Length: 58
< Content-Type: application/json
<
* Closing connection 0
request received.

当从网络内的外部机器尝试使用 :9591/api 进行卷曲调用时,它失败如下 -

$  curl -vvv http://<IP>:9591/
*   Trying <IP>...
* TCP_NODELAY set
* connect to <IP> port 9591 failed: Connection timed out
* Failed to connect to <IP> port 9591: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to <IP> port 9591: Connection timed out

请建议。

答案1

使用 ufw,允许端口进行外部访问 -

$ sudo ufw allow 9591

相关内容