Let's take a common example of a DNS setup. Your domain is example.com
, and you have "A
" records for server1.example.com
and server2.example.com
. Server1 is hosted in Vultr, but server2 is hosted on a local network, like inside your business or as a development machine in your home. Typically, these types of local environments have public IP addresses are dynamically assigned from your Internet Service Provider (ISP), and they may change unexpectedly. This would result in server2 suddenly pointing to a wrong IP address which could severely affect service. This article will show you how to set up your own dynamic DNS service, which runs on a local machine and can update the record for server2 in Vultr DNS automatically after a public IP change.
While clients like
ddclient
andinadyn
will work for some DNS providers, Vultr does not currently support these and instead uses its own custom API. This service will run locally on your machine and use GET and POST requests along with your access key.
A
" records are supported by this utility. If you have multiple "A
" records that you want updated to the same IP address, change them to "CNAME
" records and point them to one "A
" record. This will simplify things for you in the long run and is considered the proper way to configure DNS.Use Git to clone the repository containing the python DDNS client. You should do this in a safe directory for which you have full access. Your home folder should be sufficient. Run the following command:
git clone https://github.com/andyjsmith/Vultr-Dynamic-DNS.git vultrddns && cd vultrddns
Generate a personal access token in Vultr. This can be done under "Account -> API -> Personal Access Token". On that same page, you will need to go under "Access Control" and click the "Allow All IPv4" button, since you will not know the IP of your local server every time, hence the point of dynamic DNS.
config.json.example
file for an example of what your configuration file should look like.config.json
file using your favorite text editor and fill out the values based on your specific server setup.The file should contain the following:
{
"api_key": "",
"domain": "",
"dynamic_records": [
""
]
}
Enter your access token into the field api_key
.
domain
field. For example, example.com
.A
" records you want to change under the dynamic_records
field. Using the previous example, you would enter server2
to automatically change server2
's IP address. You may enter multiple subdomains. If you want to change the base "A
" record for your domain (commonly referenced as an @
, the record that responds when you navigate straight to example.com
), simply leave empty quotes.A proper config file may look like this, where you want to dynamically change the IP for example.com
and server2.example.com
:
{
"api_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"domain": "example.com",
"dynamic_records": [
"",
"server2"
]
}
Now save these changes and your file should be good to go!
python3 ddns.py
. If this does not return any errors, your configuration is nominal and you can start the automation process.After completing the basic setup, it is important to set up a recurring task as the script does not do this by default. Connect to your local machine and follow the steps below based on your operating system.
Linux and Mac have the cron
utility already installed, which lets you specify scripts to run on set schedules.
ddns.py
file using realpath ddns.py
while still in the vultrddns
directory.crontab -e
to edit your crontab.Add the following line to the end of the file, adding in the real path to the ddns.py
file:
*/30 * * * * cd [full path to ddns.py] && python3 ddns.py > /dev/null 2>&1
This will run the script every 30 minutes and redirect all of its output to /dev/null
.
Create a task in Task Scheduler to run every 30 minutes. Follow the Microsoft guide for basic task creation.
ddns.py
script as an argument.You could earn up to $300 by adding new articles