Skip to content

Instantly share code, notes, and snippets.

@sodre
Created January 8, 2017 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sodre/23b8e773eff1558439acb0cb05368575 to your computer and use it in GitHub Desktop.
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.
#!/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