I know OpenVPN automatically updates the routing tables when connecting but I want to write a script to update them myself. I've learned about OpenVPN's “--route-noexec” argument to prevent the automatic updates and the “--route-up” argument to pass relevant information via environment variables to a script of my choice.
This is where I run into trouble. I'd expect environment variables to be passed to the script, which happens, but it looks like I'm missing a few. Especially the one that lists my remote IP address, (untrusted/trusted_ip I believe) which makes it difficult to set iproute.
The environment variables my scripts receives are as follows:
Code: Select all
dev_type=tun
proto_1=udp
tun_mtu=1500
script_type=route-up
verb=1
local_port_1=1194
dev=tun0
remote_port_1=1194
PWD=/tmp
daemon=0
SHLVL=1
script_context=init
daemon_start_time=1409367799
daemon_pid=927
daemon_log_redirect=0
link_mtu=1500
_=/usr/bin/printenv
Code: Select all
sudo openvpn --dev tun --route-noexec --script-security 2 --route-up /tmp/print.sh
Code: Select all
#!/bin/bash
printenv