i have 2 rules of iptables
iptables -A INPUT -s 5.5.5.5 -j DROP iptables -A INPUT -s 6.5.5.5 -j ACCEPT
is there a function or a command that will swap the rules to be like this:
iptables -A INPUT -s 6.5.5.5 -j ACCEPT iptables -A INPUT -s 5.5.5.5 -j DROP
First check the line number:
iptables -nL --line-numbers
Delete based on line:
iptables -D INPUT {line}
Insert where you would like it to be:
iptables -I INPUT {line} -i lo -p tcp --dport {port} -j ACCEPT -m comment --comment "This rule is here for this reason"
Found at these sources:
Delete Rule
Insert Rule
We had an issue with the order of some rules, and the most efficient way I found to change this was with two tools:
First dump the rules into a file:
sudo iptables-save > /root/iptrules.txt
Then edit the file with your favorite text editor:
sudo vim /root/iptrules.txt
Make the necessary movements and then restore the rules:
sudo iptables-restore < /root/iptrules.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With