bahamutxii
Goto Top

Suche iptables Guru!

Suche einen iptables Guru der in der Lage ist mir bei meinem Script etwas unter die Arme zu greifen. Bitte keine Links zu Howtos oder Büchern posten sowas suche ich nicht googln kann ich selber.....

Content-Key: 156672

Url: https://administrator.de/contentid/156672

Printed on: April 16, 2024 at 13:04 o'clock

Member: Listo
Listo Dec 09, 2010 at 13:50:31 (UTC)
Goto Top
Wobei brauchst Du denn Hilfe???

Gruß
Listo
Member: BahamutXII
BahamutXII Dec 09, 2010 at 13:56:56 (UTC)
Goto Top
Ist ziemlich umfangreich und nicht in ein paar minuten gelöst. soll ich es hier posten oder lieber irgendwo hochladen? Ich poste es einfach mal hier:

VARIABLEN
IPTABLES="/usr/local/sbin/iptables"

##Interfaces

Loopback="lo"
Internal="eth0"
External="eth1"
Internal_Net="192.168.2.0"

##Dienste/Server
DNS_Server=192.168.2.1

##Interne IP Adresse
Int_IP=ifconfig $Internal | grep inet | grep -v inet6 | cut -d : -f 2 | cut -d ' ' -f 1

##Externe IP Adresse
Ext_IP=ifconfig $External | grep inet | grep -v inet6 | cut -d : -f 2 | cut -d ' ' -f 1

##Logging
Log_Level="notice" ##Standart Log Level kern.notice

##Lösche alle Regeln
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD

##Lösche alle Regeln die bisher geladen wurden um eine saubere Regeldefinition
##zu ermöglichen / Flush
iptables -F

##Lösche alle Ketten die erstellt wurden falls vorhanden
iptables -F -t mangle
iptables -t mangle -X
iptables -X


##Setze Default Regeln / HIGHLY RECOMMEND
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP


Spezielle Ketten

##KEEP_STATE um eingehende, ausgehende und bestehende Verbindungen zu managen
iptables -N Keep_State
iptables -F Keep_State

##Verwerfe Pakete die eine "INVALID" Verbindung darstellen
iptables -A Keep_State -m state --state INVALID -j DROP

##Akzeptiere Pakete von einer bestehenden Verbindung
iptables -A Keep_State -m state --state RELATED,ESTABLISHED -j ACCEPT

Spezielle Kette mit Check_Flags die bestimmte TCP Pakete loggen und ##verwerfen Hier werden Regeln festgelegt. Es werden limits gesetzt um
##unnötiges mitloggen zu vermeiden. Bedenke das diese Regeln nicht auf
##normalen traffic zu treffen. Sie sind dafür da verwursteten traffic zu
##vermeiden

iptables -N Check_Flags
iptables -F Check_Flags
#---------------------------------------------------------------------------
##Nmap/Portscanner mit den TCP-Flags URG,FIN,PSH
iptables -A Check_Flags -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "NMAP-XMAS:"
iptables -A Check_Flags -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
#---------------------------------------------------------------------------
##SYN/RST
iptables -A Check_Flags -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "SYN,RST:"
iptables -A Check_Flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
#---------------------------------------------------------------------------
##SYN/FIN (gegen mögliche Portscanner)
iptables -A Check_Flags -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "SYN,FIN:"
iptables -A Check_Flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
#---------------------------------------------------------------------------##gegen mögliche DoS Attacken. Diese Regelen verlangsamen Portscanner können
##aber zu unvorhergesehenen Problemen führen. Bei Problemen bitte Abschalten##!!!

iptables -A Check_Flags -m limit --limit 5/second -p tcp --tcp-flags ALL RST -j ACCEPT

iptables -A Check_Flags -m limit --limit 5/second -p tcp --tcp-flags ALL FIN -j ACCEPT

iptables -A Check_Flags -m limit --limit 5/second -p tcp --tcp-flags ALL SYN -j ACCEPT
#---------------------------------------------------------------------------

Spezielle Kette: Verbiete Ports Deny_ports
##Diese Kette unterbindet Drop/Log Pakete basierend auf Portnummern

iptables -N Deny_Ports
iptables -F Deny_Ports

#---------------------------------------------------------------------------
##Deklaration der Portnummern

Denied_Ports_TCP="0:6 8:19 23:24 26:52 54:79 81:109 111:142 144:442 444:545 548:992 994 996:1700 1702:3388 3390:65535"

for PORT in $Denied_Ports_TCP;

do

iptables -A Deny_Ports -p tcp --dport $PORT -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "Denied Port:"

iptables -A Deny_Ports -p tcp --sport $PORT -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "Denied Port:"

iptables -A Deny_Ports -p tcp --dport $PORT -j DROP
iptables -A Deny_Ports -p tcp --sport $PORT -j DROP

done
#---------------------------------------------------------------------------
##Deklaration der Portnummern

Denied_Ports_UDP="0:6 8:19 23:24 26:52 54:79 81:109 111:142 144:442 444:545 548:992 994 996:1700 1702:3388 3390:65535"

for PORT in $Denied_Ports_UDP;

do

iptables -A Deny_Ports -p udp --dport $PORT -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "Denied Port:"

iptables -A Deny_Ports -p udp --sport $PORT -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "Denied Port:"

iptables -A Deny_Ports -p udp --dport $PORT -j DROP
iptables -A Deny_Ports -p udp --sport $PORT -j DROP

done
#---------------------------------------------------------------------------
Spezielle Kette: erlaube Ports
##Regeln um Pakete portbasierend zu erlauben. Wird nur benötigt wenn Dienste
##laufen. Hier müssen also eventuelle Ports für z.b. einen Windows Server
##eingetragen werden. Da sonst nicht erreichbar.

