UFW 端口打开但连接仍然被拒绝

UFW 端口打开但连接仍然被拒绝

我正在运行 mongodb,我想从外部机器访问它

ufw status 的输出

Status: active

To                         Action      From
--                         ------      ----
80                         ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
27017                      ALLOW       Anywhere
80 (v6)                    ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)
27017 (v6)                 ALLOW       Anywhere (v6)

telnet 27017 的输出

Connecting To <ip>...Could not open connection to the host, on port 27017: Connect failed

netstat -tulpn 的输出

Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      
tcp        0      0 0.0.0.0:433             0.0.0.0:*               LISTEN      
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      

sudo systemctl status mongod

 * mongod.service - High-performance, schema-free document-oriented database
  Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
  Active: active (running) since Tue 2019-01-15 07:20:51 CET; 51min ago
  Docs: https://docs.mongodb.org/manual

我尝试过重新安装 mongo,重新启动 ufw 等...我做错了什么?

答案1

我猜 ufw 没有问题,但是 netstat 显示 127.0.0.1:27017,如果你想从外部访问端口 27017,这是不正确的。你必须将 MongoDB 配置从 更改为bindIp: 127.0.0.1bindIp: 0.0.0.0重新启动 mongod.service。

相关内容