macoshttp-redirectnetwork-programmingtcpproxy

How to redirect an outgoing traffic to another address?


I'd like to redirect specific outgoing TCP traffic to another address.

Say I have an application that tries to establish a connection to a server aaa.bbb.ccc.ddd:99999.

What I am trying to do is to redirect the application's outgoing traffic to another address (e.g., ddd.eee.fff.ggg:88888) without touching the application. Is this possible in Windows or Mac OS X?

Thanks


Solution

  • There two cases here:

    First if you have fqdn, it's easy you just have to resolve it to a different ip via the local hosts file.

    Second if the application is trying to reach specific ip address it's not so simple, and i will mention a way to do it on the system and one without changing anything on the system.

    Within the system you have to modify local firewall. I will write you an example command from iptables which works on linux systems but sth equivalent you can apply with the software MacOS (pf see the edit on the end) and Windows have installed. What i do below, is to NAT the IP i want to change, to a new IP.

    iptables -t nat -A OUTPUT -p tcp -d IP_YOU_WANT_REWRITE --dport PORT -j DNAT --to-destination NEW_IP:NEW_PORT

    In case now you don't want to mess with the host machine at all you can apply a similar NAT rule on your gateway/router, you just NAT the IP you want to change to the new one on the router configuration and your host reach the new one transparently.

    edit: As far as i can see osx equivalent to iptables is pf so you need to write a similar rule using the nat command.