Spinach.v0.11, Dynamic Sip Nat without Dyndns.org or similar

Hi to all Asterisk enthusiasts

About a month ago, Dyndns.org shut down his free dynamic dns service, disrupting service to hundreds of thousands of home server installations, shame on them!

Many Asterisk setups relied on this to overcome nat problems with dynamically assigned WAN ips (using the externhost=xyz.dyndns.org directive)

Here’s a tiny shell script to automatically update your externip directive from sip.conf reflecting your actual WAN ip address:

nano /root/spinach.sh

wanip=`curl -q tnx.nl/ip` sed -i 's/externip=.*/externip='"$wanip"'/' /etc/asterisk/sip.conf asterisk -rx 'sip reload'

crontab -e

From now on, your sip.conf externip=a.b.c.d directive will be updated every minute.
Any comments would be highly appreciated!

Nice idea, but at least the script should check whether the IP has changed or not - probably by saving the actual IP to a file. This will avoid non necessary reloads.

#!/bin/bash
doreload=0
wanip=`curl -q tnx.nl/ip`
if [ -f /tmp/oldip.txt ]; then
   oldip=`cat /tmp/oldip.txt`
   [ "$wanip" != "$oldip" ] && doreload=1
else
   doreload=1
fi
echo $wanip > /tmp/oldip.txt
if [ $doreload -eq 1 ]; then
      sed -i 's/externip=.*/externip='"$wanip"'/' /etc/asterisk/sip.conf
      asterisk -rx 'sip reload'
fi

Really true!
Thank you for your reply!
We got spinach.sh v0.11 from Olaf Winkler:

#!/bin/bash doreload=0 wanip=`curl -q tnx.nl/ip` if [ -f /tmp/oldip.txt ]; then oldip=`cat /tmp/oldip.txt` [ "$wanip" != "$oldip" ] && doreload=1 else doreload=1 fi echo $wanip > /tmp/oldip.txt if [ $doreload -eq 1 ]; then sed -i 's/externip=.*/externip='"$wanip"'/' /etc/asterisk/sip.conf asterisk -rx 'sip reload' fi

PS. if TNX.NL is down you still got a few backup sites:
whatismyip.org
icanhazip.com
myip.dnsomatic.com
ip.appspot.com
checkip.dyndns.org:8245
whatismyip.com
jsonip.com

(you may easily run your own “backup site”!!!)

Thank you!