iptables -N Allow_Ports
iptables -F Allow_Ports


TCP_Ports="20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389"


for PORT in $TCP_Ports;
do
iptables -A Allow_Ports -m state --state NEW -p tcp --dport $PORT -j ACCEPT
done

#---------------------------------------------------------------------------
## Erlaube ICMP (Ping)
##icmp: verbiete alle einkommenden pingversuche und erlaube alle ausgehenden

iptables -N Allow_ICMP
iptables -F Allow_ICMP

iptables -A Allow_ICMP -p icmp --icmp-type echo-reply -j ACCEPT
iptables -A Allow_ICMP -p icmp --icmp-type destination-unreachable -j ACCEPT
iptables -A Allow_ICMP -p icmp --icmp-type time-exceeded -j ACCEPT
iptables -A Allow_ICMP -p icmp --icmp-type echo-request -j ACCEPT

##Akzeptiere Pings mit einer Rate von 1 Ping/sekunde
iptables -A Allow_ICMP -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT

##Logge alle Pings
iptables -A Allow_ICMP -p icmp --icmp-type echo-request -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "Ping:"

##TTL Exceeded (traceroute)
iptables -A Allow_ICMP -p icmp --icmp-type time-exceeded -j ACCEPT

#---------------------------------------------------------------------------##Filtern des ausgehenden Verkehrs. Der DNS Server darf nur auf den DNS Port##lauschen und nirgends woanders. Für jeden Dienst müssen hier weitere
##4 Regeln festgelegt werden. Das ganze heist EGRESS FILTER für ausgehenden ##Verkehr. In diesem Fall der DNS Server. Hat man mehr Dienste zu laufen
##müssen dementsprechend natürlich mehr Regeln angelegt werden.
##Alle 4 Zusammen ergeben die Regeln für einen Dienst.

##Egress Filter

iptables -A PREROUTING -t nat -p tcp -i $Internal --dport 53 -j DNAT --to-destination $DNS_Server

iptables -A PREROUTING -t nat -p udp -i $Internal --dport 53 -j DNAT --to-destination $DNS_Server

iptables -A POSTROUTING -t nat -p tcp -o $External --dport 53 -j SNAT --to-source $DNS_Server

iptables -A POSTROUTING -t nat -p udp -o $External --dport 53 -j SNAT --to-source $DNS_Server
#---------------------------------------------------------------------------
#Umleitung der Pakete auf Squid
iptables -A PREROUTING -t nat -p tcp -i $Internal -m multiport --dport $TCP_Ports -j REDIRECT --to-port 3128

iptables -A PREROUTING -t nat -p udp -i $Internal -m multiport --dport $TCP_Ports -j REDIRECT --to-port 3128

iptables -A POSTROUTING -t nat -p tcp -o $External -m multiport --dport $TCP_Ports -j REDIRECT --to-port 3128

iptables -A POSTROUTING -t nat -p udp -o $External -m multiport --dport $TCP_Ports -j REDIRECT --to-port 3128
#---------------------------------------------------------------------------
Spezielle Kette Mangle_Output
##Mangle Werte von Paketen die lokal kreiert wurden.
##Nur TOS(Type of Service Bits) werden gemangelt
##(Mangle stellt die Manipulation der Pakete dar bevor sie durchs NAT laufen)


##TOS-Stuff: (type: iptables -m tos -h)
##Minimize-Delay 16(0x10)
##Maximize-Throughput 8(0x08)
##Maximizie-Reliability 4(0x04)
##Minimize-Cost 2(0x02)
##Normal-Service 0(0x00)

iptables -t mangle -N Mangle_Output
iptables -t mangle -F Mangle_Output

TCP_Ports="20,21,22,25,53,80,110,143,443,546,547,993,995,1701,3389"


iptables -t mangle -A Mangle_Output -p tcp --dport 20 -j TOS --set-tos 8
iptables -t mangle -A Mangle_Output -p tcp --dport 21 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 22 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 23 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 25 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 53 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 80 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 110 -j TOS --set-tos 8
iptables -t mangle -A Mangle_Output -p tcp --dport 143 -j TOS --set-tos 8
iptables -t mangle -A Mangle_Output -p tcp --dport 443 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 546 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 547 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 993 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 995 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 1701 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p tcp --dport 3389 -j TOS --set-tos 8

iptables -t mangle -A Mangle_Output -p udp --dport 20 -j TOS --set-tos 8
iptables -t mangle -A Mangle_Output -p udp --dport 21 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 22 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 23 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 25 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 53 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 80 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 110 -j TOS --set-tos 8
iptables -t mangle -A Mangle_Output -p udp --dport 143 -j TOS --set-tos 8
iptables -t mangle -A Mangle_Output -p udp --dport 443 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 546 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 547 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 993 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 995 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 1701 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Output -p udp --dport 3389 -j TOS --set-tos 16


#---------------------------------------------------------------------------
##Spezielle Kette Mangle_Prerouting
##Mangle Werte von Paketen die lokal kreiert wurden.
##Nur TOS(Type of Service Bits) werden gemangelt
##(Mangle stellt die Manipulation der Pakete dar bevor sie durchs NAT laufen)


##TOS-Stuff: (type: iptables -m tos -h)
##Minimize-Delay 16(0x10)
##Maximize-Throughput 8(0x08)
##Maximizie-Reliability 4(0x04)
##Minimize-Cost 2(0x02)
##Normal-Service 0(0x00)

