cannot access remotly to postgres using psql

Posted August 5, 2014 3.2k 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           trust

and allowed everyone to listen in postgresql.conf


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??


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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 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           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  --        anywhere             tcp spt:postgresql dpts:1024:65535 state ESTABLISHED

I hope this is correct.

kind regards


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