<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux, windows, asterisk, vmware &#187; sip_nat.conf</title>
	<atom:link href="http://blog.simplic8.com/tag/sip_natconf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.simplic8.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Jun 2010 02:00:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Trixbox &#8211; externhost issue, Update sip_nat.conf externip automatically</title>
		<link>http://blog.simplic8.com/2009/04/06/trixbox-externhost-issue-update-sip_natconf-externip-automatically/</link>
		<comments>http://blog.simplic8.com/2009/04/06/trixbox-externhost-issue-update-sip_natconf-externip-automatically/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 03:20:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[sip_nat.conf]]></category>
		<category><![CDATA[trixbox]]></category>

		<guid isPermaLink="false">http://blog.simplic8.com/?p=5</guid>
		<description><![CDATA[After having further issues with using externhost=yourdomain.dyndns.org in my sip_nat.conf file I decided to use the dynamic IP address and have trixbox update the sip_nat.conf file automatically using a bash script coupled with a cron job.
Your sip clients can still connect with the Dynamic DNS name without any troubles as long as the externip= is [...]]]></description>
			<content:encoded><![CDATA[<p class="snap_preview">After having further issues with using <strong>externhost=yourdomain.dyndns.or</strong>g in my <strong>sip_nat.conf</strong> file I decided to use the dynamic IP address and have <strong>trixbox</strong> update the<strong> sip_nat.conf </strong>file automatically using a bash script coupled with a cron job.</p>
<p class="snap_preview">Your sip clients can still connect with the Dynamic DNS name without any troubles as long as the<strong> externip=</strong> is the valid public IP.</p>
<p class="snap_preview">Please refer to my previous post <a title="Permanent Link to Trixbox - External sip clients, no audio" rel="bookmark" href="http://simplic8.wordpress.com/2009/01/14/trixbox-external-sip-clients-no-audio/" target="_blank">Trixbox &#8211; External sip clients, no audio</a> for additional information on how to setup your external sip clients.</p>
<p class="snap_preview">The process is as follows.</p>
<p class="snap_preview">1. Create a bash script<br />
2. Update crontab to include an hourly update check against the IP<br />
3. Sit back and relax <img class="wp-smiley" src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":-)" /></p>
<p class="snap_preview">Log into your trixbox via SSH, once logged in issue the command: <strong>nano /root/update_dyndns.sh</strong></p>
<p class="snap_preview">Paste the below contents into your new file, you should only need to change the following two values</p>
<p class="snap_preview"><strong>localnet=</strong><br />
<strong>mask=</strong></p>
<p class="snap_preview"><strong>#interogates whatismyip.org to determine the outside IP of the</strong><br />
<strong> #!/bin/bash<br />
# Interogates whatismyip.org to determine the outside IP of the<br />
# machine and checks it against what it was at the last check.<br />
# Then it creates a sip_nat.conf file, moves it to the proper<br />
# directory and performs a sip reload.</strong></p>
<p class="snap_preview"><strong># set some variables<br />
localnet=”192.168.1.0″ #change this number to your local network subnet<br />
mask=”255.255.255.0″ #change this to your subnet mask<br />
nat=”yes” #Set the nat parameter if you like. If set to no<br />
#this line will not be included in the final file</strong></p>
<p class="snap_preview"><strong># change to a working directory. Make sure this directory exists<br />
cd /root/</strong></p>
<p class="snap_preview"><strong>rm -f index.html # Remove the last file</strong></p>
<p class="snap_preview"><strong>wget whatismyip.org</strong></p>
<p class="snap_preview"><strong>read newaddy &lt; “index.html”</strong></p>
<p class="snap_preview"><strong>read oldaddy &lt; “oldindex.html”</strong></p>
<p class="snap_preview"><strong>if [ $newaddy != $oldaddy ]<br />
then<br />
mv index.html oldindex.html<br />
echo “externip=$newaddy” &gt; sip_nat.conf<br />
echo “localnet=$localnet/$mask” &gt;&gt; sip_nat.conf</strong></p>
<p class="snap_preview"><strong>if [ $nat == "yes" ]<br />
then<br />
echo “nat=$nat” &gt;&gt; sip_nat.conf<br />
fi</strong></p>
<p class="snap_preview"><strong>chmod 775 sip_nat.conf<br />
chown asterisk:asterisk sip_nat.conf<br />
cp sip_nat.conf /etc/asterisk/sip_nat.conf<br />
asterisk -rx “sip reload”<br />
fi</strong></p>
<p class="snap_preview">#THE LAST THING IN YOUR NEW FILE SHOULD BE <strong>fi </strong>DO NOT PASTE ANYTHING ELSE BELOW.</p>
<p class="snap_preview">The above script was taken and modified from an unknown website, if it’s yours! thanks and let me know so I can link back to you.</p>
<p class="snap_preview">Once you have pasted the above contents into the new file, save the file <strong>ctrl+x</strong> then enter <strong>y</strong> then press <strong>enter</strong>.</p>
<p class="snap_preview">The first time you run the script it will fail with errors, here is the work around.</p>
<p class="snap_preview">1. run the script, command:<strong> /root/update_dyndns.sh</strong></p>
<p class="snap_preview">This will create an <strong>index.html</strong> file in the <strong>/root/</strong> dir.</p>
<p class="snap_preview">2. command: <strong>mv /root/index.html /root/oldindex.html</strong><br />
3. command: <strong>nano /root/oldindex.html</strong></p>
<p class="snap_preview">Edit one of the numbers where you see the IP address, this will force the script to notice the change and update your <strong>sip_nat.conf</strong> file for the first time!</p>
<p class="snap_preview">4. command: <strong>/root/update_dyndns.sh</strong></p>
<p class="snap_preview">You should see the following output.</p>
<p class="snap_preview">[trixbox1.localdomain ~]# <strong>/root/update_dyndns.sh</strong></p>
<p class="snap_preview">–16:57:50–  http://whatismyip.org/<br />
Resolving whatismyip.org… 75.147.234.41<br />
Connecting to whatismyip.org|75.147.234.41|:80… connected.<br />
HTTP request sent, awaiting response… 200 OK<br />
Length: unspecified [text/plain]<br />
Saving to: `index.html’</p>
<p class="snap_preview">[ &lt;=&gt;                                                                                                                  ] 13          –.-K/s   in 0s</p>
<p class="snap_preview">16:57:51 (147 KB/s) &#8211; `index.html’ saved [13]<br />
[trixbox1.localdomain ~]#</p>
<p class="snap_preview">If you have followed the above steps correctly, looking at your <strong>/etc/asterisk/sip_nat.conf</strong> file should look like this..</p>
<p class="snap_preview">[trixbox1.localdomain ~]# <strong>less /etc/asterisk/sip_nat.conf</strong></p>
<p class="snap_preview"><strong>externip=203.xx.xx.xx<br />
localnet=192.168.1.0/255.255.255.0<br />
nat=yes</strong></p>
<p class="snap_preview">Now comes the question? I don’t want to run this script each time I feel like updating the IP address, you want this to happen automatically, this is where the magic of cron jobs come into play *claps*, the basic concept is to run our script at a predefined time.</p>
<p class="snap_preview">Using the website below, I created a cron task that runs, every day, every hour of every month of every year, you can use the website link below in order to customize this to suite your own needs.</p>
<p class="snap_preview"><strong>58 * * * * /root/update_dyndns.sh &gt; /dev/null</strong></p>
<p class="snap_preview">information taken from <a title="http://www.htmlbasix.com/crontab.shtml" href="http://www.htmlbasix.com/crontab.shtml">http://www.htmlbasix.com/crontab.shtml</a></p>
<div class="snap_preview">
<ol>
<li>At the prompt, type in ‘<strong>crontab -e</strong>‘. This will open up your crontab file, or create a new one if it doesn’t exist.<br />
When this file opens, you will see other cron jobs listed in here, or if you haven’t any &#8211; you’ll see a bunch of lines with ‘~’ on them.</li>
<li>Use the cursor to go down until you can’t move the cursor down any more. This is where you start your new line. Press ‘<strong>o</strong>‘ to insert a new line.</li>
<li>Press ‘<strong>o</strong>‘ to insert a new line. If you want to edit a line, press ‘<strong>i</strong>‘.</li>
<li>Copy the code above, then right click into your SSH or telnet client to paste the above code in. This should all go in as a new line.</li>
<li>Press the ‘<strong>esc</strong>‘ key to exit out of edit mode.</li>
<li>To save the changes and exit, type the following in: <strong>ZZ</strong><br />
If you want to exit without saving changes, type in: <strong>:q!</strong></p>
<p><strong> </strong></li>
<li>Once you have exited, to view the new entry in your crontab file type <strong>crontab -l</strong> in at the prompt. This will list the contents of your crontab file.</li>
</ol>
</div>
<p>That’s it! everything is now done <img class="wp-smiley" src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" alt=":-)" /></p>
<p>Comments or questions welcome.</p>
<p><a href="http://blog.simplic8.com/wp-content/uploads/update_dyndns.sh">Download the Bash Script here!</a><br/><br/> Or use the following command from your terminal</p>
<p>wget http://blog.simplic8.com/wp-content/uploads/update_dyndns.sh</p>
<img src="http://blog.simplic8.com/?ak_action=api_record_view&id=5&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.simplic8.com/2009/04/06/trixbox-externhost-issue-update-sip_natconf-externip-automatically/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
