0

i want to fwd the udp packets that are received on port 162 to another port.ex:8981

i have executed the following cmd

iptables -A PREROUTING -t nat  -p tcp --dport 162 -j REDIRECT --to-port 8981

I see that i am recieving duplicates packets now on 8981..

could some one guide me the right way of doing it?

Also how to delete the above rule ?

TIA, /d

Inv3r53
  • 163
  • 1
  • 8

1 Answers1

1

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>
womble
  • 96,255
  • 29
  • 175
  • 230
  • hi thanks for the reply, now as pudding fox points out , i may have used tcp there in cmd..also iam not quite sure of the cmd use..is there a way to see my rule using iptables and delete it? – Inv3r53 Aug 07 '11 at 11:05
  • i only want to redirect packets on same host from port 162 to another one as i cannot open socket on port < 1024 , due to permissions problem. – Inv3r53 Aug 07 '11 at 11:07
  • question updated to provide another way of deleting rules. – womble Aug 07 '11 at 17:47