Server - DNS

12 Sep 26

Bespoke domain DNS after router power cycle

When the router is unplugged/restarted, its connection to the ISP is re-established and the public IPv4 address changes.
This causes the DNS records for my bespoke domain (eg parksurf), which contain the previous public IPv4 address, to become out of date. Requests to parksurf fail.

To check this on the server, run:
curl -4 https://icanhazip.com
dig +short mydomain A
These should return the same IPv4 address. If they are different, the DNS A record is pointing to the old public IP address.

one-time fix:
  1. Log in to the DNS provider (Hostinger, dansimonsreview).
  2. Update the 2 A records - @ (root domain) and www records.
  3. Allow some time for the DNS change to propagate.
  4. Check again with dig +short mydomain A
  5. Note it takes some time for the DNS change to propagate

permanent fix (dynamic DNS update):
  1. Log in to Hostinger...API...new token 
  2. Save token myscripts/hostinger/ddns.env
  3. create bash script to check for DNS change and update Hostinger records if so ~/myscripts/hostinger/ddns.sh
  4. test the script sudo bash -c 'source  ~/myscripts/hostinger/ddns.env  && ~myscripts/hostinger/hostinger-ddns.sh'
  5. create service file to run ddns.sh /etc/ststemd/system/hostinger-ddns.service 
  6. test the service file sudo systemctl start hostinger-ddns.service (systemctl status hostinger-ddns.service)
  7. create timer file to run hostinger-ddns.service regularly
  8. start the timer sudo systemctl enable --now hostinger-ddns.timer (check - systemctl list-timers)