Skip to content

BashPlus for DNS Made Easy

monstruooo edited this page May 16, 2017 · 51 revisions

Getting started

You start by sourcing the file common.functions. This will source all other files that contain bash+ functions

When you first run any command, you are prompted for your API keys. Your keys are then saved as variables inside your shell and will persist until your close the current shell session

If you want to enter your credentials again, run command dnsme cfg reset

Next you list your domains and create a new domain

As you could notice the new domain has become visible only after command dnsme updatedb. This is because bash+ works from local cache. When you list your domains for the first time, bash+ detects that there is no cache and downloads the list of domains from the API. However, once the cache is filled, dnsme ls doesn't attempt to contact the API again and continues to use the cache until you issue command dnsme updatedb


Listing/Creating records

Next we create two A records, one of them naked. Notice that until dnsme updatedb <domain> is run, new records are not listed. This is because dnsme ls uses local cache

'args2json' is basically a bash+ function that converts arguments to json format. In this case 'args2json' creates a json with information about the new record which 'dnsme api' passes directly to the API.

Next we are adding a TXT and a CNAME. Notice again the use of dnsme updatedb to refresh the domain data.

The backslash \ means that the command continues on the next line. It's basically:

dnsme mk "$(args2json ... )" "$(args2json ... )" ...

That is, dnsme mk can create several records at the same time. Your script would run faster if you process your records in one batch instead of running dnsme mk for each one of them separately.

If you want to create records of other types, consult the API documentation

For example, for an MX record you will need additional mxLevel field

So you will add mxLevel= to the list of arguments of dnsme mk. Here I am saving the output of args2json to a variable mx_json before running dnsme mk. It works the same as the commands above with args2json on the same line with dnsme mk.

Also, notice how you can configure a different TTL than default 1800


Updating records

You update records the same way you create them with the exception of naked records. For normal records just run dnsme mk again with new values

For naked records, you need to specify their id to update existing records. Otherwise, a new record is created

You can add id when working with any existing record, not only naked. This may even make the command run a bit faster

You can update several records at once just as you can create several new records in one batch. Moreso, you can mix new records and existing records that need to be updated in the same command. dnsme mk can sort it all out


Deleting records

You delete records by their ids. Notice again the use of dnsme updatedb <domain> to refresh the list of records


Working with dnsme_api

To keep you away from trouble, bash+ doesn't have a command to delete domains. You have to do it manually in GUI. However, if you can easily issue your own API requests using bash+ dyn api command. This is how you can do it.

So instead of dnsmeapi.pl, you call function dnsme api.

You don't need to specify the -H accept: and -H content-type headers because dnsme api adds them automatically anyway. You only need to pass -X <action> and -d <data> parameters along with the url.

According to the manual, the data part should look like {["<id>"]}. In reality, [<id>] works just as well.

While you can grep the id from dnsme ls, bash+ has function dnsme domain id that can do the same more easily.

Tip: dnsme api automatically adds https://api.dnsmadeeasy.com/V2.0 to the url. Instead of https://api.dnsmadeeasy.com/V2.0/dns/managed/$id you could just as well just type dns/managed/$id

[[ -n $id ]] is a bash trick to check if the variable has a value.

You can check the result of dnsme api thru variable res_code. If it's 0, the command completed successfully.

Another variable set by dnsme api is res. This variable contains the actual response from the API.

in the example below, res contains a json with the list of domains downloaded from the API by dnsme updatedb


More dnsme features

dnsme cat and dnsme cat <domain> will print the list of domains or the records of a particular domain respectively in raw json format.

These are original configuration jsons returned by the API. dnsme cat works from the local cache. Use dnsme updatedb to update the cache to see the latest changes.


Rate Limit

You are currently officially limited to 150 requests per 5 minutes. If you exceed the limit, your next commands fail. In case you write scripts using bash+, dnsme api command takes care of the rate limit by suspending your script for as long as needed.

Besides, working from local cache and updating it only when necessary should allow you to save on extra requests.

On top of this, as you have already seen, bash+ supports multi-record create/update operations. Creating/Updating/Deleting several records with one command also reduces the number of requests