I'm running Debian 8
with iptables
.
I have the following rule:
iptables -t mangle -A PREROUTING -p tcp --dport 5000 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 4000
I simply want to redirect all traffic going with destination port 5000 to port 4000.
The standard iptables
REDIRECT
is not usable in my case, as it alters the packet and changes the original destination port.
Looking at iptables -t mangle -nvL
I can see the rule being hit:
Chain PREROUTING (policy ACCEPT 5056 packets, 13M bytes)
pkts bytes target prot opt in out source destination
12 720 TPROXY tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:5000 TPROXY redirect 0.0.0.0:4000 mark
0x1/0x1
But my service running on port 4000
doesn't intercept the packets.
I have a simple NodeJS
application listening for all TCP
on port 4000
, which doesn't get any packets
:
server.listen(4000, () => { console.log('listening on 4000'); });
Also, running wireshark
on TCP
port 4000 on all interfaces doesn't show anything.