Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 ( http://nmap.org ) at 2013-05-28 17:57 PHT
Warning: Hostname localhost resolves to 2 IPs. Using 127.0.0.1.
Interesting ports on localhost (127.0.0.1):
PORT     STATE  SERVICE
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?

Edit:

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 5432                       ALLOW IN    Anywhere
share|improve this question
1  
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 (127.0.0.1). 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
add comment

2 Answers 2

up vote 2 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
show 2 more comments

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 10.20.1.1/24, fitting your environment.

share|improve this answer
add comment

Your Answer

 
discard

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.