我试图build立一个postgres服务器,但我不能通过互联网访问它。 它在我的局域网上工作正常。 服务器只是使用Ubuntu 12.04桌面的桌面计算机。
免责声明 :我不打算永久使用此configuration。 最终,我将通过SSH隧道进行连接,而我正在做的一些事情可能是不安全的,但是现在我只想弄清楚为什么它不起作用。
在我的postgresql.conf文件中,我设置了listen_addresses = '*' 。 为了testing它是不是与我的pg_hba.conf ,我评论了一切,只是用
host all all all trust
防火墙似乎没有任何事情发生 – 确保我安装了gufw,并允许服务器和客户端上的所有传入和传出通信。
当我尝试通过指向服务器的外部IP地址的域名进行连接时,我收到以下消息:
psql: could not connect to server: Connection refused Is the server running on host "<hostname>" (<IP address>) and accepting TCP/IP connections on port 5432?
netstat -an | grep 5432的结果 netstat -an | grep 5432似乎表明postgres确实正在监听所有地址上的连接:
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN tcp6 0 0 :::5432 :::* LISTEN unix 2 [ ACC ] STREAM LISTENING 9771 /var/run/postgresql/.s.PGSQL.5432
一个在pg_hba.conf中的行,例如:
host all all 0.0.0.0/0 md5