dyndns and sip_nat.conf

fredo
Posts: 56
Member Since:
2006-06-08

With the Gizmo5 module, I was trying to enable inbound calling and was having issues with no audio. I got all the right ports forwarded (UPD 5004, 5060, 10000-20000) and then setup sip_nat.conf. Unfortunately, the externhost=xxx.dyn.dns.org does not seem to work. I f I set it as externip=xxx.xxxx.xxx.xxx then it works perfectly. Since it's dynamically updating (and not managed by the trixbox, but by my firewall) one suggestion was to use a cron job and shell script to update the sip_nat.conf file with the new ip. I searched around but couldn't find anyone with an example so I hacked a script I found (source - http://www.brandonhutchinson.com/DynDNS_update_script.html).

So, for anyone interested, below is the shell script that will update your sip_nat.conf.
You'll need to install 2 things for this to work so first:
yum install lynx bind-utils

Save the shell script somewhere (I saved it as /root/update_dyndns.sh) and set it's permissions to 755.
Be sure to change xxx.xxx.xxx.xxx to be your localnet settings.
Then set up a cron job (install and use webmin to make this easier) to run this script hourly.

#!/bin/sh

# get current ip of the router
CURRENT_IP=`/usr/bin/lynx -dump <a href="http://www.netins.net/dialup/tools/my_ip.shtml" title="http://www.netins.net/dialup/tools/my_ip.shtml">http://www.netins.net/dialup/tools/my_ip.shtml</a> | grep -A2 "Your current IP Address is:" | tail -n1 | tr -d ' '`

# update the sip_nat.conf and re-read configs
echo "externip=$CURRENT_IP
localnet=xxx.xxx.xxx.xxx/255.255.255.0" > /etc/asterisk/sip_nat.conf
chown asterisk.asterisk /etc/asterisk/sip_nat.conf
asterisk -rx reload



SkykingOH
Posts: 9537
Member Since:
2007-12-17
Handy, but it will only be

Handy, but it will only be picked up on a reload.

externhost instead of externip takes care of this for you.

--

Scott

aka "Skyking"



fredo
Posts: 56
Member Since:
2006-06-08
Scott, Please note that the

Scott,

Please note that the reload command is in the script.
Also, the whole point is that externhost *totally* failed to work for me.



SkykingOH
Posts: 9537
Member Since:
2007-12-17
I saw the reload, not sure I

I saw the reload, not sure I would want a script running a reload every 30 minutes. I should have chosen my words my carefully.

How difficult would it be to store the IP and only reload if the IP updates?

IAX2 does not refresh the host so triggering s script to restart IAX also on IP change would be very handy.

Thanks again....

--

Scott

aka "Skyking"



iCyberNet
Posts: 28
Member Since:
2006-08-30
fredo, Using externhost, pls

fredo,

Using externhost, pls try to ping your dynamic host and compare it with your actual IP address if there is a mismatch. You might need to consider using other dynamic client that can resolve your IP correctly.

iCyberNet



fredo
Posts: 56
Member Since:
2006-06-08
iCyberNet: There is no

iCyberNet: There is no mismatch, it just doesn't allow the sip audio pass. externip works perfectly.

Scott: I'd actually removed the logic to do the comparison since the script is launched by cron and runs anyway regardless and all it does is rewrite that one file. However, should you want the file not to be overwritten if the ip hasn't changed, I've put the script below with that logic back in.
I'm not sure what you mean by restart IAX, but the script does complete reload of all config files.

#!/bin/sh

# HOSTNAME is your DynDNS hostname
HOSTNAME=your_hostname.dyndns.org

# NSLOOKUP is the current DNS entry for your DynDNS hostname
NSLOOKUP=`/usr/bin/nslookup -sil $HOSTNAME | tail -2 | head -1 | cut -d" " -f2`

# get current ip of the router
CURRENT_IP=`/usr/bin/lynx -dump <a href="http://www.netins.net/dialup/tools/my_ip.shtml" title="http://www.netins.net/dialup/tools/my_ip.shtml">http://www.netins.net/dialup/tools/my_ip.shtml</a> | grep -A2 "Your current IP Address is:" | tail -n1 | tr -d ' '`

# update the sip_nat.conf and re-read configs
if [ "$NSLOOKUP" != "$CURRENT_IP" ] ; then
echo "externip=$CURRENT_IP
localnet=xxx.xxx.xxx.xxx/255.255.255.0" > /etc/asterisk/sip_nat.conf
chown asterisk.asterisk /etc/asterisk/sip_nat.conf
asterisk -rx reload
fi


SkykingOH
Posts: 9537
Member Since:
2007-12-17
Let me slow down, I was

Let me slow down, I was answering while I was working and I did not communicate my thoughts clearly.

My suggestion is the reload is only executed if the IP address has changed.

If the IP has changed the following will happen:

  1. The externip variable will be written to sip_nat.conf with the current IP
  2. Asterisk will be reloaded (as opposed to my idea of reloading sip and iax

I am also thinking of extending the script to also check all hostnames referenced in the sip and iax configuration files. This is a more significant effort, however it would keep IAX and SIP links up between servers with dynamic IP's.

Thoughts?

--

Scott

aka "Skyking"



fredo
Posts: 56
Member Since:
2006-06-08
Scott, Would be interested

Scott,

Would be interested to see what you come up with. The one thing that bugs me (and I'm not sure I read you right) is the asterisk reload. I assume you mean something like "amportal restart" and that be problematic as you would have no control over when that would happen and could potentially cut off ongoing calls.



SkykingOH
Posts: 9537
Member Since:
2007-12-17
Yes, Asterisk restart is not

Yes, Asterisk restart is not clear either. Certainly an Amportal restart would not be appropriate.

I would rather not reload the extensions (extensions.conf and all it's buddies) so I am thinking along these lines.

asterisk -rx 'sip reload'
asterisk -rx 'iax2 reload'

I am not a bash scripter so I will have to enlist some help.

Does this make more sense?

--

Scott

aka "Skyking"



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.