iptables -t mangle -N Mangle_Prerouting
iptables -t mangle -F Mangle_Prerouting

iptables -t mangle -A Mangle_Prerouting -p tcp --dport 20 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 21 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 22 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 23 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 25 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 53 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 80 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 110 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 143 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 443 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 546 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 547 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 993 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 995 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 1701 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p tcp --dport 3389 -j TOS --set-tos 16

iptables -t mangle -A Mangle_Prerouting -p udp --dport 20 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 21 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 22 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 23 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 25 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 53 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 80 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 110 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 143 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 443 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 546 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 547 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 993 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 995 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 1701 -j TOS --set-tos 16
iptables -t mangle -A Mangle_Prerouting -p udp --dport 3389 -j TOS --set-tos 16


#---------------------------------------------------------------------------################################################################################## Firewall Input Ketten

##Neue Input Ketten für externen Input

iptables -N External_Input
iptables -F External_Input

##Checke reinkommende Pakete auf verrückte TCP Flags
iptables -A External_Input -i $External -p tcp -j Check_Flags

##Filtere reinkommende Pakete basierend auf der Portnummer
iptables -A INPUT -i $Internal -p icmp -j Allow_ICMP

iptables -A External_Input -i $External ! -p icmp -j Deny_Ports
#---------------------------------------------------------------------------
##Neue Input Kette für das interne Interface

iptables -N Internal_Input
iptables -F Internal_Input

##Verwerfe jegliche Pakete die nicht aus dem internen Netzwerk kommen
iptables -A Internal_Input -i $Internal ! -s $Internal_Net -j DROP

##Prüfe von Extern reinkommende TCP Pakete nochmal am Internen Interface
iptables -A Internal_Input -i $Internal -p tcp -j Check_Flags

##Verwerfe/Logge Pakete basierend auf der Portnummer
iptables -A Internal_Input -i $Internal ! -p icmp -j Deny_Ports
#---------------------------------------------------------------------------##Neue Kette für den Input im Loopback Device

iptables -N Lo_Input
iptables -F Lo_Input

##Akzeptiere Pakete für das Loopback Device
iptables -A Lo_Input -i $Loopback -j ACCEPT
#---------------------------------------------------------------------------
Firewall Output Ketten

##Neue Kette zum Output vom Externen Interface

iptables -N External_Output
iptables -F External_Output

##Prüfe TCP Pakete die von Extern kommen auf verrückte TCP Header
iptables -A External_Output -o $External -j Check_Flags

##Filtere rausgehende Pakete am Externen Interface anhand der Portnummer
iptables -A External_Output -o $External ! -p icmp -j Deny_Ports
#-------------------------------------------------------------------------------################################################################################

##Neue Kette für den Output am Externen Interface

iptables -N Internal_Output
iptables -F Internal_Output

##Verwerfe Pakete die nicht für das interne Netzwerk bestimmt sind
iptables -A Internal_Output -o $External ! -d $Internal_Net -j DROP

##Checke Interne TCP Pakete anhand der Portnummer
iptables -A Internal_Output -o $Internal ! -p icmp -j Deny_Ports

##Checke Interne Pakete die rausgehen auf verrückte TCP Flags
iptables -A Internal_Output -o $Internal -p tcp -j Check_Flags

##Neue Kette für den Output Traffic am Loopback Device

iptables -N Lo_Output
iptables -F Lo_Output

##Für jeglichen Traffic
iptables -A Lo_Output -o $Loopback -j ACCEPT
#---------------------------------------------------------------------------
Main Stuff

##Hier kommen wir zum Sprung von den selbst definierten Ketten zu den
##built-in Ketten

##Sprung zu den mangle Tabellen


iptables -t mangle -A OUTPUT -o $External -j Mangle_Output
iptables -t mangle -A PREROUTING -i $Internal -j Mangle_Output
#---------------------------------------------------------------------------##Logge und Verwerfe alle TCP Pakete die einen leeren Header besitzen
##möglicher Null_Scan

iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -m limit --limit 5/minute -j LOG --log-level $Log_Level --log-prefix "NULL SCAN:" --log-tcp-option --log-ip-option

iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP
#---------------------------------------------------------------------------##Sprung zum loopback Device

##Input fürs loopback Device
#Sprung zu unsere Lo_Input Kette

iptables -A INPUT -i $Loopback -j Lo_Input
#---------------------------------------------------------------------------##Input zu unserem internen Interface

##Verwerfe Pakete die nicht für die interne IPAdresse der Firewall bestimmt sind
iptables -A INPUT -i $Internal ! -d $Int_IP -j DROP

##Sprung zu unserer Internal_Input Kette
iptables -A INPUT -i $Internal -j Internal_Input

##Verwerfe/Akzeptiere Pakete je nach Status der Verbindung
iptables -A INPUT -i $Internal -j Keep_State

##Akzeptiere Pakete basierend auf der Portnummer
iptables -A INPUT -i $Internal -s $Internal_Net -d $Int_IP ! -p icmp -j Allow_Ports

#---------------------------------------------------------------------------##Input zum Externen Interface

##Springe zur External_Interface Kette
iptables -A INPUT -i $External -j External_Input

##Verwerfe/Akzeptiere Pakete basierend auf der Portnummer
iptables -A INPUT -i $External -j Keep_State

##Erlaube Pakete an bestimmte Ports (22, 53, 80)
iptables -A INPUT -i $External -j Allow_Ports

##Erlaube generell ICMP
iptables -A INPUT -i $External -p icmp -j Allow_ICMP

End Input Chains###############################
#-------------------------------------------------------------------------------##################################################################################Springe zu unseren Output Ketten

