0

On Linux, I can use iptables to cause any incoming requests $FROM destined for some IP address to go to another $TO, regardless of whether $FROM and/or $TO where actually on the interface, or even registered on either of my address (for example, I can make any request for 2.2.2.2 to go to 8.8.8.8). Is it possible to do this on MacOS, either with pfctl or some other tool?

Here is my attempt: echo "rdr pass inet proto {tcp, udp} from any to 2.2.2.2 port 1:3000 -> 127.0.0.1" | sudo pfctl -ef -

EDIT: This works if $TO=127.0.0.1:

printf "rdr pass inet proto {tcp, udp} from any to 2.2.2.2 port 1:3000 -> 127.0.0.1\npass out route-to (lo0 127.0.0.1) from any to 2.2.2.2\n" | sudo pfctl -ef -

However, I can't seem to find a way to extend it to any $TO

bmike
  • 235,889
  • Something like https://apple.stackexchange.com/questions/363099/how-to-forward-traffic-from-one-machine-to-another-with-pfctl?rq=1 ? – nohillside Apr 28 '22 at 18:15
  • I have looked at it, but all of the machines was on the same LAN, and the top answer have vlan0 specified. I want something that can work regardless of the what the IP address is. – DrownedSuccess Apr 28 '22 at 18:16
  • Well, did you try to adapt it to your setup? – nohillside Apr 28 '22 at 18:20
  • I did: here's what I tried --- echo "rdr pass inet proto {tcp, udp} from any to 2.2.2.2 port 1:3000 -> 127.0.0.1" | sudo pfctl -ef -. It didn't work. – DrownedSuccess Apr 28 '22 at 18:22

0 Answers0