While I was writing a post on how to route specific WEB traffic through VPN, I’ve got inspired and decided to another post on how to route specific devices (your NAS server, laptop, iPhone, etc) through your VPN while the rest of your house still use the old ISP gateway. This kind of approach might be more interesting as not always your VPN connection is good enough to hold your entire network, or maybe some websites dont work properly behind a VPN, etc
Just like before, the idea behind this post is creating a Firewall alias on your pfSense and then modify your LAN firewall rules to switch to a different gateway (the VPN gateway) when the specified devices are detected.
A requirement for this post is to create a firewall alias called RFC1918 as discussed in a previous post. I will assume your VPN interface is OPT1, but you can use a different name.
Navigate to Firewall >> Aliases >> IP and click on Add and do as follows:
- Name: DEVICES_BEHIND_VPN_USA
- Description: List of IPs/Hostnames that must be routed through US VPN for privacy
- Type: Host(s)
- IP or FQDN: Here you add the IP or hostname you want to hide behind the VPN
If you want to add more devices, click on Add Host and add the IP/FQDN.
When you are done, click on Save and Apply changes. Now we need to update your firewall rules to use this list of devices to decide which gateway your traffic goes through.
Go to Firewall >> Rules >> LAN and look carefully to the existing rules. At the bottom there will be a PASS ALL rule, which allows traffic o go from LAN from any port/protocol to any destination IP/port. The trick is to add our new rule right before the pass all rule. That is because the pass all rule tunnel traffic coming from all devices through the WAN gateway, so we need to create a rule that sends traffic from the specific devices to OPT1 (or however you named your VPN gateway interface) before.
Next, click on Add to create a new firewall rule:
- Edit Firewal rule
- Action: Pass
- Address Family: IPv4 (I am not using IPv6 on my homelab yet)
- Protocol: Any
- Select “Single host or alias“
- Type “DEVICES_BEHIND_VPN_USA” as source address
- Invert match: checked
- Select “Single host or alias”
- Type “RFC1918” as destination address
- Extra options
- Log: unchecked
- Description: Force DEVICES_BEHIND_VPN_USA devices to go through OPT1 to reach Internet
- Advanced options
- Leave everything as is
- Gateway: Select OPT1
Press Save and Apply changes. After a couple seconds, traffic coming from the DEVICES_BEHIND_VPN_USA devices will be routed trough your VPN tunnel.
One trick that I use to test is adding my cellphone or laptop to DEVICES_BEHIND_VPN_USA and then visit myip.com and check that the IP listed is not my ISP’s but the one from my VPN provider.
That is it and safe browsing!