Ubuntu Dektopの開いているポートはシステムの外部からアクセスできません。

Ubuntu Dektopの開いているポートはシステムの外部からアクセスできません。

私はUbuntu Dektopコンピュータでポート9591を開くために0 0.0.0.0: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      -

localhostと同様に、カールコールに:9591 / apiを使用すると、127.0.0.1がシステム内でうまく機能します。 IPアドレスを使用しようとしても、コンピュータ内ではカールがうまく機能します。

UbuntuデスクトップコンピュータをホストするSSHもネットワーク上でうまく機能します。

$ 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

おすすめ記事