I want to redirect outgoing packages from my machine on port 12345
for modification to another process instead (netsed
), which will then send them to their target.
I can drop outgoing packages using iptables -A OUTPUT -p tcp --dport 12345 -j DROP
. Thus, no more packages are being sent via 12345
.
For redirecting them to netsed, it seems I need to use NAT table and DNAT:
iptables -t nat -A OUTPUT -p tcp --dport 12345 -j DNAT --to-destination 127.0.0.1:$netsed_port
Is this the right approach?
Because it doesn't work: It does not stop outgoing packages from reaching their original, remote target. It should, right? Shouldn't redirecting them into a dead end equal dropping them? Also, I am not receiving any packages at netsed's port.
/ using REDIRECT does not help either: iptables -t nat -A OUTPUT -p tcp --dport 12345 -j REDIRECT --to-port $netsed_port