I've recently added a second VPN to my setup, with the hope to setup policy routing between them, and still be able to make certain traffic (SSH) always use WAN.
I've been using PIA for my main VPN, but wanted to try AirVPN as the second.
I have my VPN configured as follows (VPN 1):
https://imgur.com/dbkqao4
I've been using this script to make SSH go over the WAN, and it has worked with the GUI for picking clients.
The kill switch works as intended. I can VPN my WAN from another location, even after turning off, and curl icanhazip.com fails to connect as expected if I turn off the VPN manually.
I had VPN #2 working, but it was inconsistently working, not applying when it should, etc, or it would just drop out into the WAN leaking my IP outright.
I would need a setup that would let me redirect by IP to either VPN, while still being able to let SSH work, and the kill switch work on either WAN. Has anyone had any luck? It took me forever to get SSH working last time.
I've been using PIA for my main VPN, but wanted to try AirVPN as the second.
I have my VPN configured as follows (VPN 1):
https://imgur.com/dbkqao4
I've been using this script to make SSH go over the WAN, and it has worked with the GUI for picking clients.
Code:
#!/bin/sh
for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do
echo 0 > $i
done
#
# Delete table 100 and flush any existing rules if they exist.
#
ip route flush table 100
ip route del default table 100
ip rule del fwmark 1 table 100
ip route flush cache
iptables -t mangle -F PREROUTING
#
# Copy all non-default and non-VPN related routes from the main table into table 100.
# Then configure table 100 to route all traffic out the WAN gateway and assign it mark "1"
#
# NOTE: Here I assume the OpenVPN tunnel is named "tun11".
#
#
ip route show table main | grep -Ev ^default | grep -Ev tun11 \
| while read ROUTE ; do
ip route add table 100 $ROUTE
done
ip route add default table 100 via $(nvram get wan_gateway)
ip rule add fwmark 1 table 100
ip route flush cache
#
# Define the routing policies for the traffic. The rules will be applied in the order that they
# are listed. In the end, packets with MARK set to "0" will pass through the VPN. If MARK is set
# to "1" it will bypass the VPN.
#
# SSH Traffic: Bypass VPN
iptables -t mangle -A PREROUTING -i br0 -p tcp --sport 22 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -i br0 -p udp --sport 22 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -i br0 -p tcp --dport 22 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -i br0 -p udp --dport 22 -j MARK --set-mark 1
The kill switch works as intended. I can VPN my WAN from another location, even after turning off, and curl icanhazip.com fails to connect as expected if I turn off the VPN manually.
I had VPN #2 working, but it was inconsistently working, not applying when it should, etc, or it would just drop out into the WAN leaking my IP outright.
I would need a setup that would let me redirect by IP to either VPN, while still being able to let SSH work, and the kill switch work on either WAN. Has anyone had any luck? It took me forever to get SSH working last time.