Bogey
Regular Contributor
Hi guys,
Selective routing is working brilliant with these two scripts route-up.sh and route-down.sh, both are defined in custom configuration (see below for the code). I found these scripts here, and they don't use the route-nopull directive.
As you can see I have only one 'real' rule active at the moment:
So all traffic to and from my NAS goes through the VPN, except for port 587. These are notification emails via Gmail, and Gmail (temporarily) locks the account when the account is accessed from too different locations (e.g. at one time it's Switzerland, the next time it's from the US - all depending on the VNP server used).
This works, no problem there. Also torrenting with Transmission seems to work. However, I don't think it's done properly as my download speed is low. I suspect this is because there's no specific 'peer-port' assigned (the famous default port 51413). How can I do this? My VPN provider AirVPN offers port forwarding at their servers and I have one assigned. So now I need to open a port on my router and/or redirect traffic?
Q1) How can I get Transmission to see the peer-port as open?
By using port forwarding in the Asus-wrt interface or by adding these (or other) rules to firewall-start script?
It also seems there's no DNS assigned. So when I enter manually a DNS in the WAN DNS Setting, it can find websites, but... isn't this DNS leakage? My guess is, that it is.
My VPN provider AirVPN has DNS servers available, but these are in the 10.x.x.x range, so they only work when the VPN is active.
Q2) So how can I assign DNS servers only for the VPN and use my regular DNS for regular WAN traffic?
Speaking of leakage, I don't have any firewall settings yet. I read the Github page by Rmerlin to add the following to firewall-start:
Q3) So my third question is, will these rules prevent all traffic or should I alter the 3rd line, so email notification via gmail is still possible, to this:
Thanks for your help,
Erwin
route-up.sh :
route-down.sh:
custom configuration:
Selective routing is working brilliant with these two scripts route-up.sh and route-down.sh, both are defined in custom configuration (see below for the code). I found these scripts here, and they don't use the route-nopull directive.
As you can see I have only one 'real' rule active at the moment:
Code:
iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.103 ! --dport 587 -j MARK --set-mark $MARK
This works, no problem there. Also torrenting with Transmission seems to work. However, I don't think it's done properly as my download speed is low. I suspect this is because there's no specific 'peer-port' assigned (the famous default port 51413). How can I do this? My VPN provider AirVPN offers port forwarding at their servers and I have one assigned. So now I need to open a port on my router and/or redirect traffic?
Q1) How can I get Transmission to see the peer-port as open?
By using port forwarding in the Asus-wrt interface or by adding these (or other) rules to firewall-start script?
Code:
iptables -D FORWARD -s 192.168.0.103 -p tcp --dport 51413 -j ACCEPT
iptables -D FORWARD -s 192.168.0.103 -p udp --dport 51413 -j ACCEPT
iptables -I FORWARD -s 192.168.0.103 -p tcp --dport 51413 -j ACCEPT
iptables -I FORWARD -s 192.168.0.103 -p udp --dport 51413 -j ACCEPT
It also seems there's no DNS assigned. So when I enter manually a DNS in the WAN DNS Setting, it can find websites, but... isn't this DNS leakage? My guess is, that it is.
My VPN provider AirVPN has DNS servers available, but these are in the 10.x.x.x range, so they only work when the VPN is active.
Q2) So how can I assign DNS servers only for the VPN and use my regular DNS for regular WAN traffic?
Speaking of leakage, I don't have any firewall settings yet. I read the Github page by Rmerlin to add the following to 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.0.103 -j DROP
iptables -I INPUT -i tun11 -j REJECT
iptables -t nat -A POSTROUTING -o tun11 -j MASQUERADE
Code:
iptables -I FORWARD ! -o tun11 -s 192.168.0.103 ! --dport 587 -j DROP
Thanks for your help,
Erwin
route-up.sh :
Code:
#!/bin/sh -x
(
TID="200"
MARK="0x88"
WS="[[:space:]]"
WAN_GTWY="$route_net_gateway" # provided by OpenVPN at runtime
WAN_IF="$(route | grep -Em1 ^${WAN_GTWY}${WS} | awk '{print $NF}')"
VPN_GTWY="$route_vpn_gateway" # provided by OpenVPN at runtime
VPN_IF="$dev" # provided by OpenVPN at runtime
REDIRECT_GTWY="$redirect_gateway" # provided by OpenVPN at runtime
# copy default/main routing table (exclude all default gateways)
ip route flush table $TID > /dev/null 2>&1
ip route show table main | grep -Ev "^default|^0.0.0.0/1${WS}|^128.0.0.0/1${WS}" \
| while read route; do
ip route add $route table $TID
done
# add VPN as default gateway
ip route add default via $VPN_GTWY table $TID
# add WAN back as default gateway in main/default routing table
if [ "$REDIRECT_GTWY" == "1" ]; then
ip route add 0.0.0.0/2 via $WAN_GTWY
ip route add 64.0.0.0/2 via $WAN_GTWY
ip route add 128.0.0.0/2 via $WAN_GTWY
ip route add 192.0.0.0/2 via $WAN_GTWY
fi
# disable WAN/VPN reverse path filtering
echo 0 > /proc/sys/net/ipv4/conf/$WAN_IF/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/$VPN_IF/rp_filter
# clear the routing cache (or else it won't recognize our changes)
ip route flush cache
# route over VPN based on source IP(s)/network(s) or network interface
#ip rule add from 192.168.0.103 table $TID
# ip rule add from 10.10.1.113 table $TID
# ip rule add from 10.10.2.0/24 table $TID
# ip rule add iif wl0.1 table $TID
# route over VPN based on other criteria (e.g., protocol, source/destination port)
# iptables -t mangle -A PREROUTING -p tcp -s 10.10.1.42 --sport 22 -j MARK --set-mark $MARK
# iptables -t mangle -A PREROUTING -p tcp -s 10.10.1.155 --sport 80 -j MARK --set-mark $MARK
iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.103 ! --dport 587 -j MARK --set-mark $MARK
#iptables -t mangle -A PREROUTING -p tcp ! --dport 2095 -j MARK --set-mark $MARK
# iptables -t mangle -A PREROUTING -s jims-ipod -j MARK --set-mark $MARK
# iptables -t mangle -A PREROUTING -m mac --mac-source 00:11:22:33:44:55 -j MARK --set-mark $MARK
# start processing marked packets through the alternate routing table
ip rule add fwmark $MARK table $TID
) 2>&1 | logger -t $(basename $0)[$$]
route-down.sh:
Code:#!/bin/sh -x ( TID="200" MARK="0x88" WS="[[:space:]]" WAN_GTWY="$route_net_gateway" # provided by OpenVPN at runtime WAN_IF="$(route | grep -Em1 ^${WAN_GTWY}${WS} | awk '{print $NF}')" VPN_GTWY="$route_vpn_gateway" # provided by OpenVPN at runtime VPN_IF="$dev" # provided by OpenVPN at runtime REDIRECT_GTWY="$redirect_gateway" # provided by OpenVPN at runtime # remove routes based on source IP(s)/network(s) or network interface #ip rule del from 192.168.0.103 table $TID # ip rule del from 10.10.1.113 table $TID # ip rule del from 10.10.2.0/24 table $TID # ip rule del iif wl0.1 table $TID # remove routes based on other criteria (e.g., protocol, source/destination port) # iptables -t mangle -D PREROUTING -p tcp -s 10.10.1.42 --sport 22 -j MARK --set-mark $MARK # iptables -t mangle -D PREROUTING -p tcp -s 10.10.1.155 --sport 80 -j MARK --set-mark $MARK iptables -t mangle -D PREROUTING -p tcp -s 192.168.0.103 ! --dport 587 -j MARK --set-mark $MARK #iptables -t mangle -D PREROUTING -p tcp ! --dport 2095 -j MARK --set-mark $MARK # iptables -t mangle -D PREROUTING -s jims-ipod -j MARK --set-mark $MARK # iptables -t mangle -D PREROUTING -m mac --mac-source 00:11:22:33:44:55 -j MARK --set-mark $MARK # stop processing marked packets through the alternate routing table ip rule del fwmark $MARK table $TID # remove WAN as default gateway in main/default routing table if [ "$REDIRECT_GTWY" == "1" ]; then ip route del 0.0.0.0/2 via $WAN_GTWY ip route del 64.0.0.0/2 via $WAN_GTWY ip route del 128.0.0.0/2 via $WAN_GTWY ip route del 192.0.0.0/2 via $WAN_GTWY fi # re-enable WAN/VPN reverse path filtering echo 1 > /proc/sys/net/ipv4/conf/$WAN_IF/rp_filter echo 1 > /proc/sys/net/ipv4/conf/$VPN_IF/rp_filter > /dev/null 2>&1 # clear the alternate routing table and routing cache ip route flush table $TID ip route flush cache ) 2>&1 | logger -t $(basename $0)[$$]
custom configuration:
Code:
script-security 2
route-up /jffs/scripts/route-up.sh
route-pre-down /jffs/scripts/route-down.sh