I seem to have tried and tweaked several bastardizations of scripts.
I'd like to be able to have my main workstation VPN everything, except SSH (as that doesn't work at all with VPN).
This client has an IP address of 192.168.2.3 (Static/Manual DHCP), and Port 22003 is forwarded to go to Port 22. This works fine without VPN.
These would be the scripts, if no port bypass were needed, and that seemed to work (however, this can be achieved without scripts via Policy Routing in the GUI). This will VPN all of 192.168.2.3 but SSH into that machine over WAN will fail.
Script: /jffs/scripts/openvpn-event
Script: /jffs/scripts/firewall-start
Permissions are fine and JFFS is setup as needed, and all port forwards and connection works without VPN enabled. So far, nothing I've tried by marking Port 22 (or 22003) as source or destination seems to work (but I'm not sure if I'm being burned by priority of the rules or something).
I would like to expand this to multiple SSH machines. I use PIA as VPN, and they only allow one port, and it should be possible to avoid that if my router will just not use the VPN for specific ports. Several topics I've browsed indicate that this is possible
I'd like to be able to have my main workstation VPN everything, except SSH (as that doesn't work at all with VPN).
This client has an IP address of 192.168.2.3 (Static/Manual DHCP), and Port 22003 is forwarded to go to Port 22. This works fine without VPN.
These would be the scripts, if no port bypass were needed, and that seemed to work (however, this can be achieved without scripts via Policy Routing in the GUI). This will VPN all of 192.168.2.3 but SSH into that machine over WAN will fail.
Script: /jffs/scripts/openvpn-event
Code:
#!/bin/sh
sleep 2
for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do
echo 0 > $i
done
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
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
iptables -t mangle -A PREROUTING -i br0 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 192.168.2.3 -j MARK --set-mark 0
exit 1
Script: /jffs/scripts/firewall-start
Code:
#!/bin/sh
sleep 4
iptables -I FORWARD -i br0 -o tun11 -j ACCEPT
iptables -I FORWARD -i tun11 -o br0 -j ACCEPT
iptables -I FORWARD ! -o tun11 -s 192.168.2.3 -j DROP
iptables -I INPUT -i tun11 -j REJECT
iptables -t nat -A POSTROUTING -o tun11 -j MASQUERADE
Permissions are fine and JFFS is setup as needed, and all port forwards and connection works without VPN enabled. So far, nothing I've tried by marking Port 22 (or 22003) as source or destination seems to work (but I'm not sure if I'm being burned by priority of the rules or something).
I would like to expand this to multiple SSH machines. I use PIA as VPN, and they only allow one port, and it should be possible to avoid that if my router will just not use the VPN for specific ports. Several topics I've browsed indicate that this is possible