0

I want to redirect the tcp traffic temporarily to a custom port. On Linux, I use the following command:

iptables -t nat -A OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT

and to reverse the changes:

iptables -t nat -D OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT

They work just fine on Linux but sadly not on OS X. Can someone please give me the equivalent commands or methods that will work on OS X 10.9?

Matteo
  • 8,097
  • 3
  • 47
  • 58
shobhu
  • 103

1 Answers1

0

Everytime I try extending a configuration for pf from OpenBSD (which I use regularly) to MacOS, I fail miserably, so this time I will spare myself (and you) some embarrassment by skipping this step, and giving you a solution which uses socat, which you can install from macports (see here to learn more about macports and how to use it).

Basically, it is as simple as:

  sudo port install socat

and from there

  socat TCP-LISTEN:8888,fork TCP:www.nytimes.com:80 

This redirects port 8888 (protocol TCP) to the New York Times' port 80. If you want to redirect to yourself, substitute www.nytimes.com with localhost*.

MariusMatutiae
  • 48,517
  • 12
  • 86
  • 136