
I have a mac that’s connected to a VPN, where the VPN’s gateway is the system’s default gateway for all outgoing traffic. This means that I cannot connect to any services running on my mac from outside of my local network, even when port forwarding is set up correctly on my router, because the source IP address of the connection will be a non-local IP and therefore the system will try to route it through the VPN, not through my local gateway.
However, I think it might be possible to use pf to route this traffic differently based on its port number. What I’d want is to have the default gateway for a connection on a specific port to be my local gateway, rather than the VPN.
Is it possible to do this? If so, how would I configure pf to do so? (Perhaps it’s possible to use pf to select a different routing table for the connection based on its port?)