PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Iptables und Postfix (bzw DNS)



Morale
04.03.15, 14:18
Neuer Tag neues Problem.

Mein CentOS Server auf der Arbeit hat ein Programm, worüber auch Mails verschickt werden.

Leider gehen die Mails mit meiner iptables Configuration nicht raus.
Das liegt anscheinend am DNS, da auch ein
host -t mx google.de bei aktiver FW nichts bringt.

Der Port dafür ist aber eigentlich (wenn auch nachträglich) freigeschaltet/gegeben.

Hier mein Script:


# 1. Delete all existing rules
iptables -F

# 2. Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

# 3. Allow incoming SSH
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 4. Allow incoming LOCALHOST/HTTP/PLESK/TOMCAT
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 8080 -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -i eth0 -p tcp --dport 8443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 8443 -m state --state ESTABLISHED -j ACCEPT


iptables -A INPUT -p tcp -s localhost --dport 3306 -j ACCEPT

iptables -A INPUT -p tcp -s localhost --dport 8005 -j ACCEPT

iptables -A INPUT -i lo -j ACCEPT

# 5. Allow outgoing SSH
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 6. Allow outgoing HTTP
iptables -A OUTPUT -o eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT

iptables -A OUTPUT -o eth0 -p tcp --dport 8080 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 8080 -m state --state ESTABLISHED -j ACCEPT

iptables -A OUTPUT -o eth0 -p tcp --dport 8443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 8443 -m state --state ESTABLISHED -j ACCEPT


iptables -A OUTPUT -p tcp -d localhost --sport 3306 ! --syn -j ACCEPT

iptables -A OUTPUT -p tcp -d localhost --sport 8005 ! --syn -j ACCEPT

iptables -A OUTPUT -o lo -j ACCEPT


iptables -A INPUT -i eth0 -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -o eth0 -p tcp --dport 53 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 53 -m state --state ESTABLISHED -j ACCEPT


iptables -A OUTPUT -o eth0 -p tcp --dport 25 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT


Ist leider noch etwas gefrickel, aber schön mache ich das, wenn alles läuft.
Also Port 25 ist ja derjeniger welche für die Mails und 53 der für den DNS.

Leider klappt es nicht :(

Bin dankbar für jeden Tipp.

PS:
Ohne FW (Also alles auf accept) keine Probleme.

DrunkenFreak
04.03.15, 14:45
iptables -A OUTPUT -o eth0 -p tcp --dport 53 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 53 -m state --state ESTABLISHED -j ACCEPT

sieht nicht richtig aus. Die zweite Regel ist eigentlich überflüssig, wenn du keinen DNS anbietest, der ersten Regel fehlt ein NEW.

Aber aus dem Kauderwelsch zu finden, ob alles richtig ist, ist schwierig. Wie die aktuelle Einstellung aussieht, weiß man damit auch nicht.

Morale
04.03.15, 15:01
Danke erstmal.

Ja ist leider ein kleiner Verhau.
Hier die iptables -L

Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:http state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:webcache state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:webcache state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:pcsync-https state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:pcsync-https state ESTABLISHED
ACCEPT tcp -- localhost.localdomain anywhere tcp dpt:mysql
ACCEPT tcp -- localhost.localdomain anywhere tcp dpt:mxi
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp spt:ssh state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW,ESTABLISHED
DROP all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
DROP all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:ssh state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:http state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:webcache state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:webcache state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:pcsync-https state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:pcsync-https state ESTABLISHED
ACCEPT tcp -- anywhere localhost.localdomain tcp spt:mysql flags:!FIN,SYN,RST,ACK/SYN
ACCEPT tcp -- anywhere localhost.localdomain tcp spt:mxi flags:!FIN,SYN,RST,ACK/SYN
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:domain state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:submission state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:submission state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:smtp state NEW,ESTABLISHED
DROP all -- anywhere anywhere


Hab es umgestellt von default chain policie DROP auf ACCEPT und nun ganz unten ein

iptables -A OUTPUT -j DROP
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP

hinzugefügt.
Geht dann leider auch nicht, wenn ich aber obriges auskommentiere, dann ja.
Fehlt da einfach noch ein Port?

DrunkenFreak
04.03.15, 15:15
Die INPUT Chain beinhaltet kein DNS für die Antwort des Servers.

Morale
04.03.15, 15:34
Ist jetzt drin, bringt aber nichts.
Weder OUTPUT noch INPUT darf am Ende auf DROP stehen, sonst geht es nicht.

DrunkenFreak
04.03.15, 15:45
Sehe gerade, dass du nur TCP freigibst für DNS. Es muss aber auch UDP sein, wobei UDP alleine in den meisten Fällen ausreicht.

Morale
04.03.15, 15:59
Merci das wars. :)