Created
January 8, 2017 20:32
-
-
Save sodre/23b8e773eff1558439acb0cb05368575 to your computer and use it in GitHub Desktop.
Vyatta / VyOS / EdgeOS script for setting tunnel remote-ip based on a given hostname.
This file contains 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
#!/bin/vbash | |
# sets the tunnel remote-ip based on the supplied host-name. | |
if [ $# == 0 ]; then | |
echo "usage: $0 <tunnel> <host-name>" | |
echo " e.g.: $0 tun0 vpn-01.no-ip.com" | |
exit 1 | |
fi | |
tunnel=$1 | |
hostname=$2 | |
source /opt/vyatta/etc/functions/script-template | |
old_remote_ip=$(cli-shell-api showCfg interfaces tunnel $tunnel remote-ip | cut -d ' ' -f 2) | |
new_remote_ip=$(host $hostname | tail -1 | cut -d ' ' -f 4) | |
if [ "$new_remote_ip" != "$old_remote_ip" ]; then | |
configure | |
set interfaces tunnel $tunnel remote-ip $new_remote_ip | |
commit | |
save | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment