IPTables
From Leo's Notes
This page was last edited on 12 May 2013, at 00:57.
Redirect Outgoing Traffic to Local Port
To redirect traffic destined to 1.2.3.4:443 to localhost:8080, use the REDIRECT directive:
iptables -t nat -A OUTPUT -p tcp -d 1.2.3.4 --dport 443 -j REDIRECT --to-ports 8080
If you want to redirect traffic to a particular destination rather than 127.0.0.1 (or the primary interface's IP) use DNAT:
iptables -t nat -A OUTPUT -p udp -d 1.2.3.4 --dport 443 -j DNAT --to-destination 9.8.7.6:8080