##Output fürs Loopback Interface
iptables -A OUTPUT -o $Loopback -j $Lo_Output

#---------------------------------------------------------------------------
##Springe zu unserem Internal_Output


##Spring zu unserer Internal_Output Kette
iptables -A OUTPUT -o $Int_IP -j $Internal_Output

##Verwerfe alles was nicht von der Firewall kommt
iptables -A OUTPUT -o $Internal ! -s $Int_IP

##Springe zur Keep_State Kette für einen generic stateful Packet Filter
iptables -A OUTPUT -o $Internal -j Keep_State

##Erlaube Pakete ins Interne Netz die von der Firewall kommen
iptables -A OUTPUT -o $Internal -s $Int_IP -d $Internal_Net -m state --state NEW -j ACCEPT

##Springe zum Allow_ICMP
iptables -A OUTPUT -o $Internal -j Allow_ICMP
#---------------------------------------------------------------------------
##Output am Externen Interface

##Springe zur Externen Output Kette
iptables -A OUTPUT -o $External -j External_Output

##Springe zur Keep_State Kette für einen generischen Paketfilter
iptables -A OUTPUT -o $External -j Keep_State

##Akzeptiere Pakete die nach draussen eine Verbindung aufbauen
iptables -A OUTPUT -o $External -m state --state NEW -j ACCEPT

##Akzeptiere Pings nach draussen
iptables -A OUTPUT -o $External -p icmp -j Allow_ICMP
Spring zu unseren Forward Ketten

##Springe zu unserem Internen/Externen Interface

iptables -A FORWARD -i $External -j External_Input
iptables -A FORWARD -i $External -j External_Output
iptables -A FORWARD -i $Internal -j Internal_Input
iptables -A FORWARD -i $Internal -j Internal_Output
Mehr Regeln um Sachen zu Verwerfen / DROP

##Verwerfe jeglichen Traffic von draussen der versucht eine Verbindung ins
##interne Netzwerk aufzubauen
iptables -A FORWARD -i $External -d $Internal_Net -m state --state NEW -j DROP

##Verwerfe jeglichen Traffic der von innen versucht eine Verbindung ins
##interne Netz aufzubauen
iptables -A FORWARD -o $Internal -d $Internal_Net -m state --state NEW -j DROP

##Verwerfe Echo Requests Pakete ins interne Netzwerk
iptables -A FORWARD -o $Internal -p icmp --icmp-type echo-request -j DROP
Egress Stuff

##Verwerfe jegliche Pakete die nicht für das interne Netzwerk bestimmt sind
iptables -A FORWARD -i $Internal ! -d $Internal_Net -j DROP

Akzeptiere einiges
iptables -A FORWARD -j Keep_State

##Akzeptiere Pakete die nach draussen eine Verbindung aufbauen
iptables -A FORWARD -o $External -m state --state NEW -j ACCEPT

##Springe zu Allow_ICMP
iptables -A FORWARD -p icmp -j ACCEPT
NAT

##Destination NAT

#
iptables -A PREROUTING -t nat -p tcp -i $External -d $Ext_IP --dport 22 -j DNAT --to-destination $External

iptables -A PREROUTING -t nat -p tcp -i $External -d $Ext_IP --dport 80 -j DNAT --to-destination $External
---------------------------------------------------------------------------##Source NAT (Masquerade)

##Dynamic IP Adress
iptables -t nat -A POSTROUTING -o $External -s $Internal_Net -j MASQUERADE
##Setze die Anzahl der möglichen Verbindungen die zu Überwachen sind höher

if

[ -e /proc/sys/net/ipv4/ip_conntrack_max ]; then
echo "4096" > /proc/sys/net/ipv4/ip_conntrack_max

fi

#-------------------------------------------------------------------------------
##Lege die lokale Portrange fest TCP/UDP

if

[ -e /proc/sys/net/ipv4/ip_local_portrange ]; then
echo -e "32768\t61000" > /proc/sys/net/ipv4/ip_local_portrange

fi
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
##verhindere das sich ein Paket mit gefälscter Absenderadresse einschleicht auch
##IP-Spoofing genannt
##verhindere source-routing damit ein Paket nicht vorgeben kann aus dem internen#Netz zu sein
echo "Disabling source routed packets..."
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
echo "0" > $i
done
#-------------------------------------------------------------------------------
echo "Setting up spoofing protection..."
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $i
done
#-------------------------------------------------------------------------------##ignoriere alle icmp echo requests(ping)
if [ -e /proc/sys/net/ipv4/conf/icmp_echo_ignore_broadcasts ]; then
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
fi
#-------------------------------------------------------------------------------##ignoriere sämtlichen icmp traffic

if [ -e /proc/sys/net/ipv4/conf/icmp_echo_ignore_all ]; then
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
fi
#-------------------------------------------------------------------------------##logge Pakete mit unmöglichen Adressen die an den kernel selbst adressiert sind
if [ -e /proc/sys/net/ipv4/conf/all/log_martians ]; then
echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
fi
#-------------------------------------------------------------------------------#verweigere icmp redirects (könnten die kernel routing einstellungen verändern)

##verhindere redirect vom externen interface
if [ -e /proc/sys/net/ipv4/conf/$External/accept_redirects ]; then
echo "0" > /proc/sys/net/ipv4/conf/$External/accept_redirects

fi
#-------------------------------------------------------------------------------##Sage dem kernel das du ein dynamisches netzwerkinterface hast / IP
if [ -e /proc/sys/net/ipv4/ip_dynaddr ]; then
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
fi
#-------------------------------------------------------------------------------##Aktiviere IP Forwarding
if [ -e /proc/sys/net/ipv4/ip_forward ]; then
echo "1" > /proc/sys/net/ipv4/ip_forward
else
echo "oh oh /proc/sys/net/ipv4/ip_forward existiert nicht"
fi
#---------------------------------------------------------------------------

