Difference between revisions of "Script for connecting to openVPN and updating nameserver appropriately"
From Notes_Wiki
m |
m |
||
Line 1: | Line 1: | ||
<yambe:breadcrumb self=" | <yambe:breadcrumb self="Script for connecting to openVPN and updating nameserver appropriately">Useful bash shell scripts|Useful bash shell scripts</yambe:breadcrumb> | ||
=Script for connecting to openVPN and updating nameserver appropriately= | =Script for connecting to openVPN and updating nameserver appropriately= | ||
Line 34: | Line 34: | ||
<yambe:breadcrumb self="Script for connecting to openVPN and updating nameserver appropriately">Useful bash shell scripts|Useful bash shell scripts</yambe:breadcrumb> | |||
Revision as of 09:11, 25 January 2019
<yambe:breadcrumb self="Script for connecting to openVPN and updating nameserver appropriately">Useful bash shell scripts|Useful bash shell scripts</yambe:breadcrumb>
Script for connecting to openVPN and updating nameserver appropriately
Following script can be used for connecting to openVPN and updating nameserver appropriately:
#!/bin/bash sudo /sbin/service openvpn start echo "Waiting for connection establishment to complete" STATUS=$(ifconfig | grep '10\.7\.1\.1') while [[ "$STATUS" = "" ]]; do echo -n "."; sleep 1 STATUS=$(ifconfig | grep '10\.7\.1\.1') done echo "Connection successful" echo "Going to replace nameserver" sudo mv /etc/resolv.conf /etc/resolv.conf.backup echo "nameserver 10.4.3.222" > /tmp/resolv.conf sudo mv /tmp/resolv.conf /etc/resolv.conf echo "Nameserver replaced" echo "Press enter to disconnect..." read A sudo /sbin/service openvpn stop echo "Going to restore nameserver" sudo mv /etc/resolv.conf.backup /etc/resolv.conf echo "Nameserver restored" exit 0
Note:
- The script assumes that after successful connection client would get IP 10.7.1.1. Replace the "grep '10\.7\.1\.1'" line with appropriate condition such as "ifconfig | grep -A 1 tun0 | grep 'inet addr'" for the case.
- The script assumes nameserver to be configured is 10.4.3.222. This should be replaced with correct nameserver based on situation.
<yambe:breadcrumb self="Script for connecting to openVPN and updating nameserver appropriately">Useful bash shell scripts|Useful bash shell scripts</yambe:breadcrumb>