Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been struggling to open the port 5432 for remote PostgreSQL access. Which I installed on a Ubuntu 10.04 desktop machine.

Here is the shell log:

xybrek@ubuntu:~$ sudo ufw allow 5432
[sudo] password for xybrek: 
Skipping adding existing rule
xybrek@ubuntu:~$ sudo ufw allow 5432/tcp
Skipping adding existing rule
xybrek@ubuntu:~$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
5432/tcp                   ALLOW       Anywhere
5433/tcp                   ALLOW       Anywhere
5432                       ALLOW       Anywhere

5432/tcp                   ALLOW OUT   Anywhere

xybrek@ubuntu:~$ sudo nmap localhost -p5432

Starting Nmap 5.00 ( ) at 2013-05-28 17:57 PHT
Warning: Hostname localhost resolves to 2 IPs. Using
Interesting ports on localhost (
5432/tcp closed postgresql

Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds

When I try to connect to the port from another machine its just connection timeout, whereas when I try to connect to other port like 80, 8080 it works. What am I missing?


Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 5432                       ALLOW IN    Anywhere
share|improve this question
1) Try using nmap command with your IP address ...2) please past results of naslookup localhost & your /etc/host file entries – Rishee May 28 '13 at 10:33
You should not do nmap on your localhost address ( That is not what other computers connects to, and usually not what the firewalls lock down. Use 'ip addr' and the use nmap on the external interface address. You should also try that from your other computer you want to connect from to your server. – Anders May 28 '13 at 19:50
up vote 3 down vote accepted

You have allowed OUT only on that port. So its considered closed as ou haven't allowed in. The 5432 rule is ignored as the 5432 OUT takes precedence.

To fix it best delete what you have and add rule again.

List the rules with the following command

sudo ufw status numbered

then delete the rule by the line number

 sudo ufw delete X

Where X is the rule that has the 5432 against it. Repeat to delete other rule as well, make sure you do the status numbered command again to see the new numbers as when you delete one the numbers change

Then add the rule properly with command

sudo ufw allow 5432
share|improve this answer
Ok, so what should I do? How do I fix this? – xybrek May 28 '13 at 11:59
@xybrek answer updated – Meer Borg May 28 '13 at 12:19
I just did this, but still getting Connection timeout on the machine ping'ing the port 5432 – xybrek May 28 '13 at 12:50
@xybrek Is the machine you are connecting FROM also firewalled? – Meer Borg May 28 '13 at 12:53
Its a windows machine, and the firewall is Off, it can Ping the PostgreSQL server on port 80, and 8080, but not in 5432 – xybrek May 28 '13 at 12:57

Have you altered your pg_hba.conf to fit your network environment and the listen_address in the postgresql.conf?

If so, then try the following:

udo ufw allow from <network> to any port 5432

For <network> you have to add something like, fitting your environment.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.