简体   繁体   中英

Opening port for Postgresql

I've been trying to make Postgres available over the network but so far have been unable to do so.

According to netstat, postgres is listening on the right port:

#netstat -anltp | grep 5432
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      2385/postgres   

But when I try to nmap from another device, the port appears to be closed.

#nmap -p 5432 marvin
Starting Nmap 6.40 ( http://nmap.org ) at 2014-10-31 10:31 CET
Nmap scan report for marvin (*.*.*.*)
Host is up (0.00048s latency).
rDNS record for *.*.*.*: marvin.*.*
PORT     STATE  SERVICE
5432/tcp closed postgresql

My guess is, it has to do something with the fact that I'm using a hostname instead of an IP, but since the IP changes here every so often, I'd rather use the hostname.

I've already set listen_addresses = '*', which was the solution to another similar problem I've found here, but to no avail. I've also experimented with different settings in the pg_hba.conf but the port remained closed.

host    all     all     .jarvis         trust
host    all     all     jarvis         trust
host    all     all     0.0.0.0/24      trust

I've also used several examples I've found for my iptables, but no luck there either.

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:postgresqlflags: FIN,SYN,RST,ACK/SYN
ACCEPT     tcp  --  anywhere             Marvin               tcp spts:1024:65535 dpt:postgresql state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:postgresql

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

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

And lastly, I've tried to connect via telnet, no luck there either

telnet marvin 5432
Trying *.*.*.*...
telnet: Unable to connect to remote host: Connection refusedo connect to the port 

Yet, there are no issues on 22.

telnet marvin 22
Trying *.*.*.*...
Connected to marvin.*.*.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.0p1 Debian-3ubuntu1

Can anyone tell me if there's a setting somewhere I misinterpreted or of its an issue with using hostnames?

Look at your netstat output again. You are only listening on localhost (127.0.0.1). Check your config file and restart PostgreSQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM