1

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

1 Answer 1

0

The iptables rule needs to be defined before the first package is sent by the respective process on port 12345. This solved my problem.

also I tried disabling the firewall ufw disable. Not sure how this affects iptables.

redirect and dnat actually work equally well here

You must log in to answer this question.

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