PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : iptables



apfelmaennchen
15.02.14, 18:52
Ich "sperre" mich aus meinem System aus, wenn ich folgende Regeln ausführe, wobei meine-ip die IP ist, mit der ich mich per ssh auf den server konnektiere.
Ich verstehe den Fehler nicht.


iptables -A THRU -i eth0 -s {meine-ip} -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -j DROP

apfelmaennchen
15.02.14, 18:54
ich würde als Test gerne mich einloggen auf dem Server (ich habe restarted und komme wieder drauf) und sehen, mit welcher IP ich dort ankomme. vielleicht sieht die ja doch anders aus auf dem Zielsystem

mbo
15.02.14, 18:56
Das Accept ist auf der THRU.
Als erstes triffst Du auf die INPUT.
Wie kommst Du von INPUT in die THRU?

apfelmaennchen
15.02.14, 19:02
Oh, entschuldige. Ich habe vorher noch den chain TRU so angelegt

iptables -A INPUT -j THRU

apfelmaennchen
15.02.14, 19:03
also besser ich poste mal die ganze iptables


#!/bin/sh
echo "Start to set up FIREWALL"
echo Accept all
iptables -P INPUT ACCEPT

echo clean the firewall
iptables -F
iptables -X WEB
iptables -X BLACKLIST
iptables -X THRU
iptables -X LOGDROP

echo "create some chains (WEB will be linked to PORT80)"
iptables -N WEB
iptables -N BLACKLIST
iptables -N THRU
iptables -N LOGDROP

echo already accepted packets are accepted right away without passing further on
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

echo allow all inter-machine interaction
iptables -A INPUT -i lo -j ACCEPT

echo now reject some odd-looking packets
iptables -A INPUT -i eth0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --tcp-flags FIN,RST FIN,RST -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --tcp-flags FIN,ACK FIN -j DROP
iptables -A INPUT -i eth0 -p tcp -m tcp --tcp-flags ACK,URG URG -j DROP

echo send all port 80 traffic to chain "WEB"
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 80 -j WEB

echo now proceed with all packets through the blacklist and than to to "whitelist" THRU
iptables -A INPUT -j BLACKLIST
iptables -A INPUT -j THRU
iptables -A INPUT -m limit --limit 1/sec -j LOG --log-prefix "drop_packet" --log-level 7

echo "BLACKLIST (example; when you're listed your're dropped, order does not matter)" ####
iptables -I WEB -s spam.junk.com -j LOGDROP
iptables -I BLACKLIST -s spam2.junk.com -j LOGDROP
################################################## ###################################


echo THRU CHAIN WITHELIST ################################################## ############
echo "allow icmp"
iptables -A THRU -p icmp -m limit --limit 1/sec -m icmp --icmp-type 8 -j ACCEPT
echo "allow imap via SSL"
#iptables -A THRU -i eth0 -p tcp -m tcp --dport 993 -j ACCEPT
echo "allow smtp for mail"
#iptables -A THRU -i eth0 -p tcp -m tcp --dport 25 -j ACCEPT
echo "allow SSH from my host"
iptables -A THRU -i eth0 -s {meine-ip} -p tcp -m tcp --dport 22 -j ACCEPT
echo "allow JIRA"
iptables -A THRU -i eth0 -p tcp -m tcp --dport 8080 -j ACCEPT
echo "allow VOIP TCP"
iptables -A THRU -i eth0 -p tcp -m tcp --dport 5050 -j ACCEPT
iptables -A THRU -i eth0 -p tcp -m tcp --dport 5060 -j ACCEPT
iptables -A THRU -i eth0 -p tcp -m tcp --dport 5061 -j ACCEPT
echo "allow VOIP UDP"
iptables -A THRU -i eth0 -p udp -m udp --dport 5050 -j ACCEPT
iptables -A THRU -i eth0 -p udp -m udp --dport 5060 -j ACCEPT
iptables -A THRU -i eth0 -p udp -m udp --dport 5061 -j ACCEPT
echo "RTP for VOIP, must be one more than the rtp range as defined in /etc/asterisk/rtp.conf"
iptables -A THRU -i eth0 -p udp -m udp --dport 10000:10500 -j ACCEPT
echo "allow http"
iptables -A THRU -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
echo "allow webmin from my machine"
iptables -A THRU -i eth0 -s {meine-ip} -p tcp -m tcp --dport 10000 -j ACCEPT
################################################## ##################################

echo now lock down the INPUT CHAIN for all packets, that have no match yet
iptables -A INPUT -j DROP
iptables -P INPUT DROP

echo LOGDROP CHAIN
iptables -A LOGDROP -p tcp -m tcp --dport 80 -m limit --limit 1/sec -j LOG --log-prefix "web_blacklist" --log-level 7
iptables -A LOGDROP -j REJECT --reject-with icmp-host-prohibited

L00NIX
16.02.14, 09:05
Abgesehen davon, dass ich dieses Splitting in THRU usw. nicht verstehe...

Du springst erst in die BLACKLIST chain, dann aber nicht mehr raus. Somit kommst du nie in die THRU hinein.

Es fehlt also an der richtigen Stelle, d.h. nach der letzten BLACKLIST Regel, ein


iptables -A BLACKLIST -j RETURN

Des Gleiche gilt für die THRU-chain.
Es fehlt also an der richtigen Stelle, d.h. nach der letzten THRU Regel, ein


iptables -A THRU -j RETURN

Danach bist du wieder in der chain INPUT.

Gruß
L00NIX

mbo
16.02.14, 09:08
Von welchem Generator ist das denn?