Advertisement
the-technoholik

OpenVPN connect with DNS configuration

Feb 13th, 2015
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.54 KB | None | 0 0
  1. #!/bin/sh -e
  2.  
  3. script_dir="`dirname $0`"
  4. vpnconfig="client.conf"
  5. vpnlog="openvpn.log"
  6. vpnpidfile="openvpn.pid"
  7. vpnconnecttime="5" # seconds
  8. vpnresolvconf="resolv.conf"
  9. systemresolvconf="/etc/resolv.conf"
  10.  
  11. if ! cd $script_dir ; then
  12.     echo "Cannot cd to $script_dir." 1>&2
  13.     exit 1
  14. fi
  15.  
  16. sudo echo "Launching OpenVPN..."
  17.  
  18. sudo openvpn $vpnconfig > $vpnlog &
  19.  
  20. sleep 1 # wait for sudo to launch command
  21.  
  22. vpnpid=$(ps --ppid $! -o pid=)
  23.  
  24. echo $vpnpid > $vpnpidfile
  25.  
  26. sleep $vpnconnecttime
  27.  
  28. sudo cp $vpnresolvconf $systemresolvconf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement