We'll leave the "duplicate packets" problem until there's some more diagnostic data available, but the rule deletion is easy.
To delete an iptables rule, simply replace the -A
with -D
:
iptables -D PREROUTING -t nat -p tcp --dport 162 -j REDIRECT --to-port 8981
If you're using -I N
instead, you can use iptables -D N
, but that's risky if there have been any rules inserted subsequently.
If you've really screwed up and don't even know what iptables
command you ran (bash
has command history for a reason...) then you can list all the rules in a chain like this:
iptables -t nat -L PREROUTING --line-numbers
Which will get you output like this:
Chain int2ext (1 references)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
2 ACCEPT all -- 192.0.2.0/24 0.0.0.0/0
3 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
Then, find the num
column entry corresponding to the rule you want to delete, and run
iptables -t nat -D PREROUTING <num>