2

Just set up ubuntu server, which has a dynamic ip. I am looking for a way to keep my dns server updated. Im using entrydns to do this and they provide the following command to update the server.

curl -k -X PUT -d "" https://entrydns.net/records/modify/TOKEN

What I need is a way of checking whether the ip has changed so I can update the dns server.

jasonspiro
  • 647
  • 4
  • 12
geminiCoder
  • 121
  • 1
  • 3

3 Answers3

8

It would be better to make a script that gets triggered any time the network configuration changes, and have that script unconditionally update DNS. If you're using Network Manager, such a script can go in /etc/NetworkManager/dispatcher.d -- see networkmanager(8) for details.

If you're not using network-manager, /etc/dhcp/dhclient-enter-hooks.d might be more appropriate.

Then you won't have to poll anything.

Jim Paris
  • 14,137
  • 5
  • 36
  • 35
  • This documentation can help too: https://networkmanager.dev/docs/api/latest/NetworkManager-dispatcher.html I suggest to use the environment variables IP4_GATEWAY and IP6_GATEWAY. Thank you for this smart and scalable solution. The answers to this question help to debug those variables: https://unix.stackexchange.com/q/465273/379099 – gouessej Feb 07 '23 at 23:07
  • Actually, IP4_GATEWAY contains the private IP address, not the public one :( – gouessej Feb 08 '23 at 19:12
4

Something like this would do:

#!/bin/bash

# "${0%.sh}.myip" transforms /path/to/script.sh to /path/to/script.myip
if [[ ! -s "${0%.sh}.myip" ]]; then echo "0.0.0.0" > "${0%.sh}.myip"

newip=$(curl -k -X PUT -d "" https://entrydns.net/records/modify/TOKEN)

read oldip < "${0%.sh}.myip"
echo $newip > "${0%.sh}.myip"

if [[ $newip != $oldip]]; echo "IP changed"; fi
bobah
  • 245
  • 1
  • 6
2

There might be a simpler way if you can live with a small delay in updating your IP and if there is not a limit on how often you can make updates to your record on entrydns.net

If this command works for updating entrydns.net then just put in in crontab and configure it to run at a set interval.

curl -k -X PUT -d "" https://entrydns.net/records/modify/TOKEN
Arv Evans
  • 21
  • 1