Hi,
I've done an openvpn-event and firewall-start files to have specific rules for the VPN.
I want :
- NAS Synology on VPN except for some ports,
- TOR port on VPN for all devices,
- Internet Traffic on NAS to stop if VPN connection drops.
It works well except that when i turn off openvpn connection, traffic is still working on my NAS. I guess the problem is with the firewall-start script. Could you please help ?
Here is what i did (using a script found on a forum):
For openvpn-event :
#!/bin/sh
Sleep 2
logger -t "($(basename $0))" $$ ExpressVPN Selective Customization Starting... " $0${*:+ $*}."
DiskStation="192.168.0.2"
ByPassPortList="5000,5001,5100,5101,5005,5006,5010,6690,8001,8801,7101,7001"
VPNPortList="9150"
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
tun_if="tun11"
ip route show table main | grep -Ev ^default | grep -Ev $tun_if \
| while read ROUTE ; do
ip route add table 100 $ROUTE
logger -t "($(basename $0))" $$ ExpressVPN Table 100 added entry: $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
logger -t "($(basename $0))" $$ Selective customisation for: DiskStation
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range $DiskStation -j MARK --set-mark 0
logger -t "($(basename $0))" $$ Routing ports to bypass VPN on all Devices:
iptables -t mangle -A PREROUTING -i br0 -p tcp -m multiport --port $ByPassPortList -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -i br0 -p tcp -m multiport --port $VPNPortList -j MARK --set-mark 0
logger -t "($(basename $0))" $$ ExpressVPN Selective Customization completed.
exit 1
For firewall-start :
ByPassPortList="5000,5001,5100,5101,5005,5006,5010,6690,8001,8801,7101,7001"
iptables -I FORWARD -i br0 -s 192.168.0.2 -o eth0 -j DROP
iptables -I FORWARD -i br0 -s 192.168.0.2 -o eth0 -p tcp -m multiport --port $ByPassPortList -j ACCEPT
Thanx !!
I've done an openvpn-event and firewall-start files to have specific rules for the VPN.
I want :
- NAS Synology on VPN except for some ports,
- TOR port on VPN for all devices,
- Internet Traffic on NAS to stop if VPN connection drops.
It works well except that when i turn off openvpn connection, traffic is still working on my NAS. I guess the problem is with the firewall-start script. Could you please help ?
Here is what i did (using a script found on a forum):
For openvpn-event :
#!/bin/sh
Sleep 2
logger -t "($(basename $0))" $$ ExpressVPN Selective Customization Starting... " $0${*:+ $*}."
DiskStation="192.168.0.2"
ByPassPortList="5000,5001,5100,5101,5005,5006,5010,6690,8001,8801,7101,7001"
VPNPortList="9150"
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
tun_if="tun11"
ip route show table main | grep -Ev ^default | grep -Ev $tun_if \
| while read ROUTE ; do
ip route add table 100 $ROUTE
logger -t "($(basename $0))" $$ ExpressVPN Table 100 added entry: $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
logger -t "($(basename $0))" $$ Selective customisation for: DiskStation
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range $DiskStation -j MARK --set-mark 0
logger -t "($(basename $0))" $$ Routing ports to bypass VPN on all Devices:
iptables -t mangle -A PREROUTING -i br0 -p tcp -m multiport --port $ByPassPortList -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -i br0 -p tcp -m multiport --port $VPNPortList -j MARK --set-mark 0
logger -t "($(basename $0))" $$ ExpressVPN Selective Customization completed.
exit 1
For firewall-start :
ByPassPortList="5000,5001,5100,5101,5005,5006,5010,6690,8001,8801,7101,7001"
iptables -I FORWARD -i br0 -s 192.168.0.2 -o eth0 -j DROP
iptables -I FORWARD -i br0 -s 192.168.0.2 -o eth0 -p tcp -m multiport --port $ByPassPortList -j ACCEPT
Thanx !!