##EOF
Member: brammer
brammer Dec 09, 2010 at 14:30:16 (UTC)
Goto Top
Hallo,

schön, und wir sollen dein Problem jetzt erraten????

brammer
Member: BahamutXII
BahamutXII Dec 09, 2010 at 14:47:30 (UTC)
Goto Top
Es sind so einige Fehler drin

Ich möchte das mich keiner pingen kann ich möchte pingen können. An einigen Stellen ist die notation angeblich falsch obwohl sie stimmt ich weis nicht warum er es nicht schluckt. Die Regeln fürs Prerouting für alle Ports sind noch nicht fertig aber grundsätzlich sagt er aber falsches Argument warum?

Hoffe jemand kann mir die Fehler aufzeigen!

Mfg
Benjamin

Hier das Fehlerlog:

''+ IPTABLES=/usr/local/sbin/iptables
''+ Loopback=lo
''+ Internal=eth0
''+ External=eth1
''+ Internal_Net=192.168.2.0
''+ DNS_Server=192.168.2.1
''+ Int_IP=ifconfig
''+ eth0
''./ruleset.sh: line 17: eth0: command not found
''+ grep inet
''+ grep -v inet6
''+ cut -d : -f 2
''+ cut -d ' ' -f 1
''+ Ext_IP=ifconfig
''+ eth1
./ruleset.sh: line 20: eth1: command not found
''+ grep inet
''+ grep -v inet6
''+ cut -d : -f 2
''+ cut -d ' ' -f 1
''+ Log_Level=notice
''+ iptables -F INPUT
''+ iptables -F OUTPUT
''+ iptables -F FORWARD
''+ iptables -F
''+ iptables -F -t mangle
''+ iptables -t mangle -X
''+ iptables -X
''+ iptables -P INPUT DROP
''+ iptables -P OUTPUT DROP
''+ iptables -P FORWARD DROP
''+ iptables -N Keep_State
''+ iptables -F Keep_State
''+ iptables -A Keep_State -m state --state INVALID -j DROP
''+ iptables -A Keep_State -m state --state RELATED,ESTABLISHED -j ACCEPT
''+ iptables -N Check_Flags
''+ iptables -F Check_Flags
''+ iptables -A Check_Flags -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level notice --log-prefix NMAP-XMAS:
''+ iptables -A Check_Flags -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
''+ iptables -A Check_Flags -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level notice --log-prefix SYN,RST:
''+ iptables -A Check_Flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
''+ iptables -A Check_Flags -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level notice --log-prefix SYN,FIN:
''+ iptables -A Check_Flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
''+ iptables -A Check_Flags -m limit --limit 5/second -p tcp --tcp-flags ALL RST -j ACCEPT
''+ iptables -A Check_Flags -m limit --limit 5/second -p tcp --tcp-flags ALL FIN -j ACCEPT
''+ iptables -A Check_Flags -m limit --limit 5/second -p tcp --tcp-flags ALL SYN -j ACCEPT
''+ iptables -N Deny_Ports
''+ iptables -F Deny_Ports
''+ Denied_Ports_TCP='0:6 8:19 23:24 26:52 54:79 81:109 111:142 144:442 444:545 548:992 994 996:1700 1702:3388 3390:65535'
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 0:6 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 0:6 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 0:6 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 0:6 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 8:19 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 8:19 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 8:19 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 8:19 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 23:24 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 23:24 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 23:24 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 23:24 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 26:52 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 26:52 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 26:52 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 26:52 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 54:79 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 54:79 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 54:79 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 54:79 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 81:109 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 81:109 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 81:109 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 81:109 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 111:142 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 111:142 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 111:142 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 111:142 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 144:442 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 144:442 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 144:442 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 144:442 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 444:545 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 444:545 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 444:545 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 444:545 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 548:992 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 548:992 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 548:992 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 548:992 -j DROP
''+ for PORT in '$Denied_Ports_TCP
''+ iptables -A Deny_Ports -p tcp --dport 994 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 994 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 994 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 994 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 996:1700 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 996:1700 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 996:1700 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 996:1700 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 1702:3388 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 1702:3388 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 1702:3388 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 1702:3388 -j DROP
''+ for PORT in '$Denied_Ports_TCP'
''+ iptables -A Deny_Ports -p tcp --dport 3390:65535 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --sport 3390:65535 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p tcp --dport 3390:65535 -j DROP
''+ iptables -A Deny_Ports -p tcp --sport 3390:65535 -j DROP
''+ Denied_Ports_UDP='0:6 8:19 23:24 26:52 54:79 81:109 111:142 144:442 444:545 548:992 994 996:1700 1702:3388 3390:65535'
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 0:6 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 0:6 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 0:6 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 0:6 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 8:19 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 8:19 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 8:19 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 8:19 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 23:24 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 23:24 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 23:24 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 23:24 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 26:52 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 26:52 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 26:52 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 26:52 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 54:79 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 54:79 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 54:79 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 54:79 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 81:109 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 81:109 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 81:109 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 81:109 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 111:142 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 111:142 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 111:142 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 111:142 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 144:442 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 144:442 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 144:442 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 144:442 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 444:545 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 444:545 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 444:545 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 444:545 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 548:992 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 548:992 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 548:992 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 548:992 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 994 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 994 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 994 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 994 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 996:1700 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 996:1700 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 996:1700 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 996:1700 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 1702:3388 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 1702:3388 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 1702:3388 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 1702:3388 -j DROP
''+ for PORT in '$Denied_Ports_UDP'
''+ iptables -A Deny_Ports -p udp --dport 3390:65535 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --sport 3390:65535 -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'Denied Port:'
''+ iptables -A Deny_Ports -p udp --dport 3390:65535 -j DROP
''+ iptables -A Deny_Ports -p udp --sport 3390:65535 -j DROP
''+ iptables -N Allow_Ports
''+ iptables -F Allow_Ports
''+ TCP_Ports='20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389'
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 20 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 21 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 22 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 25 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 53 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 80 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 443 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 546 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 547 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 1701 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 110 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 143 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 993 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 995 -j ACCEPT
''+ for PORT in '$TCP_Ports'
''+ iptables -A Allow_Ports -m state --state NEW -p tcp --dport 3389 -j ACCEPT
''+ iptables -N Allow_ICMP
''+ iptables -F Allow_ICMP
''+ iptables -A Allow_ICMP -p icmp --icmp-type echo-reply -j ACCEPT
''+ iptables -A Allow_ICMP -p icmp --icmp-type destination-unreachable -j ACCEPT
''+ iptables -A Allow_ICMP -p icmp --icmp-type time-exceeded -j ACCEPT
''+ iptables -A Allow_ICMP -p icmp --icmp-type echo-request -j ACCEPT
''+ iptables -A Allow_ICMP -p icmp --icmp-type echo-request -m limit --limit 1/second -j ACCEPT
''+ iptables -A Allow_ICMP -p icmp --icmp-type echo-request -m limit --limit 5/minute -j LOG --log-level notice --log-prefix Ping:
''+ iptables -A Allow_ICMP -p icmp --icmp-type time-exceeded -j ACCEPT
''+ iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 53 -j DNAT --to-destination 192.168.2.1
''+ iptables -A PREROUTING -t nat -p udp -i eth0 --dport 53 -j DNAT --to-destination 192.168.2.1
''+ iptables -A POSTROUTING -t nat -p tcp -o eth1 --dport 53 -j SNAT --to-source 192.168.2.1
''+ iptables -A POSTROUTING -t nat -p udp -o eth1 --dport 53 -j SNAT --to-source 192.168.2.1

