clempaul / dreamhost-dynamic-dns

A Dynamic DNS updater for use with the Dreamhost API
Other
91 stars 39 forks source link

Multiple Records #13

Closed rafny closed 4 years ago

rafny commented 4 years ago

Does this script support updating multiple records with the same ip address? If so, what's the best syntax for it?

clempaul commented 4 years ago

Hi @rafny, the script only supports updating a single record.

If you want to update multiple records you've got a couple of options:

  1. Run the script multiple times, once for each record - supplying -r on the command line will override whatever's in the config file if you're using that.
  2. Update a single record and use CNAMEs to redirect. This is approach that I prefer as all the records will be updated together.

As an example of the CNAME approach, you could have the following:

Record Type Value
dynamic.foo.com A <whatever comes from the script>
thing1.foo.com CNAME dynamic.foo.com
thing2.foo.com CNAME dynamic.foo.com

I hope that helps.

robotjohn commented 4 years ago

Hey @rafny, Like @clempaul mentioned you can just run it multiple times or use cnames. If you don't want to have cnames connecting multiple separate domains then multiple times is your next best best.

To prevent going over your dreamhost API rate limits you can make a small script to check if your ip has changed first and only run this script when required.

Here is what I use. If you use it I would recommend adding basic error checking as this will take any errors from eval "dig +short myip.opendns.com @resolver1.opendns.com" as a new ip.

#!/bin/bash

NewIP=$(eval "dig +short myip.opendns.com @resolver1.opendns.com -4")
read OldIP < OldIP.txt

if [ "$OldIP" != "$NewIP" ]
then
    echo Hey, it looks like our IP changed from $OldIP to $NewIP!
    /<your path to the script>/dynamicdns.bash -k <API KEY> -r site.tld -i $NewIP
    /<your path to the script>/dynamicdns.bash -k <API KEY> -r some.site.tld -i $NewIP
    /<your path to the script>/dynamicdns.bash -k <API KEY> -r some.funky.site.tld -i $NewIP
    /<your path to the script>/dynamicdns.bash -k <API KEY> -r some.strange.site.tld -i $NewIP
    /<your path to the script>/dynamicdns.bash -k <API KEY> -r *.othersite.tld -i $NewIP
    echo $NewIP > OldIP.txt
fi

if [ "$OldIP" = "$NewIP" ]
then
    echo Hey, it looks like our IP has not changed!
fi