News & Reviews
More How-To's & Tips More News
More Reviews Device Configuration Tools
No account yet? Create one
Forgot your Username or Password?

Welcome to the Voxilla VoIP Forum.

Voxilla has been a trusted source for accurate, up-to-date information on the IP Communications industry since 2002. A dedicated staff of reporters and engineers produce feature articles and product reviews to keep industry watchers abreast of the people, companies, and trends driving a fast moving market.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.





Closed Thread
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old November 15th, 2006, 06:41 PM
jcgalvezv's Avatar
jcgalvezv jcgalvezv is offline
Senior Member
 
Join Date: Apr 2005
Location: San Salvador, El Salvador, Central America
Posts: 1,025
jcgalvezv
Default Asterisk as a SIP client behind NAT - A Solution

Sometimes we need to configure asterisk as a SIP client behind a NAT. Common ways to solve this NAT issue is configuring externip=xxx.xxx.xxx.xxx and localnet=xxx.xxx.xxx.xxx where this last localnet use the form:

;localnet=192.168.0.0/255.255.0.0; All RFC 1918 addresses are local networks
;localnet=10.0.0.0/255.0.0.0 ; Also RFC1918
;localnet=172.16.0.0/12 ; Another RFC1918 with CIDR notation
;localnet=169.254.0.0/255.255.0.0 ;Zero conf local network

or something like:

localnet=192.168.1.1/24;

Everything would be just fine is the externip or External IP address remained always the same; but, some times this is not true because our ISP assigns us a dynamic public IP address that changes from time to time, or in the worst case a private IP address (like me).

To solve the previous issue we could, from time to time (really often), discover the new IP address and change the line externip=xxx.xxx.xxx.xxx in sip.conf file and issue a sip reload command in asterisk CLI; we could also use an automated procedure, as I did. A third option could be to use dyndns, something that cannot be done if you get a private IP address asigned.

I am going to explain how I solved this problem by using an automated procedure.

1. I changed the line

externip=xxx.xxx.xxx.xxx

for:

#include sip_externip.conf.

2. I wrote a script (with some help at the begining) that has changed. This is what I currently have (saved as checkexternip):

--------------------------------------------------------------------
# Get external IP address.

mynewip=`wget -O - http://checkip.dyndns.com|cut -b77-92|tr -d "</body>"`

# Get current Asterisk IP address.

myoldip=`dd if=/etc/asterisk/sip_externip.conf bs=9 skip=1 2>null`

if test .$myoldip != .$mynewip && !(test -z $mynewip)
then
echo "externip=$mynewip" > /etc/asterisk/sip_externip.conf
echo `date` "$mynewip" >> /etc/asterisk/sip_externip.log
asterisk -r -x "sip reload"
fi
-------------------------------------------------------------

This script checks for external IP changes, if changed rewrite sip_externip.conf, records the new IP address in sip_externip.log and asks asterisk to reaload sip configuration.

3. I wrote a cron entry like this:

*/1 * * * * /etc/asterisk/checkexternip

This cron entry executes the script once every minute so, my asterisk could be out of service (if my extern IP address changes) for maximum 1 minute. You must change /etc/asterisk/ with the path where you save your checkexternip script.

I hope this procedure can be usefull to someone else.

Juan C.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
  #2 (permalink)  
Old November 15th, 2006, 07:37 PM
rizsher rizsher is offline
Senior Member
 
Join Date: Jul 2004
Posts: 1,119
rizsher
Default Re: Asterisk as a SIP client behind NAT - A Solution

Quote:
A third option could be to use dyndns, something that cannot be done if you get a private IP address asigned.
Even with Dyndns, the IP address needs to be renever. Using Dyndns, I've got the following entries in my sip.conf

Code:
port = 5060           ; Port to bind to (SIP is 5060)
bindaddr = 0.0.0.0    ; Address to bind to (all addresses on machine)
externhost = mydyndnshost.freedomain.net
externrefresh = 5
localnet=192.168.1.1/255.255.255.0
nat=yes
defaultexpirey=3600
With this setup, my Dynamic IP has never created a problem for me; The externrefresh=5 setting makes sure I can be offline for a maximum of 5 minutes, this setting could be further reduced if desired. With this, there is no need for a script to be executed in cron.

I suppose jcgalvezv method could be used in a situation where a dyndns isn't available (though I guess pretty any router released in the last 3-4 years has a dynamic DNS clinet built in).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:



Similar Threads for: Asterisk as a SIP client behind NAT - A Solution
Thread Thread Starter Forum Replies Last Post
can't get external sip phone to register with Asterisk behind a NAT idatoo Asterisk Support Forum 3 October 3rd, 2006 03:37 PM
Asterisk as SIP client behind router problem singingwolf Asterisk Support Forum 2 August 25th, 2006 09:47 AM
Register Asterisk as a client to another SIP svr.. himidiri Asterisk Support Forum 0 March 23rd, 2006 10:11 AM
One way audio on sip client but only out to PSTN Cozzman Asterisk Support Forum 3 November 2nd, 2005 03:57 AM
Ingate Launches Far-End NAT Traversal Solution (comment) PhoneBoy General VoIP Discussion 0 December 14th, 2004 08:50 PM



All times are GMT. The time now is 09:52 AM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd. SEO by vBSEO 3.0.0 ©2007, Crawlability, Inc. Logos and trademarks are the property of Voxilla or their respective owner. All other content © 2003-2007 by Voxilla, Inc.