Created
January 27, 2020 19:48
-
-
Save alsunseri/328bdb8fe8e2e6aca89f4aba8cfd00f2 to your computer and use it in GitHub Desktop.
dynamic DNS from clouDNS on GCP/Amazon linux VM instances with systemctl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a work in progress. | |
Using cloudns for dynamic DNS - get your AWS or EC2 server to use dynamic DNS at boot. | |
Get new dynamic DNS update via cloudns when systemctl starts on VM instances such as GCP and EC2. | |
I have a zone hosted in cloudns so this is a plus, I dont know if you can use this without a full zone of your own. | |
These are the steps | |
1. Make a new A record for the VM that you want to use in a zone file on cloudns | |
2. click the "Active Dynamic URL" button to popup the dynamic DNS info box. | |
You will see a wget one line command; plus links to perl and python scripts etc - for that specific hostname. | |
You can use wget command in crontab - BUT - upload the perl or python script to /root/bin on the vm. | |
Perl works fine for Ubuntu - but AWS Linux has an OLD version of Tiny::HTTP so USE PYTHON ON AWS Linux | |
WGET will not work via this systemctl service - I dont know why yet. | |
3. Download ( and RENAME ) the perl or python script - | |
each script is custom for that single "A" hostname. | |
Each script has a custom ID for that particular hostname. | |
4. Upload the script to the VM and place it in /root/bin/ or similar | |
5. Create the 2-3 line bach script to run the script provided by CloudNS | |
i.e. /root/bin/update-cloudns-dynamic-ip.sh | |
#!/bin/bash | |
/usr/bin/python /root/bin/al2-dynamic-url-python.py | |
exit | |
You can add whatever monitoring / sanity checks you want to this script etc. | |
6. Create a new file to use as a new "simple service" for systemctl: | |
Create this file as cloudns-dynamic-ip.service in the folder /etc/systemd/system/ | |
i.e.: | |
[root@ip-172-23-23-23 ~]# vim /etc/systemd/system/cloudns-dynamic-ip.service | |
[Unit] | |
Description=UPDATE Dynamic DNS via cloudns | |
[Service] | |
Type=simple | |
ExecStart=/bin/bash /root/bin/update-cloudns-dynamic-ip.sh | |
[Install] | |
WantedBy=default.target | |
[root@ip-172-23-23-23 ~]# | |
7. enable the new "service" | |
[root@ip-172-23-23-23 ~]# systemctl enable cloudns-dynamic-ip | |
Created symlink from /etc/systemd/system/default.target.wants/cloudns-dynamic-ip.service to /etc/systemd/system/cloudns-dynamic-ip.service. | |
8. Start the service ( this will execute the script ) | |
[root@ip-172-23-23-23 ~]# systemctl start cloudns-dynamic-ip | |
9. run this to see that it ran the script sucessfully: | |
[root@ip-172-23-23-23 ~]# systemctl status cloudns-dynamic-ip | |
You can also check with the DNS server to make sure it has the new value. | |
Finally - using the wget command from CLOUDNS - make a cron job for hourly updates in case the lease changes while server is up etc. | |
25 * * * * wget -q --read-timeout=0.0 --waitretry=5 --tries=30 --background https://ipv4.cloudns.net/api/dynamicURL/?q=base64ID | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment