i need to mirror all packets from port 162 to another (for example 1162) on localhost.

I know that TEE can mirror packets but to some ip address.

Maybe it is possible in one rule change also destination port, but i can't find working solution.

Something like that:

iptables -t mangle -A PREROUTING -d -j TEE --to-destination

But from manual: Send the cloned packet to the host reachable at the given IP address. Use of (for IPv4 packets) or :: (IPv6) is invalid.

Thanks for any hint.

OS:RedHat 6.9

  • 1
    What have you tried? What OS are you using? Please take our tour and see How to Ask.
    – Burgi
    Jan 26, 2018 at 9:08
  • Finally i use github.com/sleinen/samplicator for such activity
    – Neci
    Jul 26, 2019 at 8:54
  • You should write an answer explaining how you solved it.
    – Burgi
    Aug 2, 2019 at 16:58

1 Answer 1


It seems that there are some misunderstanding :

I need to mirror all packets from port 162

your rule should include --sport 162 or --dport 162 if you meant "all packets arriving to port 162"


In fact does not match the localhost. You should use instead.

Finally you can try for TCP traffic:

iptables -t mangle -A PREROUTING -p TCP --dport 162 -j TEE --gateway
iptables -t nat -A PREROUTING -d -p TCP --dport 162 -j DNAT  --to

The first rule copies the traffic to localhost The second rule forwards traffic from to

Please note that as traditional port forwarding which apply to POSTROUTING chain, the second rule applies to PREROUTING. This is because we deals with localhost addresses so that POSTROUTING chain of nat table is not crossed by packet.

An for UDP traffic:

iptables -t mangle -A PREROUTING -p UDP --dport 162 -j TEE --gateway
iptables -t nat -A PREROUTING -d -p UDP --dport 162 -j DNAT  --to
  • Ouch looks like redhat 6.9 with version 1.4.7 doesn't have TEE functionality, we don't have module in kernel for that also.
    – Neci
    Jan 26, 2018 at 13:48
  • 1
    Strange, you mentioned TEE in your question and the error looks like a TEE ` --gateway` input error (ipset.netfilter.org/iptables-extensions.man.html#lbDW).
    – vera
    Jan 26, 2018 at 14:38
  • 1
    When testing this on UDP, It appears that the destination IP of the packet is not altered by the TEE rule thereby nullifying the nat rule. Mar 12, 2019 at 22:38
  • 2
    In my test (4.15 kernel), using TEE in PREROUTING causes no change in the packet (source or destination) and thus when you specify any localhost address as the gateway, creates a feedback loop (50Gbps on my machine) Apr 7, 2020 at 17:10
  • Well, this is a very interesting topic. I too had to fan-out SNMPTRAP data and reuse the original collector's IP, while keep forwarding the data to the original collector (that runs Solaris 9). I'm using this as a match in mangle: -A PREROUTING -i ens192 -p udp -m udp --dport 162 -j TEE --gateway and this in nat: -A PREROUTING -p udp -m udp --dport 162 -j DNAT --to, and it works (not sure how, though)... (Centos8, kernel 4.18)
    – user39049
    Sep 22, 2020 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .