
Ich habe eine Debian-Installation
~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/
wo ich PostgreSQL installiert habe
PostgreSQL 11.3 (Debian 11.3-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
PostgreSQL läuft, aber ich kann es von einem anderen Rechner aus verwenden: Ich habe den 5432-Por über Firewall geöffnet
# firewall-cmd --zone=public --list-ports
8443/tcp 5432/tcp
aber es funktioniert nicht.
Dies lokal
~$ telnet localhost 5432
Trying ::1...
Connected to localhost.
Escape character is '^]'.
das ist von meiner Maschine (auf einem anderen VLAN)
:> telnet 192.168.13.183 5432
Trying 192.168.13.183...
telnet: Unable to connect to remote host: Connection refused
dies ist von einer anderen Maschine (im selben VLAN wie Debian)
telnet 192.168.13.183 5432
Trying 192.168.13.183...
telnet: connect to address 192.168.13.183: Connection refused
Also schalte ich Firewall aus (nur zum Test), aber ich bekomme die gleichen Ergebnisse. Danach habe ich versucht, dasselbe mit iptables zu tun:
iptables -A INPUT -p tcp --dport 5432 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 5432 -m conntrack --ctstate ESTABLISHED -j ACCEPT
Mit den gleichen Ergebnissen. Was übersehe ich hier?
schau dir das einfach an (danke@Thomas):
netstat -tulpan | grep postgres
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 6386/postgres
tcp6 0 0 ::1:5432 :::* LISTEN 6386/postgres
udp6 0 0 ::1:44652 ::1:44652 ESTABLISHED 6386/postgres
lsof -n -i:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 6386 postgres 3u IPv6 72390 0t0 TCP [::1]:postgresql (LISTEN)
postgres 6386 postgres 5u IPv4 72391 0t0 TCP 127.0.0.1:postgresql (LISTEN
Antwort1
postgresql
hört standardmäßig nur auf localhost (127.0.0.1Und::1). Um dieses Verhalten zu ändern, müssen Sie andere Abhöradressen manuell in konfigurieren postgresql.conf
, die sich normalerweise in befinden $PGDATA
.
Um beispielsweise Postgres dazu zu bringen, auch auf der lokalen Adresse 10.0.10.156 zu lauschen, müssten Sie listen_addresses
Folgendes angeben.
listen_addresses = 'localhost, 10.0.10.156'
Um Postgres dazu zu bringen, auf allen Schnittstellen zu lauschen, können Sie auch ein Platzhalterzeichen verwenden.
listen_addresses = '*'
Nach dieser Änderung muss Postgres neu gestartet werden. Ich würde auch empfehlen, zu überprüfen, ob das Ergebnis Ihren Erwartungen entspricht.
Ausgabe lsof
mit einem Postgres, das auf localhost und 10.0.10.156 lauscht.
# lsof -n -i:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 7893 postgres 3u IPv6 55868 0t0 TCP [::1]:postgres (LISTEN)
postgres 7893 postgres 4u IPv4 55869 0t0 TCP 127.0.0.1:postgres (LISTEN)
postgres 7893 postgres 5u IPv4 55870 0t0 TCP 10.0.10.156:postgres (LISTEN)
Ausgabe lsof
mit einem Postgres, das auf allen Schnittstellen lauscht.
# lsof -n -i:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 7527 postgres 3u IPv4 54903 0t0 TCP *:postgres (LISTEN)
postgres 7527 postgres 4u IPv6 54904 0t0 TCP *:postgres (LISTEN)