DDNS Troubles

I’m new to Freepbx and have it working quite well with one exception. I cannot seem to figure out how to get ddns service working / set up properly. I’m sure I’m just missing something with NAT or something. I am not a network expert either so sorry. I’ve been through Wiki and all seems simple but it just doesn’t work.

My setup:
FreePBX 13.0.192.9
DDNS 99999999.deployments.pbxact.com
SIPSTATION for trunk service

I can access my network by going to this DDNS address so I know that part is working. Everything works great when, in Asterisk SIP settings, I have external address as my WAN Ip Address, Chan SIP Settings IP Configuration set to Static.

My ISP changes my IP address daily and I don’t realize the phones are down until I try to make a call. At this very moment, if I put my DDNS address in Chan SIP settings and change it to dynmaic it works. If I change my External Address to the 99999999.deployments.pbxact.com it works. BUT, when my IP address changes again today, it will all stop working. I have the time interval in system admin DDNS set to lowest 15 mins. 15 Mins is too long for phones to be down for one, but for 2, it NEVER updates and system never reconnects after an IP address change.

Thanks for any help you might be able to offer.

Your external WAN address should be your DDNS FQDN and your Address Type should be set to Dynamic. Leave it that way and your problems should stop (or at least slow to a pace where you can catch them easily).

1 Like

Under SIP settings you can set the Dynamic Host Refresh time to the value you want:

1 Like

I should mention that I do have some external phones but the issue I’m facing causes all internal phones to stop working as well. In Connectivity -> SIPSTATION my contact Ip and network ip don’t match when the IP address changes. Right now, I have the DDNS address set up in both places in asterisk sip settings and it works fine. When IP changes, it will stop working until I change it back to the WAN IP, then, once I do and get it reconnected, I can put the DDNS address back in and it works. It is like it is holding on to the old IP even though the ddns address is there AND the ddns address resolves to the new IP address.

Thanks avayax. I’ve made a few changes there but no matter what, it doesn’t seem to reconnect after IP address changes. Even overnight. I’m disonnected most every morning.

This is what I would expect as well. No luck. I’ve been messing with this for a few weeks. Seems nothing I do works.

So when you find your trunks disconnected, do you see the old, non updated IP address under Sysadmin/DDNS/Detect External IP?

1 Like

I’ll have to check that but I certainly assume yes. I usually go hit “Detect IP” and change to static quickly to get back online.

Current state of settings as follows and all working (until IP changes again).

General SIP Settings:
External IP Address is 999999999.deployments.pbxact.com

Chan SIP Settings:
IP Configuration is Dynamic IP
Dynamic Host is 999999999.deployments.pbxact.com
Dynamic Host Refresh is 10

System Admin:
Enable DDNS - Yes
External DDNS - 99999999.deployments.pbxact.com
Force IP Address is blank
Update interval is 15 mins.
Detected IP is my WAN IP Address as it should be.

When it changes, I will validate detected IP.

Yes, also then check what is under general sip settings for external IP, cause that is the one relevant for your SIP trunks.

This is a long time issue with Chan sip and how it requires a reload as it caches DNS.

Tony,
Are you suggesting that with Chan Sip it simply doesnt’ work unless I recycle and there is no solution? Is there a better solution for my setup with SIPSTATION? This was basically the default.

avayax,
My External Address is set to by my dyndns address.

Have you thought of getting a static IP address from your ISP?

Sure I have thought about a static IP but seems this SHOULD work and save me a bunch of dough.

Also, I have two ISP’s with a dual wan router. If I have a failover situation, it won’t work with a static IP from only one of the providers.

You could write a little shell script that periodically checks your external IP address and if it changes, does a sip reload.

This script sends an email on ip change, but could be modified to do something else.

We are doing the same thing, reload SIP channel when DDNS address changes.
Try this script and run as cronjob */5 * * * * /root/check-ddns.sh

 #!/bin/sh
 #
 # Check if DDNS end-points have changed for SIP or IAX trunks, and if so, reload
 #
 # First, make sure current server is running asterisk, else exit w/o action
 if [ ! -f /var/run/asterisk/asterisk.pid ]; then
    exit
 fi
 PID=`cat /var/run/asterisk/asterisk.pid`
 if [ ! -e /proc/$PID/exe ]; then
     exit
 fi
 #
 # Check last known IP address
 #
 DDNS=_yourDNS_.deployments.pbxact.com"
 if [ ! -f /var/run/trunk-ddns/$DDNS ]; then
     # If prior IP file doesn't exist, write it if can, and bail till next time
     IP=`dig +short $DDNS`
     if [ ! -z "$IP" ]; then
         echo $IP > /var/run/trunk-ddns/$DDNS
     fi
     exit
 fi
 # Get prior IP address
 IP=`cat /var/run/trunk-ddns/$DDNS`
 # Get current IP address
 NEWIP=`dig +short $DDNS`
 if [ -z "$NEWIP" ]; then
     # DNS failure on getting new address, can only assume unchanged, exit
     exit
 fi
 # Compare new and old
 if [ ! "$IP" = "$NEWIP" ]; then
     # Different, note new IP address in file
     echo $NEWIP > /var/run/trunk-ddns/$DDNS
     # Reload SIP trunks in asterisk, presumably to force-reassociation with new end-point
     /usr/sbin/asterisk -rx "sip reload"
 fi
 exit 0

That should take care of your problems

In other words, if my IP configuration is Dynamic IP, and my external IP address changes, Asterisk won’t know until I do a manual SIP reload or click Detect Network Settings?
This is never happening automatically?

I like the script ideas. I did go ahead and order a Static IP but it takes away my dual wan automatic failover so maybe even just an email notification as provided here so we can manually detect ip and get phone up and running quickly if we loose primary ISP.

Like Avayax’s question, I guess I’m just surprised this doesn’t work. I would have thought a lot of people using this system would have this need. Curious if ANYONE has Dynamic DNS working and can share how they got it going?

Of course my IP changed about every 12 hours for the last 2 weeks and now it hasn’t changed since I started this thread! Murphy’s law. I’ll keep watching while I await delivery of static IP.