打开Postgresql的端口

时间:2014-10-31 09:45:32

标签: postgresql ubuntu networking port iptables

我一直试图通过网络提供Postgres,但到目前为止还没有这样做。

根据netstat的说法,postgres正在收听正确的端口:

#netstat -anltp | grep 5432
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      2385/postgres   

但是当我尝试从另一台设备进行nmap时,端口似乎已关闭。

#nmap -p 5432 marvin
Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-31 10:31 CET
Nmap scan report for marvin (*.*.*.*)
Host is up (0.00048s latency).
rDNS record for *.*.*.*: marvin.*.*
PORT     STATE  SERVICE
5432/tcp closed postgresql

我的猜测是,它必须对我使用主机名而不是IP这一事实做一些事情,但由于IP经常变化,我宁愿使用主机名。

我已经设置了listen_addresses ='*',这是我在这里找到的另一个类似问题的解决方案,但无济于事。我还尝试了pg_hba.conf中的不同设置,但端口仍然关闭。

host    all     all     .jarvis         trust
host    all     all     jarvis         trust
host    all     all     0.0.0.0/24      trust

我也使用了我为iptables找到的几个例子,但也没有运气。

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:postgresqlflags: FIN,SYN,RST,ACK/SYN
ACCEPT     tcp  --  anywhere             Marvin               tcp spts:1024:65535 dpt:postgresql state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:postgresql

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  Marvin               anywhere             tcp spt:postgresql dpts:1024:65535 state ESTABLISHED

最后,我试图通过telnet连接,没有运气

telnet marvin 5432
Trying *.*.*.*...
telnet: Unable to connect to remote host: Connection refusedo connect to the port 

然而,22日没有问题。

telnet marvin 22
Trying *.*.*.*...
Connected to marvin.*.*.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.0p1 Debian-3ubuntu1

有人可以告诉我,如果某个地方有错误解释的设置或使用主机名的问题吗?

1 个答案:

答案 0 :(得分:3)

再次查看您的netstat输出。您只是在侦听localhost(127.0.0.1)。检查配置文件并重新启动PostgreSQL。