I got tired of updating Asterisk’s externip setting every time my IP address changed, so I wrote this quick script, saved as /usr/local/bin/asterisk_update_externip:
#!/bin/bash
ip_url="http://automation.whatismyip.com/n09230945.asp"
oldip=`grep externip /etc/asterisk/sip.conf |sed 's/;.*//' |grep -v ^$ |sed s/.*=\ *//`
ip=`curl -s "$ip_url" |head -n 1`
if [ "$oldip" != "$ip" ]
then
#echo "Updating IP"
sed -i "s/externip = $oldip/externip = $ip/" /etc/asterisk/sip.conf
asterisk -r -x "core reload"
fi
I put it in /etc/cron.d/asterisk-externip as follows:
# Update Asterisk's SIP External IP 3,8,13,18,23,28,33,38,43,48,53,58 * * * * root asterisk_update_externip
Enjoy!
