So löschen Sie mehrere Zeilen der IPTABLES

495
Bastian Nanchen

Gibt es eine Möglichkeit, mehrere Zeilen in einem zu löschen, der iptablesnicht weiß, was sich in meinem befindet iptables?

Ich möchte zum Beispiel jede Portweiterleitung von Port 80 löschen und hier ist Folgendes iptables:

Chain PREROUTING (policy ACCEPT) target prot opt source destination  REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080 REDIRECT tcp -- anywhere anywhere tcp dpt:https redir ports 8443 

Gibt es eine Möglichkeit, diese beiden Zeilen in einem Befehl zu löschen?

0

1 Antwort auf die Frage

0
Bastian Nanchen

Hier ist ein Arbeitsskript:

 iptables -t nat --list-rules PREROUTING | while IFS='' read -r line || [[ -n "$line" ]]; do RULE443=$(echo $line | grep "REDIRECT --to-ports 8443") RULE80=$(echo $line | grep "REDIRECT --to-ports 8080") if [ "$RULE80" != '' ] then PORT80=$(echo $RULE80 | grep -o '\-\-dport.*' | cut -d' ' -f2) iptables -t nat -D PREROUTING -p tcp --dport $PORT80 -j REDIRECT --to-port 8080 elif [ "$RULE443" != '' ] then PORT443=$(echo $RULE443 | grep -o '\-\-dport.*' | cut -d' ' -f2) iptables -t nat -D PREROUTING -p tcp --dport $PORT443 -j REDIRECT --to-port 8443 fi done