How to Automate DDNS updating on local Mac?

apologies, I have no idea what that means. Is there a guide I can follow?

Just Google “cron job to open url” and you’ll get lots of examples from StackExchange or elsewhere.

In Terminal, the command to open your URL is

wget https://...

If you don’t want to play with the terminal, or want a UI to help manage the schedule for you, then consider getting Lingon

1 Like

Are you adventurous?
Open Terminal and copy and paste this command, then press Return:

EDITOR=/usr/bin/nano crontab -e

A very basic editor will open.

Copy and paste this line, adding the other stuff you need at the end, rather than the ...:

5 5-23 * * * /usr/local/bin/wget https://link-ip.nextdns.io/...

Press Ctrl-O and press Return to save.
Press Ctrl-X and press Return to exit.

Every hour from 5:00am - 11:00pm, at 5 minutes past the hour, the wget command will run.

Crontab.guru can enlighten you on the syntax.

caveat emptor. void where prohibited. valid in 49 States, sorry Tennessee.

3 Likes

I have just done this. Hopefully, it works. It was easier than I thought it would. Many thanks, @JohnAtl and @anon41602260

Btw, are there any logs that would show this working?

You could pipe the output to a file by adding something like >~/logfile.txt to the end of the command in crontab. This will allow you to see the output from the last time the command executed.
There are other ways to do logging, but I don’t have the information at hand at the moment.

a cron job to run a “curl” or “wget” command

What happens if MereCivilian is using a VPN at the time the cron job executes?

Won’t NextDNS get the wrong IP then? (Until the next cron job run after VPN is disabled)

Depending on your router you might be able to do this on your router as well.

(I run a curl command in the ddns-start script of my ASUS router running Asuswrt-Merlin firmware)

Are you sure you even need to do this?

It’s not needed when you use their App, DNS-over-TLS, DNS-over-HTTPS, or IPv6.

(so my script is redundant as well; I use DOH via the NextDNS CLI).

You can use the NextDNS Apple Configuration Profile creator to set up DOH.

1 Like

The request was for an automated method. Any query of one’s IP could be impacted if that machine has an active VPN connection when the command runs. In that case, the cron job would need to be scheduled to run when VPN was not active.

To make things more robust, one could write a script to check the VPN status (e.g. for a work VPN, check for access to specific DNS or other internal servers) and only query the URL if not on VPN then make that script the command called via cron. This would need to be customized for each individual’s environment.

2 Likes

The only acceptable crontab editor is vi :stuck_out_tongue:

3 Likes

You misspelled EMACS :slightly_smiling_face:

I’ll just ⎋!wq my way out now.

˄x˄s

1 Like

That was my thought :rofl: nano indeed…

1 Like

The right answer is, of course, “ed”. :smiling_imp:

BTW, while emacs was the first Unix editor I learned, I use vi almost exclusively now since that is the only editor I have access to on much of the hardware I support for work.

1 Like

Nano is pretty ubiquitous now.
Plus it’s non-modal, so you don’t have to switch between typing and moving modes.
(probably ways around that now, given it’s the 21st Century) (right?)

I’d have to see if nano was part of the stripped down OSes running on some of the hardware I support. That said, trying to keep track of where different editors are available was the main reason I switched away from emacs in the first place.

@JohnAtl and @anon41602260 - it seems the commands are not running. Does the terminal window need to be open for the commands to run?

This is what I setup:

What does give that impression? (IP’s not correct?)

Is what you’re showing the output of crontab -l?

Do the commands work on the command line? (For example is wget installed, in /usr/local/bin?)

Add this to each line

>/var/log/cron.stdout.txt 2>/var/log/cron.stderr.txt

Then you can review the output with a text editor.
For easier troubleshooting, you could decrease the time interval to, say, every 2 minutes.

*/2 * * * *

If you want to monitor the output in a terminal, just open a window and type this:

tail -f /var/log/cron.stdout.txt

and in another window:

tail -f /var/log/cron.stderr.txt

Press Ctrl-C to stop the tail command.

This is how I’ve done this when I needed it in the past. Some routers even have a built-in config option for it. You point the config option at the service you use and it will automatically update the service with your IP address every time it changes or every so often, depending on how to configure it.

Sadly, despite the assistance provided (i appreciate the guidance), I couldnt get it to work… Just not great with terminal. May look at Lingon or perhaps Keyboard Maestro to open a link in a browser, wait 10 seconds and close the browser.

Maybe use an App instead then?

I have no experience with this App (only searched for DDNS in the App Store) and it hasn’t been updated in 2 years, but maybe it (or a similar App) can help?

You could combine that with using a DDNS service and let NextDNS use the hostname provided by that DDNS service to resolve your IP automatically (instead of regularly opening a link yourself).

Oops, I now see you don’t want to use a DDNS service…