If you have ever setup an asterisk box then you know some changes are in the configuration. One of those challenges is being behind a nat or router. The issue usually arises when you use the ivr and you dont receive DTMF tones to your ivr. I use ViaTalk for service and their support staff clued me into the problem. I had to externhost=my.dyndns.com in your sip_nat.conf does not solve this problem, or at least didnt for me so I had to write my own dynamic dns update script using php only because it was quick but you can do this is bash probably just as easily.
$ip = gethostbyname($your_ddns_name);
$conf_file= file_get_contents($your_sip_nat_conf);
// Place each line of $userfile into array
$lines = explode("\n",$conf_file);
$found=false;
$write=false;
$conf_str="";
foreach ($lines as $line) {
@list($attr, $var) = explode("=", $line);
$attr=strtolower(trim($attr));
$var=trim($var);
if ($attr=="externip")
{
$found=true;
if ($var!=$ip)
{
$write=true;
$conf_str.="externip=$ip\n";
}
}
else
$conf_str.=$line."\n";
}
if (!$found)
{
$write=true;
$conf_str.="externip=$ip";
}
if ($write)
{
if (is_writable($your_sip_nat_conf)) {
if (!$handle = fopen($your_sip_nat_conf, 'w')) {
echo "Cannot open file ($your_sip_nat_conf)";
exit;
}
if (fwrite($handle, $conf_str) === FALSE) {
echo "Cannot write to file ($your_sip_nat_conf)";
exit;
}
fclose($handle);
} else {
echo "The file $your_sip_nat_conf is not writable";
}
system($your_restart_command);
}
?>

Leave a comment