Created
March 20, 2020 09:43
-
-
Save moraisaugusto/eac4cf5c2895640e34ba6a513a5a6598 to your computer and use it in GitHub Desktop.
openvpn - handle dns entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# alternative to: openvpn-update-resolv-conf: aur package | |
# I don't want to install a openvpn script to just handle dns entries for a VPN connection | |
# So, I created this script to do it | |
if ps ax | grep "openvpn --config" | grep "OPENVPN_CONFIG_PROVIDED_BY_COMPANY.ovpn" > /dev/null | |
then | |
echo "VPN CONNECTED" | |
echo "restoring resolv.conf..." | |
sudo sed -i '/DNS_SERVER_IP/d' /etc/resolv.conf | |
echo "disconnecting from vpn..." | |
sudo killall openvpn | |
else | |
echo "VPN DISCONNECTED" | |
echo "changing resolv.conf..." | |
sudo sed -i "2i nameserver DNS_SERVER_IP" /etc/resolv.conf | |
echo "connecting to vpn" | |
cd $HOME/.vpn | |
sudo openvpn --config /etc/openvpn/client/OPENVPN_CONFIG_PROVIDED_BY_COMPANY.ovpn | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment