Skip to content

Instantly share code, notes, and snippets.

@gmvi
Last active July 19, 2017 09:20
Show Gist options
  • Save gmvi/5fac1fa1c044f7899c97a648806316cc to your computer and use it in GitHub Desktop.
Save gmvi/5fac1fa1c044f7899c97a648806316cc to your computer and use it in GitHub Desktop.
OpenVPN setup (these live in /etc/openvpn)
client
dev tun
proto udp
remote nl.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca /etc/openvpn/ca.crt
tls-client
remote-cert-tls server
auth-user-pass /etc/openvpn/login.txt
comp-lzo
verb 1
reneg-sec 0
crl-verify /etc/openvpn/crl.pem
script-security 2
route-noexec
up /etc/openvpn/up.sh
down /etc/openvpn/down.sh
#!/bin/sh
exit 0
[username redacted]
[password redacted]
#!/bin/sh
echo "$dev : $ifconfig_local -> $ifconfig_remote gw: $route_vpn_gateway"
table_name="custom_table"
# make sure the ip table exists
if ! grep -q "^10 $table_name$" /etc/iproute2/rt_tables ; then echo "10 $table_name" >> /etc/iproute2/rt_tables; fi
# clear old ip rules
while ( ip rule del table $table_name ); do true; done
# write ip route and rules
ip route add default via $route_vpn_gateway dev $dev table $table_name
ip rule add from $ifconfig_local/32 table $table_name
ip rule add to $route_vpn_gateway/32 table $table_name
ip route flush cache
# shutdown transmission-daemon while editing the settings file
systemctl stop transmission-daemon
# TODO: replace hackey `sed` parsing with `jq`
sed -ri 's/(bind-address-ipv4":\s)"[^"]*"/\1"'"$ifconfig_local"'"/g' /etc/transmission-daemon/settings.json
systemctl start transmission-daemon
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment