Skip to content

Instantly share code, notes, and snippets.

@iMilnb
Created August 19, 2013 21:10
Show Gist options
  • Save iMilnb/6274243 to your computer and use it in GitHub Desktop.
Save iMilnb/6274243 to your computer and use it in GitHub Desktop.
Update OpenVPN remotes for vpntunnel endpoints with IP addresses instead of FQDN as resolving fails from time to time
#!/bin/sh
[ $# -lt 1 ] && exit 1
tunnel="jenny.vpntunnel.se"
ovpntmp="/tmp/openvpn.conf-tmp"
ovpncnf=$1
host -t a ${tunnel} >/dev/null 2>&1 || exit 1
sed '/^remote\ /d' "${ovpncnf}" > "${ovpntmp}"
for ip in `host -t a ${tunnel}|grep -oE [0-9\.]+$`
do
for port in `seq 7001 7004`
do
echo remote ${ip} ${port} >> "${ovpntmp}"
done
done
cp -f "${ovpntmp}" "${ovpncnf}"
kill -HUP `cat /var/run/openvpn.pid`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment