Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Quick IP Updater! Among my VPS Usage :)
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Quick IP Updater! Among my VPS Usage :)

Smoke signal across the globe!
Conceived for specific reasons,
This Dynamic DNS IP Update is a METHOD FOR ACHIEVING MINIMUM DOWNTIME° following IP changes FOR LOCAL ACCESS SERVICES like;
– Reverse proxy to enable public access + the benefit of DDoS protection from VPS provider if available,
– VPN link with services like IP PBX, private Jabber,…
– Monitoring critical services,
– Gaming,
– Stock Management update from multiple location (Ticketing…)
– Private critical IoT devices management
– Basic POS
– Digital Signage at various location
– etc.
And for almost any purpose where very low downtime is required in between IP change, while you are stuck on a dynamically allocated public IPv4 from your ISP and also if your ISP charge excessively high for a fix IP.

°downtime vary according to latency/connection bandwidth/router processor, but usually much less than 2 minutes and most of the time almost ~40 seconds variations according to sites

The configuration make use of a VPS with Linux and BIND DNS, HTTP, FTP and Mail Server configured.
And a local OpenWRT device or other Linux based local device.

On the O.WRT device:

  • opkg install msmtp curl bash
    Configure the msmtp for your mail.

Make use of cron on the O.WRT device to to set its execution frequency. Every 30 seconds with the help of the 'sleep' cmd°
As $cached_ip here being in 'tmp', the line "Was:" ip in mail notification will be blank in the event if a reboot or power cut occured on the device, you may put it where you sees more appropriate.

As per dnsmasq features, its config must be updated to include the use of custom DNS server for the specific IP resolvement of each site addresses

  • File "/etc/dnsmasq.conf" to include details as per below:
    server=/site1.yourPrivateCustomDomain.You/IPADDRESS.OF.YOUR.VPS
    server=/site2.yourPrivateCustomDomain.You/IPADDRESS.OF.YOUR.VPS
    server=/site3.yourPrivateCustomDomain.You/IPADDRESS.OF.YOUR.VPS

–––––––––––––––––––––––––––––––––––––––––––––––––

!/bin/bash

sender="Orbit Site1 site1@mail-example.com"
receiver="your-email-here"
tmpemail="/tmp/site1.mail"
cached_ip="/tmp/ip_site1"
touch $cached_ip
touch $tmpemail
#
while true; do
touriss=$(curl -s http://api.ipify.org)
doublivi=$(cat $cached_ip)
echo $touriss
echo $doublivi
if [ "$touriss" != "$doublivi" ]
then echo "They are different!"
rm -f $cached_ip &&
echo $touriss >> $cached_ip &&

VPS Notification

            curl -p "ftp://your-vps/" --user "the-ftp-account-name@your-vps:the-ftp-account-password" -T $cached_ip &&

Email Notification

    echo "To: $receiver" >> $tmpemail &&
    echo "From: $sender" >> $tmpemail &&
    echo "Subject: Orbit Pointer Site1 Updated" >> $tmpemail &&
    echo "" >> $tmpemail &&
    echo "Is: $touriss" >> $tmpemail &&
    echo "Was: $doublivi" >> $tmpemail &&
    cat $tmpemail | msmtp -a site1 $receiver &&
    rm -f $tmpemail

#
else echo "All good, IP still as last check" && exit 1
break
fi
break
done
–––––––––––––––––––––––––––––––––––––––––––––––––

On the Linux VPS°
Ensure proper permissions set for the various folder and file to be used for proper execution of each services.
Configure DNS and set the 'A' records for the various sites with a ~30 seconds ttl

  • Sample 'A' record line in /var/lib/bind/yourPrivateCustomDomain-host-file:
    site1.yourPrivateCustomDomain.You. 30s IN A 10.10.10.10 ;Link for Site 1

Configure Email for the emailing of the IP update notifications
Configure FTP Server service access and the ftp user
Configure firewall for all necessary services
Ensure fails2Ban is configured, up and running
Use CRON to schedule script below

–––––––––––––––––––––––––––––––––––––––––––––––––

!/bin/bash

touch /custom/folder/location/oldLine_site1
touch /custom/folder/location/old_site1.address
touch /custom/folder/location/newLine_site1
touch /custom/folder/location/site1.mail

sender="Star SITE1 <site1@your-vps>"
receiver="your-email-here"
tmpemail="/custom/folder/location/site1.mail"

cat /var/lib/bind/yourPrivateCustomDomain.You.hosts | grep site1.yourPrivateCustomDomain.You > /custom/folder/location/oldLine_site1
sleep 1
grep -E -o "([0-9]{1,3}[.]){3}[0-9]{1,3}" /custom/folder/location/oldLine_site1 > /custom/folder/location/old_site1.address
oldIP="/custom/folder/location/old_site1.address"
newIP="/full/path/of/your/virtual/server/ftp/shared/folder/site1.txt"
ExIP=$(cat $oldIP)
UpdatedIP=$(cat $newIP)

while true; do
rm -f $tmpemail
echo "To: $receiver" >> $tmpemail
echo "From: $sender" >> $tmpemail
echo "Subject: Star Pointer SITE1 Updated" >> $tmpemail
echo "" >> $tmpemail
touriss=$(cat $newIP)
doublivi=$(cat $oldIP)
echo "Is: $touriss" >> $tmpemail
echo "Was: $doublivi" >> $tmpemail
echo $touriss
echo $doublivi
if [ "$touriss" != "$doublivi" ]
then echo "SITE1 IP Changed!"

sed "s@$ExIP@$UpdatedIP@g" /custom/folder/location/oldLine_site1 > /custom/folder/location/newLine_site1

sleep 1
cat /var/lib/bind/yourPrivateCustomDomain.You.hosts | grep site1.yourPrivateCustomDomain.You > /custom/folder/location/oldLine_site1

newLine="/custom/folder/location/newLine_site1"
oldLine="/custom/folder/location/oldLine_site1"
ReplaceOld=$(cat $oldLine)
UpdateNew=$(cat $newLine)

sed -i "s@$ReplaceOld@$UpdateNew@g" /var/lib/bind/yourPrivateCustomDomain.You.hosts

systemctl reload bind9

    cat $tmpemail | /usr/sbin/sendmail -f $sender $receiver

break
fi
echo "IP same, no update done"
break

echo "done!"

.
done
–––––––––––––––––––––––––––––––––––––––––––––––––
°Files to accompany the script on the Linux VPS
Note that all these files must be in place with appropriate permissions for proper execution,
else you might cause issue to your CRON process or saturate your mail inbox.

    1. /full/path/of/your/virtual/server/ftp/shared/folder/site1.txt
      10.10.10.10
    1. /custom/folder/location/oldLine_site1
      site1.yourPrivateCustomDomain.You. 30s IN A 10.10.10.10 ;Link for Site 1
    1. /custom/folder/location/newLine_site1
      site1.yourPrivateCustomDomain.You. 30s IN A 10.10.10.10 ;Link for Site 1
    1. /custom/folder/location/old_site1.address
      10.10.10.10
    1. /custom/folder/location/site1.mail
      To: [email protected]
      From: Star Site1 site1@yourregistereddomainname.com
      Subject: Star Pointer SITE1 Updated

Is: 12.12.12.12
Was: 10.10.10.10

–––––––––––––––––––––––––––––––––––––––––––––––––

Voilà!
your smoke signal is up!

If any other method in use out there, you are most welcome to share, or any improvement you see good for simplification, or any issue within the lines requiring corrections :)

Improved over time, the above method is in used since 2014 for some sites all around the globe with absolutely no downtime greater than 3 minutes directly related to it and longest offsync time recorded during an issue being troubleshooted was 3 minutes and 35 seconds.

From PPTP to Campagnol to OpenVPN to IPSEC, and now, since some time, thanks to jason@zx2c4 with the advent of Wireguard, VPN services are 24/7 UP! No Extra paid DDNS services and for as many nodes needed.

This method once also survive sync every 15-30 minutes with downtime of only ~2 minutes when ISP was troubleshooting their own issues and WAN IP was being changed every 15-30 minutes!

Note that for optimum result O.WRT CRON timing must be define with various test, like time taken of script execution on specific device(beware of extroot with cheap pendrive), test during high cpu load, test when bandwidth is being saturated by local users etc., TTL and CRON on VPS set accordingly and all devices sharing same NTP servers, may it be existing ones or your own.
Note:

  • with a very low TTL, DNS cache will be updated according to the TTL, and with a 30 seconds period or less, links will almost be constant across all hop between you and your VPS.
  • WAN IP resolver service will be queried according the frequency set in CRON in O.WRT - various resolver can be used according to geolocation of site and script amended for the respective resolver

With VPN, may it be behind LTE, CG-NAT, Backup MultiWAN Fiber/LTE device, connection links comes back up in less than a minute.

If DNS names of nodes must be publicly available(Split DNS Config.), DNS service provider API can also be used and appended within the O.WRT script but the public access downtime will vary according to DNS service provider minimum TTL.
Sample script here: http://teanazar.com/2016/05/godaddy-ddns-updater/
HTTP service can be enabled on the VPS to share access of the folder containing the IP files if needed.

–––––––––––––––––––––––––––––––––––––––––––––––––

°For your understanding of the CRON interval,
note that on heavy CPU load the written text test being logged will not be in sync with the time it is being executed:

          • /bin/sleep 11 && /usr/bin/logger Timing_TEST_NEW-11
          • /bin/sleep 25 && /usr/bin/logger Timing_TEST_NEW-25
          • /bin/sleep 35 && /usr/bin/logger Timing_TEST_NEW-35
          • /bin/sleep 43 && /usr/bin/logger Timing_TEST_NEW-43
          • /usr/bin/logger Timing_TEST_NEW-Base

Tue Sep 26 15:40:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:40:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:40:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:40:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:40:43 2023 user.notice root: Timing_TEST_NEW-43
Tue Sep 26 15:41:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:41:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:41:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:41:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:41:43 2023 user.notice root: Timing_TEST_NEW-43
Tue Sep 26 15:42:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:42:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:42:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:42:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:42:43 2023 user.notice root: Timing_TEST_NEW-43
Tue Sep 26 15:43:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:43:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:43:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:43:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:43:43 2023 user.notice root: Timing_TEST_NEW-43
Tue Sep 26 15:44:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:44:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:44:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:44:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:44:43 2023 user.notice root: Timing_TEST_NEW-43
Tue Sep 26 15:45:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:45:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:45:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:45:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:45:43 2023 user.notice root: Timing_TEST_NEW-43
Tue Sep 26 15:46:00 2023 user.notice root: Timing_TEST_NEW-Base
Tue Sep 26 15:46:11 2023 user.notice root: Timing_TEST_NEW-11
Tue Sep 26 15:46:25 2023 user.notice root: Timing_TEST_NEW-25
Tue Sep 26 15:46:35 2023 user.notice root: Timing_TEST_NEW-35
Tue Sep 26 15:46:43 2023 user.notice root: Timing_TEST_NEW-43

–––––––––––––––––––––––––––––––––––––––––––––––––

For whoever finds these instruction useful and fruitful for their project,
you are most welcome to PM me for a donation :)

Comments

  • isnt it better to post it to git and write a markdown?

    Thanked by 2tjn ariq01
  • Im new here and was checking the categories, this post is about one of my usages of VPS.

    The posting modified my code where there is the diez letter, how can I have the code as it shoud be in the forum? Or may be the administrator can correct it for everyone please?

    thank you

  • @SweetnSourAverrhoaL said:
    Im new here and was checking the categories, this post is about one of my usages of VPS.

    The posting modified my code where there is the diez letter, how can I have the code as it shoud be in the forum? Or may be the administrator can correct it for everyone please?

    thank you

    I mean, just write a markdown post on git or gist, whatever you prefer and post the link here?

Sign In or Register to comment.