cannot access remotly to postgres using psql

August 5, 2014 1.6k views

I am trying to access to postgresql remotly using psql. Can it be that a firewall is blocking postgresql default port 5432 ?

I did the following modification in pg_hba.conf

host    all             all             80.240.129.47/24        trust

and allowed everyone to listen in postgresql.conf

listen_addresses='*'

I do not know, what still is missing to make in run?

When starting nmap from a different host the port of postgres is not shown.

any idea??

Markus

3 Answers

If you have listen_addresses='*' and nmap doesn't show port 5432, it is very likely that your firewall is blocking the port. Have you set up any IP table rules?

Is the IP address 80.240.129.47 the IP of your server or the IP of the machine connecting to it? It should be the address of the client that will connect to the server. Check out the pg_hba.conf docs.

Hi, thanks for your quick response

I assume this. I set up the following rule:

sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             80.240.129.47        tcp spts:1024:65535 dpt:postgresql state NEW,ESTABLISHED

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

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

I hope this is correct.

kind regards

Markus

wait Andrew I got it. it was wrongly set in my pg_hba.conf. 80.240.129.47 is the host of the server and not of the client. My mistake and sorry for bothering.

Markus

Have another answer? Share your knowledge.