back-to-topiptables -A PREROUTING -t nat -p tcp -i eth0 -m multiport --dport 20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389 -j REDIRECT --to-port 3128

Bad argument `21'
Try `iptables -h' or 'iptables --help' for more information.

back-to-topiptables -A PREROUTING -t nat -p udp -i eth0 -m multiport --dport 20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389 -j REDIRECT --to-port 3128

Bad argument `21'
Try `iptables -h' or 'iptables --help' for more information.

back-to-topiptables -A POSTROUTING -t nat -p tcp -o eth1 -m multiport --dport 20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389 -j REDIRECT --to-port 3128

Bad argument `21'
Try `iptables -h' or 'iptables --help' for more information.

back-to-topiptables -A POSTROUTING -t nat -p udp -o eth1 -m multiport --dport 20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389 -j REDIRECT --to-port 3128

Bad argument `21'
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -t mangle -N Mangle_Output
''+ iptables -t mangle -F Mangle_Output
''+ TCP_Ports=20,21,22,25,53,80,110,143,443,546,547,993,995,1701,3389
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 20 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 21 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 22 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 23 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 25 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 53 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 80 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 110 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 143 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 443 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 546 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 547 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 993 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 995 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 1701 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p tcp --dport 3389 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p udp --dport 20 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p udp --dport 21 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 22 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 23 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 25 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 53 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 80 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 110 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p udp --dport 143 -j TOS --set-tos 8
''+ iptables -t mangle -A Mangle_Output -p udp --dport 443 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 546 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 547 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 993 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 995 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 1701 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Output -p udp --dport 3389 -j TOS --set-tos 16
''+ iptables -t mangle -N Mangle_Prerouting
''+ iptables -t mangle -F Mangle_Prerouting
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 20 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 21 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 22 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 23 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 25 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 53 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 80 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 110 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 143 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 443 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 546 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 547 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 993 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 995 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 1701 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p tcp --dport 3389 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 20 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 21 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 22 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 23 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 25 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 53 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 80 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 110 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 143 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 443 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 546 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 547 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 993 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 995 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 1701 -j TOS --set-tos 16
''+ iptables -t mangle -A Mangle_Prerouting -p udp --dport 3389 -j TOS --set-tos 16
''+ iptables -N External_Input
''+ iptables -F External_Input
''+ iptables -A External_Input -i eth1 -p tcp -j Check_Flags
''+ iptables -A INPUT -i eth0 -p icmp -j Allow_ICMP
''+ iptables -A External_Input -i eth1 '!' -p icmp -j Deny_Ports
''+ iptables -N Internal_Input
''+ iptables -F Internal_Input
''+ iptables -A Internal_Input -i eth0 '!' -s 192.168.2.0 -j DROP
''+ iptables -A Internal_Input -i eth0 -p tcp -j Check_Flags
''+ iptables -A Internal_Input -i eth0 '!' -p icmp -j Deny_Ports
''+ iptables -N Lo_Input
''+ iptables -F Lo_Input
''+ iptables -A Lo_Input -i lo -j ACCEPT
''+ iptables -N External_Output
''+ iptables -F External_Output
''+ iptables -A External_Output -o eth1 -j Check_Flags
''+ iptables -A External_Output -o eth1 '!' -p icmp -j Deny_Ports
''+ iptables -N Internal_Output
''+ iptables -F Internal_Output
''+ iptables -A Internal_Output -o eth1 '!' -d 192.168.2.0 -j DROP
''+ iptables -A Internal_Output -o eth0 '!' -p icmp -j Deny_Ports
''+ iptables -A Internal_Output -o eth0 -p tcp -j Check_Flags
''+ iptables -N Lo_Output
''+ iptables -F Lo_Output
''+ iptables -A Lo_Output -o lo -j ACCEPT
''+ iptables -t mangle -A OUTPUT -o eth1 -j Mangle_Output
''+ iptables -t mangle -A PREROUTING -i eth0 -j Mangle_Output
''+ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -m limit --limit 5/minute -j LOG --log-level notice --log-prefix 'NULL SCAN:' --log-tcp-option --log-ip-option
''+ iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP
''+ iptables -A INPUT -i lo -j Lo_Input

back-to-topiptables -A INPUT -i eth0 '!' -d -j DROP

Bad argument `DROP'
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -A INPUT -i eth0 -j Internal_Input
''+ iptables -A INPUT -i eth0 -j Keep_State

back-to-topiptables -A INPUT -i eth0 -s 192.168.2.0 -d '!' -p icmp -j Allow_Ports

Using intrapositioned negation (`--option ! this`) is deprecated in favor of extrapositioned (`! --option this`).
Bad argument `icmp'
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -A INPUT -i eth1 -j External_Input
''+ iptables -A INPUT -i eth1 -j Keep_State
''+ iptables -A INPUT -i eth1 -j Allow_Ports
''+ iptables -A INPUT -i eth1 -p icmp -j Allow_ICMP

back-to-topiptables -A OUTPUT -o lo -j

iptables v1.4.9.1: option `-j' requires an argument
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -A OUTPUT -o -j

back-to-topiptables -A OUTPUT -o eth0 '!' -s

iptables v1.4.9.1: option `-s' requires an argument
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -A OUTPUT -o eth0 -j Keep_State

back-to-topiptables -A OUTPUT -o eth0 -s -d 192.168.2.0 -m state --state NEW -j ACCEPT

Bad argument `192.168.2.0'
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -A OUTPUT -o eth0 -j Allow_ICMP
''+ iptables -A OUTPUT -o eth1 -j External_Output
''+ iptables -A OUTPUT -o eth1 -j Keep_State
''+ iptables -A OUTPUT -o eth1 -m state --state NEW -j ACCEPT
''+ iptables -A OUTPUT -o eth1 -p icmp -j Allow_ICMP
''+ iptables -A FORWARD -i eth1 -j External_Input
''+ iptables -A FORWARD -i eth1 -j External_Output
''+ iptables -A FORWARD -i eth0 -j Internal_Input
''+ iptables -A FORWARD -i eth0 -j Internal_Output
''+ iptables -A FORWARD -i eth1 -d 192.168.2.0 -m state --state NEW -j DROP
''+ iptables -A FORWARD -o eth0 -d 192.168.2.0 -m state --state NEW -j DROP
''+ iptables -A FORWARD -o eth0 -p icmp --icmp-type echo-request -j DROP
''+ iptables -A FORWARD -i eth0 '!' -d 192.168.2.0 -j DROP
''+ iptables -A FORWARD -j Keep_State
''+ iptables -A FORWARD -o eth1 -m state --state NEW -j ACCEPT
''+ iptables -A FORWARD -p icmp -j ACCEPT

back-to-topiptables -A PREROUTING -t nat -p tcp -i eth1 -d --dport 22 -j DNAT --to-destination eth1

Bad argument `22'
Try `iptables -h' or 'iptables --help' for more information.

back-to-topiptables -A PREROUTING -t nat -p tcp -i eth1 -d --dport 80 -j DNAT --to-destination eth1

Bad argument `80'
Try `iptables -h' or 'iptables --help' for more information.
''+ iptables -t nat -A POSTROUTING -o eth1 -s 192.168.2.0 -j MASQUERADE
''+ '[' -e /proc/sys/net/ipv4/ip_conntrack_max ']'
''+ '[' -e /proc/sys/net/ipv4/ip_local_portrange ']'
''+ echo 'Disabling source routed packets...'
''Disabling source routed packets...''
''+ for i in '/proc/sys/net/ipv4/conf/*/accept_source_route'
''+ echo 0
''+ for i in '/proc/sys/net/ipv4/conf/*/accept_source_route'
''+ echo 0
''+ for i in '/proc/sys/net/ipv4/conf/*/accept_source_route'
''+ echo 0
''+ for i in '/proc/sys/net/ipv4/conf/*/accept_source_route'
''+ echo 0
''+ for i in '/proc/sys/net/ipv4/conf/*/accept_source_route'
''+ echo 0
''+ echo 'Setting up spoofing protection...'
''Setting up spoofing protection...
''+ for i in '/proc/sys/net/ipv4/conf/*/rp_filter'
''+ echo 1
''+ for i in '/proc/sys/net/ipv4/conf/*/rp_filter'
''+ echo 1
''+ for i in '/proc/sys/net/ipv4/conf/*/rp_filter'
''+ echo 1
''+ for i in '/proc/sys/net/ipv4/conf/*/rp_filter'
''+ echo 1
''+ for i in '/proc/sys/net/ipv4/conf/*/rp_filter'
''+ echo 1
''+ '[' -e /proc/sys/net/ipv4/conf/icmp_echo_ignore_broadcasts ']'
''+ '[' -e /proc/sys/net/ipv4/conf/icmp_echo_ignore_all ']'
''+ '[' -e /proc/sys/net/ipv4/conf/all/log_martians ']'
''+ echo 1
''+ '[' -e /proc/sys/net/ipv4/conf/eth1/accept_redirects ']'
''+ echo 0
''+ '[' -e /proc/sys/net/ipv4/ip_dynaddr ']'
''+ echo 1
''+ '[' -e /proc/sys/net/ipv4/ip_forward ']'
''+ echo 1
Member: brutuz09
brutuz09 Dec 09, 2010 at 15:06:21 (UTC)
Goto Top
Hallo,

