Iptables: Unterschied zwischen den Versionen
Wolf (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
Kn3cHt (Diskussion | Beiträge) Script hinzugefügt |
||
| Zeile 10: | Zeile 10: | ||
Definiere ein paar Regeln, und starte ''/etc/rc.d/iptables save'' Das Script ruft 'iptables-save' auf, und speichert Deine erstellten Regeln in ''/etc/iptables/iptables.rules''. | Definiere ein paar Regeln, und starte ''/etc/rc.d/iptables save'' Das Script ruft 'iptables-save' auf, und speichert Deine erstellten Regeln in ''/etc/iptables/iptables.rules''. | ||
Jetzt kannst Du iptables starten. Das Script ruft ''iptables-restore'' auf, und lädt Deine Regeln. | Jetzt kannst Du iptables starten. | ||
# /etc/rc.d/iptables start | |||
Das Script ruft ''iptables-restore'' auf, und lädt Deine Regeln. | |||
Du kannst die Firewall natürlich im DAEMONS Feld in ''/etc/rc.conf'' eintragen, damit es nach jedem boot automatisch geladen wird. | Du kannst die Firewall natürlich im DAEMONS Feld in ''/etc/rc.conf'' eintragen, damit es nach jedem boot automatisch geladen wird. | ||
# DAEMONS=(...'''iptables''' network...) | |||
Hier ein Script um iptables für einen Rechner der direkt am Internet hängt einzurichten. | |||
#!/bin/bash | |||
#Ports: Hier eintragen welche Ports geöffnet werden sollen | |||
SERVICES_UDP="" #freigegebene UDP-Ports | |||
SERVICES_TCP="22 80" #freigegebene TCP-Ports (Hier sshd und http) | |||
#Alle vorhandenen Regeln löschen | |||
iptables -F | |||
iptables -t nat -F | |||
iptables -t mangle -F | |||
iptables -X | |||
iptables -t nat -X | |||
iptables -t mangle -X | |||
#Grundregeln | |||
iptables -P OUTPUT ACCEPT | |||
iptables -P INPUT DROP | |||
iptables -P FORWARD DROP | |||
#Sicherheit | |||
iptables -N bad_packets | |||
iptables -A bad_packets -p ALL -m state --state INVALID -j DROP #kaputte Pakete droppen | |||
iptables -A bad_packets -p tcp -j REJECT --reject-with tcp-reset #Antispoofing | |||
iptables -A bad_packets -p udp -j REJECT --reject-with icmp-port-unreachable #Antispoofing | |||
iptables -A bad_packets -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT #Ping Of Death | |||
iptables -A bad_packets -p ALL -j RETURN | |||
iptables -N service_sec | |||
iptables -A service_sec -p tcp --syn -m limit --limit 1/s -j ACCEPT #SYN-Flood Attacken | |||
iptables -A service_sec -p tcp ! --syn -m state --state NEW -j DROP #TCP-SYN-Pakete ohne Status NEW droppen | |||
iptables -A service_sec -p tcp --tcp-flags ALL NONE -m limit --limit 1/h -j ACCEPT #Portscanner ausschalten | |||
iptables -A service_sec -p tcp --tcp-flags ALL ALL -m limit --limit 1/h -j ACCEPT #Portscanner ausschalten | |||
iptables -A service_sec -p ALL -j RETURN | |||
#Dienste | |||
iptables -N services | |||
for port in $SERVICES_TCP ; do | |||
iptables -A services -p tcp --dport $port -j service_sec | |||
iptables -A services -p tcp --dport $port -j ACCEPT | |||
done | |||
for port in $SERVICES_UDP ; do | |||
iptables -A services -p udp --dport $port -j service_sec | |||
iptables -A services -p udp --dport $port -j ACCEPT | |||
done | |||
iptables -A services -p ALL -j RETURN | |||
#INPUT | |||
iptables -A INPUT -p ALL -i lo -j ACCEPT | |||
iptables -A INPUT -p icmp -j ACCEPT | |||
iptables -A INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT | |||
iptables -A INPUT -p ALL -j services | |||
iptables -A INPUT -p ALL -j bad_packets | |||
#OUTPUT: Alles was raus geht wird erlaubt | |||
iptables -A OUTPUT -p ALL -j ACCEPT | |||
#Speichern | |||
/etc/rc.d/iptables save | |||
Version vom 6. Oktober 2007, 14:16 Uhr
iptables
Der Kernel selber hat mit 'Netfilter' einen sehr mächtigen und sicheren Paketfilter. Der Paketfilter untersucht die Paket die deinen Rechner verlassen, oder erreichen. Mit anderen Worten... er reagiert auf Netzwerkpaket je nach Art, Quelle, Ziel usw. zum Beispiel mit Zurückweisung. Das entsprechende Programm zur Steuerung des Paketfilters lautet 'iptables'.
Das entsprechende Paket wird mittels folgendem Aufruf installiert.
# pacman -S iptables
Definiere ein paar Regeln, und starte /etc/rc.d/iptables save Das Script ruft 'iptables-save' auf, und speichert Deine erstellten Regeln in /etc/iptables/iptables.rules.
Jetzt kannst Du iptables starten.
# /etc/rc.d/iptables start
Das Script ruft iptables-restore auf, und lädt Deine Regeln. Du kannst die Firewall natürlich im DAEMONS Feld in /etc/rc.conf eintragen, damit es nach jedem boot automatisch geladen wird.
# DAEMONS=(...iptables network...)
Hier ein Script um iptables für einen Rechner der direkt am Internet hängt einzurichten.
#!/bin/bash
#Ports: Hier eintragen welche Ports geöffnet werden sollen
SERVICES_UDP="" #freigegebene UDP-Ports
SERVICES_TCP="22 80" #freigegebene TCP-Ports (Hier sshd und http)
#Alle vorhandenen Regeln löschen
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
#Grundregeln
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
#Sicherheit
iptables -N bad_packets
iptables -A bad_packets -p ALL -m state --state INVALID -j DROP #kaputte Pakete droppen
iptables -A bad_packets -p tcp -j REJECT --reject-with tcp-reset #Antispoofing
iptables -A bad_packets -p udp -j REJECT --reject-with icmp-port-unreachable #Antispoofing
iptables -A bad_packets -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT #Ping Of Death
iptables -A bad_packets -p ALL -j RETURN
iptables -N service_sec
iptables -A service_sec -p tcp --syn -m limit --limit 1/s -j ACCEPT #SYN-Flood Attacken
iptables -A service_sec -p tcp ! --syn -m state --state NEW -j DROP #TCP-SYN-Pakete ohne Status NEW droppen
iptables -A service_sec -p tcp --tcp-flags ALL NONE -m limit --limit 1/h -j ACCEPT #Portscanner ausschalten
iptables -A service_sec -p tcp --tcp-flags ALL ALL -m limit --limit 1/h -j ACCEPT #Portscanner ausschalten
iptables -A service_sec -p ALL -j RETURN
#Dienste
iptables -N services
for port in $SERVICES_TCP ; do
iptables -A services -p tcp --dport $port -j service_sec
iptables -A services -p tcp --dport $port -j ACCEPT
done
for port in $SERVICES_UDP ; do
iptables -A services -p udp --dport $port -j service_sec
iptables -A services -p udp --dport $port -j ACCEPT
done
iptables -A services -p ALL -j RETURN
#INPUT
iptables -A INPUT -p ALL -i lo -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p ALL -j services
iptables -A INPUT -p ALL -j bad_packets
#OUTPUT: Alles was raus geht wird erlaubt
iptables -A OUTPUT -p ALL -j ACCEPT
#Speichern
/etc/rc.d/iptables save
Weitere Quellen