mercoledì 11 giugno 2014

Dynamically update externip without Dyndns.org or similar

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

#!/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

# crontab -e

* * * * * /root/./spinach.sh

From now on, your sip.conf externip=* directive will be checked every minute.

Note: reloading Sip should not drop any outgoing or incoming call!

Nessun commento:

Posta un commento