Hi, sorry for the probably stupid question. I have an AC66 with Merlin 380.59.
I have a PIA VPN account.
My goal is to have the router connect to this VPN account, and then send exclusively port 80 and 443 traffic through the VPN, and nothing else. All other traffic proceeds by the normal gateway. This is probably the opposite of what most people want to do and Ive struggled to find information for this purpose and configuration.
My goal is to have the router connect to this VPN account, and then send exclusively port 80 and 443 traffic through the VPN, and nothing else. All other traffic proceeds by the normal gateway
Ensure you have enabled 'Redirect Internet traffic=Policy Rules' in the VPN Client GUI used for the PIA connection.
Manually issue the following commands via SSH replacing '?' with the appropriate VPN Client instance.
Code:
ip rule del fwmark 0x?000
ip rule add fwmark 0x?000 table 11? prio 999?
ip route flush cache
iptables -t mangle -D PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
iptables -t mangle -A PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
Once you are satisfied it works, (https://ipleak.net from any LAN/WiFi device) permanently add them to /jffs/scripts/nat-start.
NOTE: The above PREROUTING rule applies to ALL devices except the router itself, e.g. 'curl' commands etc. on the router will always be routed via the WAN. If all http/https traffic is to be routed via the WAN, then the PREROUTING rule will need to be changed.
The '-D' means delete, so it ensures that unnecessary duplicate rules are not created by the '-I' insert command if/when the nat-start script is re-run.
You can always find another VPN provider. I have no issues when using some servers from Astrill for Netflix and none with any of the StrongVPN servers I have used.
Thanks ill have a look. For now a simpler solution would be to just exempt the IP of my TV as thats the only device we use netflix for. I've tried to add a new route for packets from that TV but so far I can't get it to work.
For the purposes of helping anyone else, I got it working using this code ;
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 -D PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0/0
iptables -t mangle -A PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0/0
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 192.168.0.67 -j MARK --set-mark 1
exit 1
Packets marked with 1 are sent via the WAN. Packets marked via 0 are sent through the VPN. In this example, 192.168.0.67 (my tv) is marked 1 and is sent via WAN.
For the purposes of helping anyone else, I got it working using this code ;
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 -D PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0/0
iptables -t mangle -A PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0/0
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 192.168.0.67 -j MARK --set-mark 1
exit 1
Packets marked with 1 are sent via the WAN. Packets marked via 0 are sent through the VPN. In this example, 192.168.0.67 (my tv) is marked 1 and is sent via WAN.
I propose that the following technique addresses the custom edge case requirements of the OP.
Code:
# All LAN/WiFi device http/https requests will use the VPN, but device xxx.xxx.xxx.xxx will be excluded and use the WAN
ip rule del fwmark 0x7000
ip rule add fwmark 0x7000 table 254 prio 9990
ip rule del fwmark 0x?000
ip rule add fwmark 0x?000 table 11? prio 999?
ip route flush cache
iptables -t mangle -D PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
iptables -t mangle -A PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
iptables -t mangle -D PREROUTING -i br0 -s xxx.xxx.xxx.xxx -p tcp -m multiport -j MARK --set-mark 0x7000/0x7000
iptables -t mangle -A PREROUTING -i br0 -s xxx.xxx.xxx.xxx -p tcp -m multiport -j MARK --set-mark 0x7000/0x7000
and FWMARK 0x7000 will use the WAN and FWMARK 0x?000 will use the VPN instance identified by '?'
I did consider inserting RPDB FWMARK rules within the individual VPN Client ranges as allocated by RMerlin's vpnrouting.sh script i.e. PRIO 1000-2000 (or lower 3000?) rather than using PRIO 9990-9005 which would then still allow use of the GUI Policy Rules for subnet/device selective routing as alluded to by @Xentrk but for my purposes I decided to make the Selective Port Routing have a higher priority than the Selective Routing Policy Rules.
I propose that the following technique addresses the custom edge case requirements of the OP.
Code:
# All LAN/WiFi device http/https requests will use the VPN, but device xxx.xxx.xxx.xxx will be excluded and use the WAN
ip rule del fwmark 0x7000
ip rule add fwmark 0x7000 table 254 prio 9990
ip rule del fwmark 0x?000
ip rule add fwmark 0x?000 table 11? prio 999?
ip route flush cache
iptables -t mangle -D PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
iptables -t mangle -A PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
iptables -t mangle -D PREROUTING -i br0 -s xxx.xxx.xxx.xxx -p tcp -m multiport -j MARK --set-mark 0x7000/0x7000
iptables -t mangle -A PREROUTING -i br0 -s xxx.xxx.xxx.xxx -p tcp -m multiport -j MARK --set-mark 0x7000/0x7000
and FWMARK 0x7000 will use the WAN and FWMARK 0x?000 will use the VPN instance identified by '?'
I did consider inserting RPDB FWMARK rules within the individual VPN Client ranges as allocated by RMerlin's vpnrouting.sh script i.e. PRIO 1000-2000 (or lower 3000?) rather than using PRIO 9990-9005 which would then still allow use of the GUI Policy Rules for subnet/device selective routing as alluded to by @Xentrk but for my purposes I decided to make the Selective Port Routing have a higher priority than the Selective Routing Policy Rules.
Sorry for my noobness but could you please correct where I'm wrong.
- I'm using VPN Client 1 so I should put 1 for all "?" right?
- and put this script to nat-start with starting "#!/bin/sh" and make it executable of course.
- I should also enable Start with WAN my VPN Client 1 and select Redirect Internet traffic as Policy Rules.
but when I run;
admin@Fatiii:/tmp/home/root# ip rule del fwmark 0x7000
RTNETLINK answers: No such file or directory
Ensure you have enabled 'Redirect Internet traffic=Policy Rules' in the VPN Client GUI used for the PIA connection.
Manually issue the following commands via SSH replacing '?' with the appropriate VPN Client instance.
Code:
ip rule del fwmark 0x?000
ip rule add fwmark 0x?000 table 11? prio 999?
ip route flush cache
iptables -t mangle -D PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
iptables -t mangle -A PREROUTING -i br0 ! -s $(nvram get lan_ipaddr) -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x?000/0x?000
Once you are satisfied it works, (https://ipleak.net from any LAN/WiFi device) permanently add them to /jffs/scripts/nat-start.
NOTE: The above PREROUTING rule applies to ALL devices except the router itself, e.g. 'curl' commands etc. on the router will always be routed via the WAN. If all http/https traffic is to be routed via the WAN, then the PREROUTING rule will need to be changed.
Technically yes...although can use the far easier VPN GUI option to set 'Accept DNS configuration=EXCLUSIVE' (depending on your requirements) to add entries to the DNSVPN? chain instead of using the fwmark technique.
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.