PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Problem mit IPTABLES



Frey
02.03.03, 19:20
Ich hab mit diversen Anleitungen mir ein Iptables script gebastelt.
Es funktioniert auch doch wenn ich einige Zeit nichts mache krieg ich keine Verbindung mehr hin. Die Programme bringen dann die Fehlermeldung "Server nicht gefunden".
Wenn ich die Iptables selber lösche und per default alles erlaube gehts wieder.

Hier das Script:

echo "0" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

echo "1" > /proc/sys/net/ipv4/conf/ppp0/rp_filter
echo "0" > /proc/sys/net/ipv4/conf/ppp0/accept_redirects
echo "0" > /proc/sys/net/ipv4/conf/ppp0/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/ppp0/bootp_relay

# Default Policy: legt fest, das alles gedropt wird, was nicht expliziet zugelassen wird
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

#iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmt

#löschen aller bisherigen regeln
iptables -F
iptables -X


# alles, was über die Loopbackdevice geht, wird zugelassen.
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

iptables -N my_drop
iptables -A my_drop -p ICMP -j LOG --log-prefix " DROP-ICMP "
iptables -A my_drop -p UDP -j LOG --log-prefix " DROP-UDP "
iptables -A my_drop -p TCP -j LOG --log-prefix " DROP-TCP "
iptables -A my_drop -j DROP

#Alles, was zu einer bestehenden Verbindung gehört wird zugelassen

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#Alles was von aussen kommt und zu keiner bestehenden Verbindung gehört wird geblockt.

iptables -A INPUT -m state --state NEW,INVALID -j DROP


################## Regeln ##############################
iptables -A OUTPUT -p ICMP --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p ICMP --icmp-type echo-reply -j ACCEPT
################## HTTP ################################
iptables -A OUTPUT -p TCP --sport 1024:65535 --dport 80 -m state --state NEW -j ACCEPT

################## HTTPS ###############################
iptables -A OUTPUT -p TCP --sport 1024:65535 --dport 443 -m state --state NEW -j ACCEPT

################## FTP #################################
iptables -A OUTPUT -p tcp --sport 1024:65535 --dport 21 -m state --state NEW -j ACCEPT
################## Rest verhindern #####################
iptables -A OUTPUT -p tcp --sport 1024:65535 --dport 110 -m state --state NEW -j ACCEPT

iptables -A INPUT -j my_drop
iptables -A FORWARD -j my_drop
iptables -A OUTPUT -j REJECT


Was stimmt mit dem nun nicht ?

HangLoose
02.03.03, 22:39
was mich wundert ist, das es überhaupt funktioniert, zumindest das *surfen*. du hast nämlich keine regeln für dns definiert.


Gruß HL

Frey
03.03.03, 10:31
Hmm merkwürdig ist auch dass wenn ich alles blocke per default und nichts freigebe trotzdem alles geht :confused:
Ich hab jetzt die Iptables neu installiert und jetzt scheint alles zu richtig zu sein. Ziemlich merkwürdig

HangLoose
03.03.03, 10:44
hi

was für eine distri hast du denn? möglich das noch irgendwelche regeln, von einem distrieigenen *firewall-tool* definiert waren.

mit iptables-save kannst du dir die regeln ausgeben lassen.


Gruß HL

Frey
03.03.03, 10:58
Ich hab Debian und das ist keine eigene Firewall dabei.
Und jetzt gehts ja nach der neu Installation.

HangLoose
03.03.03, 10:59
Und jetzt gehts ja nach der neu Installation.

und das ist ja die hauptsache ;)


Gruß HL

zbled
03.03.03, 11:23
Es ist zwar schön, dass es funktioniert... Aber funktioniert es wirklich? Irgendwie fehlt mir auch der DNS-Eintrag ;-).. könntest Du mal in der Konsole (rein Interessenhalber) ein iptables -L -n eingeben und die Ausgabe posten?

Danke

Frey
03.03.03, 11:30
Hier dns ist jetzt aber dabei

Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
DROP all -- anywhere anywhere state INVALID,NEW
ACCEPT icmp -- anywhere anywhere icmp echo-reply
my_drop all -- anywhere anywhere

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

Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT udp -- anywhere anywhere udp spts:1024:65535 dpt:domain state NEW
ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:domain state NEW
ACCEPT icmp -- anywhere anywhere icmp echo-request
ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:www state NEW
ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:https state NEW
ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:ftp state NEW
ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:pop3 state NEW
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable

Chain my_drop (2 references)
target prot opt source destination
LOG icmp -- anywhere anywhere LOG level warning prefix ` DROP-ICMP '
LOG udp -- anywhere anywhere LOG level warning prefix ` DROP-UDP '
LOG tcp -- anywhere anywhere LOG level warning prefix ` DROP-TCP '
DROP all -- anywhere anywhere

zbled
03.03.03, 11:58
Entweder bin ich blind, oder schon zu blöd :).. ich seh hier keinen port 53 (udp), der für OUTPUT offen wäre. Bist Du Dir sicher, dass Dein Script funktioniert?

übrigens, meine Ausgabe sieht so aus. Du siehst bei OUTPUT schön, dass DNS offen ist. click (http://members.chello.at/marscha/trash/ipt)

HangLoose
03.03.03, 12:01
ACCEPT udp -- anywhere anywhere udp spts:1024:65535 dpt:domain state NEW
ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:domain state NEW

;)

zbled
03.03.03, 12:07
DNS ist port 53, Du hast nur die UDP-"High Ports" freigegeben - hoffentlich steh ich jetzt nicht auf der Leitung, denn ich habe keine Ahnung, was "dpt:domain state NEW" bedeuten soll.

Frey
03.03.03, 12:12
domain heißt 53.
Du kannst bei den den Iptables entweder den port oder ein alias hinschreiben.
Das ist irgendwo in einer Datei festgelegt aber ich weiß nicht mehr wo.

HangLoose
03.03.03, 12:14
*von leitung schubs*

ACCEPT udp -- anywhere anywhere udp spts:1024:65535 dpt:domain state NEW

erlaubt sind (neue) verbindungen von den sourceports 1024:65535 => zielport domain

du kannst für port 53 auch domän schreiben, ist wie bei www, wo du statt dem port 80 auch www schreiben kannst.

edit: zu spät :)

Gruß HL

zbled
03.03.03, 12:25
ah ja ;-) - danke schön