wenn du nur eingehende Ping's blockieren willst reicht glaub ich der Befehl "iptables -A INPUT -p icmp --icmp-type 8 -j DROP"

Nicht böse nehmen aber bei der hälfte deines FW script's weisst du bestimmt nicht was es tut nehme ich an - daher würde ich dir vorschlagen - google mal ein paar iptables tutorials ;)


lg
Member: BahamutXII
BahamutXII Dec 09, 2010 at 15:17:03 (UTC)
Goto Top
ich weis das sehr wohl aber es sind nunmal noch fehler drin willst du helfen oder nicht?
Member: brammer
brammer Dec 09, 2010 at 15:28:59 (UTC)
Goto Top
Hallo,

kann es sein das dein Verhalten etwas arrogant ist?
Das ist hier ein freiwilliges forum!

iptables -A PREROUTING -t nat -p tcp -i eth0 -m multiport --dport 20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389 -j REDIRECT --to-port 3128
Bad argument `21'
Try `iptables -h' or 'iptables --help' for more information.

Müsste die Syntax evtl.
iptables -A PREROUTING -t nat -p tcp -i eth0 -m multiport --dport 20, 21, 22, 25, 53, 80, 443, 546, 547, 1701, 110, 143, 993,...
heißen ?
und wieso sperrst du nicht einfach alles und machst nur das was du brauchst auf?


iptables -A OUTPUT -o eth0 -s -d 192.168.2.0 -m state --state NEW -j ACCEPT

192.168.2.0 ist keine IP adresse sondern eine Netzadresse

brammer
Member: BahamutXII
BahamutXII Dec 09, 2010 at 15:39:09 (UTC)
Goto Top
Sorry kam wohl etwas falsch rüber...stehe etwas unter druck

Also ich habe das eben mal umgedreht muss aber festestellen das er trotzdem bei den ports wrong argument sagt. Das erscheint mir unlogisch. So wie du oben:

iptables -t nat -A PREROUTING -P TCP --o eth0 m multiport --dport 20 21 22 25 53 80 443 546 547 1701 110 143 993 995 3389 -j REDIRECT --to-port 3128

naja es sind 15 ports find ich jetzt nicht so tragisch. dahinter steckt nochmal ein squid mit squidguard darum der redirect.


iptables -A OUTPUT -o eth0 -s -d 192.168.2.0 -m state --state NEW -j ACCEPT

Hhm jo dachte halt ich kann das ganze netz nehmen: es sind doch Pakete die die von der Firewall kommen und ins interne Netz gelassen werden sollen...lieber ne variable mit ipadressen konfigurieren oder muss ich dann tatsächlich für jede Rechner im Netz die Regel aufstellen?


face-smile
Member: BahamutXII
BahamutXII Dec 09, 2010 at 16:46:13 (UTC)
Goto Top
Also ich hab das eben nochmal auf der Konsole händisch eingegeben ohne Script und da meckert er nicht und die Regel ist vollkommen in Ordnung.

iptables -A OUTPUT -o eth0 -s 192.168.2.100 -d 192.168.2.0 -m state --state NEW -j ACCEPT

Wieso meckert er wenn ich es als Script ausführe und in der Konsole tut ers einwandfrei!?

--Nachtrag--

Wenn alle nic das netzwerk und vieles mehr sind ja als variablen deklariert wenn ich die variable durch die adresse des Netzes ersetze schluckt er die regel einwandfrei ich kann es nciht begreifen....unlogisch
Member: brammer
brammer Dec 09, 2010 at 17:09:54 (UTC)
Goto Top
Hallo,

solange du nicht den selben Befehl benutzt kannst du auch nicht vergleichen ob er mit einem anderen übereinstimmt!!

iptables -A OUTPUT -o eth0 -s -d 192.168.2.0 -m state --state NEW -j ACCEPT

ist nicht identisch mit

iptables -A OUTPUT -o eth0 -s 192.168.2.100 -d 192.168.2.0 -m state --state NEW -j ACCEPT

brammer
Member: BahamutXII
BahamutXII Dec 09, 2010 at 17:20:36 (UTC)
Goto Top
das ist der Befehl nur das er im Fehlerlog sagt das er die Variable nicht schluckt und ich unten die variablen durch die adressen selbst ersetze habe siehe oben....

Eigentlich sieht das so aus:

iptables -A OUTPUT -o $Internal -s $Int_IP -d $Internal_Net -m state --state NEW -j ACCEPT

Er macht aber daraus das:

iptables -A OUPUT -o eth0 -s -d 192.168.2.0 -m state --state NEW -j ACCEPT

Bad argument '192.168.2.0'
Member: brammer
brammer Dec 09, 2010 at 18:12:16 (UTC)
Goto Top
Hallo,

was passiert wenn du die Netzadresse durch die echte interface adresse austauscht?

brammer
Member: BahamutXII
BahamutXII Dec 10, 2010 at 09:40:19 (UTC)
Goto Top
Danke erstmal für die schnelle Hilfe,

leider hat mir der Austausch auch nichts gebracht. Habs aber trotzdem gelöst. Der grep auf die ip hatte nicht richtig gegriffen daraus entstanden fast alle Folgefehler.

face-smile