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
vlan0specified. I want something that can work regardless of the what the IP address is. – DrownedSuccess Apr 28 '22 at 18:16echo "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