ich schlage mich seit ein paar Tagen damit herum, den Port für PostgreSQL (5432) per iptables zu öffnen - leider erfolglos. Auch bin ich aus den vielen Beiträgen hier im Forum nicht schlau geworden, wo ich den Fehler suchen könnte.
Ich arbeite via SSH von einem Windows-Client auf Debian Etch. Mit der meiner iptables (s.u.) kann ich problemlos die Ports 80 und 22 öffnen und wieder zumachen. Den Port 5432 möchte ich öffnen, um meine Datenbanken vom lokal auf meinem Client installierten pgAdmin3 aus verwalten zu können. phpPG-Admin möchte ich nicht einsetzen.
Auf dem lokalen Interface funktioniert die Verbindung hervorragend. Postgres läuft als Backend für ein CMS. Der Verbindungsversuch von der Windows-Konsole zu Postgres bzw. pgAdmin3 zu Postgres schlägt jedoch mit der Meldung
Code: Alles auswählen
C:\Program Files\PostgreSQL\8.3\bin>psql -h meine_ip -U postgres -d postgres
psql: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "meine_ip" and accepting
TCP/IP connections on port 5432?
Code: Alles auswählen
-# netstat -anp|grep postgres
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 3298/postgres
tcp6 0 0 :::5432 :::* LISTEN 3298/postgres
udp 0 0 127.0.0.1:33092 127.0.0.1:33092 ESTABLISHED 3298/postgres
unix 2 [ ACC ] STREAM LISTENING 383161 3298/postgres /var/run/postgresql/.s.PGSQL.5432
Code: Alles auswählen
-# pg_ctl restart -w -D $PGDATA -s -m smart
-# ps -efl
...
0 S postgres 3298 1 0 78 0 - 10546 - 11:57 pts/0 00:00:00 /usr/lib/postgresql/8.3/bin/postgres
1 S postgres 3300 3298 0 75 0 - 10546 - 11:57 ? 00:00:00 postgres: writer process
1 S postgres 3301 3298 0 75 0 - 10546 - 11:57 ? 00:00:00 postgres: wal writer process
1 S postgres 3302 3298 0 75 0 - 10613 - 11:57 ? 00:00:00 postgres: autovacuum launcher process
1 S postgres 3303 3298 0 75 0 - 3410 - 11:57 ? 00:00:00 postgres: stats collector process
...
Code: Alles auswählen
-# ls -al /var/run/postgresql/
total 16
drwxrwsr-x 2 postgres postgres 4096 2008-04-21 11:57 .
drwxr-xr-x 19 root root 4096 2008-04-21 11:13 ..
-rw------- 1 postgres postgres 5 2008-04-21 11:57 8.3-main.pid
srwxrwxrwx 1 postgres postgres 0 2008-04-21 11:57 .s.PGSQL.5432
-rw------- 1 postgres postgres 33 2008-04-21 11:57 .s.PGSQL.5432.lock
Code: Alles auswählen
#!/bin/bash
# PATH TO IPTABLES
IPTABLES=/sbin/iptables
# FLUSHING ALL OLD RULES - MAKE SURE, THAT ONLY THE RULES DEFINED HEREAFTER APPLY
$IPTABLES -F
$IPTABLES -X
# ESTABLISHING A NEW FIREWALL CHAIN NAMED 'firewall'.
$IPTABLES -N firewall
# BANNING ALL PACKAGES & CONNECTIONS THAT ARE NOT BEING OPENED EXPLCITELY
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
# ACCEPTING LOOPBACK-TRAFFIC FOR INTERNAL COMMUNICATION (e.g. Apache <=> PostgreSQL)
$IPTABLES -A firewall -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT
# REJECTING INVALID PACKETS
$IPTABLES -A firewall -m state --state INVALID -j DROP
# ACCEPTING PACKETS AND CONNECTIONS, THAT RELATE TO ALREADY EXISTING CONNECTIONS
$IPTABLES -A firewall -m state --state RELATED,ESTABLISHED -j ACCEPT
# Aapache Web Server on port 80
$IPTABLES -A firewall -i eth0 -p tcp --dport 80 -j ACCEPT
$IPTABLES -A OUTPUT -o eth0 -p tcp --sport 80 -j ACCEPT
# SSH access on port 22
$IPTABLES -A firewall -i eth0 -p tcp --dport 22 -j ACCEPT
$IPTABLES -A OUTPUT -o eth0 -p tcp --sport 22 -j ACCEPT
# PostgreSQL access on port 5432
$IPTABLES -A firewall -i eth0 -p tcp --dport 5432 -j ACCEPT
$IPTABLES -A OUTPUT -o eth0 -p tcp --sport 5432 -j ACCEPT
# MySQL access on port 3306
$IPTABLES -A firewall -i eth0 -p tcp --dport 3306 -j ACCEPT
$IPTABLES -A OUTPUT -o eth0 -p tcp --sport 3306 -j ACCEPT
# REJECT ALL TCP-PACKAGES, THAT HAVE NOT BEEN DEALT WITH UNTIL HERE VIA 'tcp-reset'
$IPTABLES -A firewall -p tcp -j REJECT --reject-with tcp-reset
# REJECT ALL OTHER PACKAGES, THAT HAVE NOT BEEN DEALT WITH UNTIL HERE
$IPTABLES -A firewall -j REJECT
# CHANNEL ALL PACKAGES OF THE CHAIN 'INPUT' INTO OUR CHAIN 'firewall'
$IPTABLES -A INPUT -j firewall
Code: Alles auswählen
-# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
firewall all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp spt:www
ACCEPT tcp -- anywhere anywhere tcp spt:ssh
ACCEPT tcp -- anywhere anywhere tcp spt:postgresql
ACCEPT tcp -- anywhere anywhere tcp spt:mysql
Chain firewall (1 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
DROP all -- anywhere anywhere state INVALID
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:www
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:postgresql
ACCEPT tcp -- anywhere anywhere tcp dpt:mysql
REJECT tcp -- anywhere anywhere reject-with tcp-reset
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
Besten Dank,
nilson