In case that your home network gets a dynamic (public) IP address from the internet service provider (ISP) and you want to get access to your network services (NAS, IP Cam, any webserver etc.) over the internet, then a DDNS service is necessary.
Typical modems support DDNS service configuration out of the box (e.g. Fritzbox), but if that is not possible then any OpenWRT device on your network can help out.
Content
- Setup a ddns-client on an OpenWrt Access Point where the Modem would not support dyndns out of the box ** The ddns-client will update the public IP periodically on the chosen DDNS service provider
Port forwarding to the local services has to be configured on the modem.
**Requirements *
- Pick and register a free DNS name with a compatible DynamicDNS provider (e.g. no-ip.com)
- Your network needs to get a public dynamic IP address assigned from the internet service provider (ISP)
ISP
|
LTE Modem (Dynamic public IP; Modem configured with port-forwarding; Modem acts as router)
| <lan interface>
OpenWRT Access Point (Local IP 192.168.1.2, Dumb WiFi Access Point; Configured DDNS client)
|
Local Service (192.168.1.10, e.g. IP Cam; exposed to the internet via http://mydomain.ddns.net:8080/webcams)
Install ddns scripts using opkg package manager.
opkg update
opkg install ddns-scripts
Depending on your ddns service provider, additional packages may be necessary.
opkg install ddns-scripts_no-ip_com
The ddns-scripts are installed to /usr/lib/ddns
:
root@openwrt:/usr/lib/ddns# ll
-rwxr-xr-x 1 root root 30151 Aug 1 16:31 dynamic_dns_functions.sh*
-rwxr-xr-x 1 root root 4109 Aug 1 16:31 dynamic_dns_lucihelper.sh*
-rwxr-xr-x 1 root root 10308 Aug 1 16:31 dynamic_dns_updater.sh*
-rwxr-xr-x 1 root root 1366 Aug 1 16:31 update_no-ip_com.sh*
The ddns client can be configured directly in /etc/config/ddns
.
Start with enabling the ddns client.
$ /etc/init.d/ddns enable
First of all, you have to set your credentials from your provider.
config service 'myddns_ipv4-config'
option lookup_host '<YOUR-DOMAIN-NAME>'
option domain '<YOUR-DOMAIN-NAME>' # e.g. myhome.ddns.net
option username '<YOUR-USER>'
option password '<YOUR-PASSWORD>'
option interface 'lan'
option ip_network 'lan'
option service_name 'no-ip.com'
The purpose of the ddns client is to update the dyndns service provider with your current IP address, so we have to configure that.
For that setup the ddns client is running on an arbitary Access Point, so an external service like http://ifconfig.me/ip
is necessary to retrieve the public IP address.
Append to configuration:
config service 'myddns_ipv4-config'
option ip_source 'web'
option ip_url 'http://ifconfig.me/ip' # external service retrieves public IP in plain text
This setting tells the client how to notify your dyndns service provider with your current IP.
Next configure the setting update_url
(depending on your service).
Lookup the setting for your supported service provider (supported dyndns providers are listed in /etc/ddns/services
)
$ awk '$1 ~ /no-ip.com/ {print $2}' /etc/ddns/services
update_no-ip_com.sh
Append in service configuration:
config service 'myddns_ipv4-config'
option update_url 'update_no-ip_com.sh'
*Sidenote: For no-ip.com the update_url setting uses on the additional installed update_no-ip_com.sh
script. For other ddns providers the setting could be a http link pointing directly to an API, e.g. for opendns.com
it would be http://[USERNAME]:[PASSWORD]@updates.opendns.com/nic/update?hostname=[DOMAIN]&myip=[IP]
.
config service 'myddns_ipv4-config'
option use_logfile '1'
$ /etc/init.d/ddns restart
Check that your configuration works!
The log output should look like:
104739 : Detect registered/public IP
104739 : #> /usr/bin/nslookup <your.ddns.net> >/var/run/ddns/myddns_ipv4.dat 2>/var/run/ddns/myddns_ipv4.err
104743 : Registered IP '<YOUR-PUBLIC-DYNAMIC-IP>' detected
104743 info : Starting main loop at 2020-08-12 10:47
104743 : Detect local IP on 'web'
104743 : #> /bin/uclient-fetch -q -O /var/run/ddns/myddns_ipv4.dat -Y off 'http://ifconfig.me/ip' 2>/var/run/ddns/myddns_ipv4.err
104747 : Local IP '<PUBLIC-IP>' detected on web at 'http://ifconfig.me/ip'
104747 : Update needed - L: '<PUBLIC-IP>' <> R: '<PUBLIC-IP>'
104747 : parsing script '/usr/lib/ddns/update_no-ip_com.sh'
104747 : sending dummy IP to 'no-ip.com'
104747 : #> /bin/uclient-fetch -q -O /var/run/ddns/myddns_ipv4.dat -Y off 'http:<[email protected]>:***PW***@dynupdate.no-ip.com/nic/update?hostname=<YOUR.DDNS.NET>&myip=127.0.0.1' 2>/var/run/ddns/myddns_ipv4.err
104755 : 'no-ip.com' answered:
good 127.0.0.1
104756 : sending real IP to 'no-ip.com'
104756 : #> /bin/uclient-fetch -q -O /var/run/ddns/myddns_ipv4.dat -Y off 'http:<[email protected]>:***PW***@dynupdate.no-ip.com/nic/update?hostname=<YOUR.DDNS.NET>&myip=<PUBLIC-IP>' 2>/var/run/ddns/myddns_ipv4.err
104805 : 'no-ip.com' answered:
good 46.75.33.201
104805 info : Update successful - IP '<PUBLIC-IP>' send
104805 info : Forced update successful - IP: '<PUBLIC-IP>' send
104805 : Waiting 600 seconds (Check Interval)
Dyndns is ready to use, configure port forwarding and you are set.
Thank you for your sharing! Lately I decided to use an old router has only TZO & outdated version of GNU.dip client which means DDNS will not work anymore So I tried to use mockbin.org as ACS endpoint port 80/443 just to capture IP changes peroidically (Bad Idea) but It doesn't work too with both AP & main router modes althought the router is not locked to any ISP. I wish if you have the answer of why. BTW I have no option except using OpenWRT or DD-WRT but still worrying about whitch version or specs should I choose with low budget used router/access point as I never used such firmwares before.