My ISP has issues with ip assignments. They would re-assign a previous address and the script would think all was good. I needed a better solution.
I looked around and grabbed some ideas from various posts and came up with a script that fixes the issue I had. Here is a copy for everyone to replace the existing ip.sh program. Feel free to make suggestions.
I looked around and grabbed some ideas from various posts and came up with a script that fixes the issue I had. Here is a copy for everyone to replace the existing ip.sh program. Feel free to make suggestions.
Code:
#!/bin/bash
# File to log the IP Address
IPFILE='/var/log/asterisk/externip'
# Your local lan ip block
localnet=192.168.1.0
# Nothing else needs to be changed.
if [ ! -f "$IPFILE" ]; then
echo "creating $IPFILE"
echo first_time_usage > $IPFILE
fi
lastip=`cat $IPFILE`
externip=$(curl -s http://myip.dnsomatic.com/)
if [ $externip != $lastip ]; then
# Writes new IP address (if it has changed) to file.
echo "$externip" > $IPFILE
echo "externip=$externip" > /etc/asterisk/sip_custom.conf
echo "localnet=$localnet/255.255.255.0" >> /etc/asterisk/sip_custom.conf
echo "srvlookup=yes" >> /etc/asterisk/sip_custom.conf
echo "nat=yes" >> /etc/asterisk/sip_custom.conf
asterisk -rx "dialplan reload" ;
else
exit 0;
fi
exit;