1
I have setup OpenVPN on a raspberry pi and wrote some scripts that contain various things like adding/removing iptable rules as well as killing/starting up applications.
here is my openvpn configuration file:
client
dev tun
proto udp
route-up route-up.sh
down down.sh
remote chi.central.usa.torguardvpnaccess.com 1912
remote ny.east.usa.torguardvpnaccess.com 1912
remote la.west.usa.torguardvpnaccess.com 1912
remote lon.uk.torguardvpnaccess.com 1912
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-auth ta.key 1
auth SHA256
cipher AES-128-CBC
remote-cert-tls server
auth-user-pass user.txt
comp-lzo
verb 1
reneg-sec 0
fast-io
# Uncomment these directives if you have speed issues
;sndbuf 393216
;rcvbuf 393216
;push "sndbuf 393216"
;push "rcvbuf 393216"
here are my two scripts: route-up.sh
#!/bin/sh
sleep 10
sudo ip rule add from 192.168.0.133 table 10
sudo ip route add default via 192.168.0.1 table 10
sudo iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE
sudo iptables -A INPUT -d mydns.duckdns.org -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -d mydns.duckdns.org -j DROP
sudo -u pi deluged
PID=$!
sleep 3
kill -2 $PID 2>/dev/null
down.sh
#!/bin/sh
sudo pkill deluged
sudo iptables -t nat -D POSTROUTING -o tun0 -j MASQUERADE
So my question is... How do I test that these work correctly? I have read OpenVPN's documentation and I realize in theory this works, that when the VPN disconnects for whatever reason, it will execute "down.sh" and when it reconnects, it will execute "route-up.sh". But is there a way to simulate a VPN disconnect for testing purposes? I know I can "sudo pkill openvpn" but that kills the whole tunnel and won't execute those scripts.
I appreciate any help and suggestions! Thanks everyone!