I have a rule in iptables that looks like this:
DROP all -- 5.158.238.32 anywhere
But I would like to change it to be:
DROP all -- 5.158.0.0/16 anywhere
How do I do this?
I've found info on how you add rules but this seems to append rules to the end of the list and for some reason the rule doesn't take effect unless it's higher up.
I've also found info on editing a file but my distro (debain) doesn't seem to have a file any of the locations mentioned in the articles - is there a file I can edit somewhere?
Any pointers in the right direction would be much appreciated.
Cheers
Ben
Run iptables -L --line-numbers
, which will give you all the current rules as well as their rule numbers. Once you have identified the line number of the rule you would like to replace, run iptables -R <chain> <rulenum> <new rule def>
. In your case, the output to the first would be something like this (greatly truncated):
Chain INPUT (policy ACCEPT)
num target prot opt source destination
....
12 DROP all -- 5.158.238.32 anywhere
...
and to replace it, you would run:
iptables -R INPUT 12 -s 5.158.0.0/16 -j DROP
Hope this makes sense. Good luck!
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