psql:无法连接到服务器:networking无法访问

我知道这是一个重复的问题,但他们的解决scheme不工作,

我正在做的是,从我的本地ubunut机器连接到远程Postgresql数据库:

psql -h xxxx -U username

但它给错误:

 > psql: could not connect to server: Network is unreachable Is the server running on host "xxxx" and accepting TCP/IP connections on port 5432? 

我做了什么,

我更新了我的pg_hba.confpostgresql.conf文件,并使用下面的命令重新启动服务器:

/etc/init.d/postgresql restart

哪个说好, 重新启动

我做了NMAP检查从本地机器到远程vps显示如下输出:

 root@host:~# nmap xxxx -p 5432 Starting Nmap 5.21 ( http://nmap.org ) at 2015-11-19 15:49 IST Nmap scan report for xxxx Host is up (0.16s latency). PORT STATE SERVICE 5432/tcp filtered postgresql 

输出

 # netstat -plnt |grep 5432 tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 9167/postgres tcp6 0 0 :::5432 :::* LISTEN 9167/postgres 

我怎样才能解决这个问题?

编辑添加iptables -L输出: 在这里输入图像说明

你没有提到你的客户端和数据库服务器之间有防火墙,但是我可以看到你有iptables标签。

如错误消息所示,您需要确保您可以从客户端到达服务器xxxx,特别是TCP端口5432(默认postgresql端口)。

如果您在数据库机器上使用iptables,则可能需要添加如下规则:

 -I INPUT -p tcp --dport 5432 -j ACCEPT 

您可以通过添加-s yyyy来限制源IP地址的此规则。

如果您位于可信networking中,您甚至可以禁用防火墙。