how to undo an iptables rule that I did?

I accidentally did:

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to 0.0.0.0

when 0.0.0.0 should be the server's IP address but I forgot to replace it. How can I undo this?


Solution 1:

Just run:

iptables -t nat -D POSTROUTING -s 10.8.0.0/24 -j SNAT --to 0.0.0.0

-D flag remove the rules that are matching the rule specified as parameters. In short, run the same command, but replace -A or -I with -D to remove that rule.