Package: setmy53dns
setmy53dns - DNS updates for Route53The scenerio exists where a servers public (external) IP address can change over time.  This is especially true with cloud computing.This program can be used to update Route53 public zone records automatically when a server reboots or returns from hibernation, and can be used both in the cloud and on-prem if needed.Limitationssetmy53dnswill updateexistingDNS records - the records mustalready existin your Route53 zone.setmy53dnsdoesn't create or remove records.This is by design to prevent things from going wrong.setmy53dnsupdatesAandAAAADNS records; other records are not supported.setmy53dns Command Usage and OptionsAfter configuringsetmy53dnsis simple to use and in most instances does not require any special switchs.%setmy53dnsThis willautomaticallyfind your public IP address and update the dns zone record based on thefully qualifed domain name(fqdn) of your computer.In a more complex configuration you can use a different name or multiple ip address.%setmy53dns--fqdnfirst.example.com%setmy53dns--fqdnsecond.example.com-ip100.100.22.23A list of all availabe options:% setmy53dns --help
usage: setmy53dns [-h] [-v] [-ip IP] [-fqdn FQDN] [-q] [-z ZONE] [-6]

Update Route53 IP record

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -ip IP, --ip IP       set specific IP address to use
  -fqdn FQDN, --fqdn FQDN
                        Fully Qualified Domain Name (rkmbp.sunyocc.edu)
  -q, --query           Query only - no updates are made
  -z ZONE, --zone ZONE  Route53 Zone to update (optional)
  -6                    Update AAAA record (default is A record)

setmy53dns gunville 2022 v1Automatic IP detection:By defaultsetmyipautomatically detects the public IP address by sending an HTTP request toicanhazip.com. This site returns the IP address of the sender.You can optionally use a different site to autodetect the public ip by setting the environment variableIPAPIURLto that URL:%IPAPIURL='http://api.ipify.org'%setmy53dnsWhen ipv6 is selected with the-6switch automatic detection uses the ipv6 stack.icanhazip.comworks with both ipv4 and ipv6.If your host has multiple ip addresses or uses a proxy for web requests you will need to provide the ip address to use with the--ip IPcommand line switch.%setmy53dns--ip100.123.4.56
%setmy53dns-6--ip2600:1f16:a44:1701:1be3:f8b7:aa51:410bAutomatic Hostname Determination:The fqdn of the host is acquired with the Pythonsocket.gethostname()function. (Several solutions were tried, none worked perfect, but this one seems to work best.)There are some limitations to hostname determination:Some systems are not configured to provide the fqdn (web01.example.com) and provide only the short hostname (web01). There is no elegant and simple solution that works on all platforms and configurations.In some environments the hostname on the private side (e.g. web01.local) is not the same one used on the public side (web01.example.com).Likewise, cloud VPCs by default provide hostnames in a similar fashion (e.g.ip-172-31-84-22.ec2.internal)In these cases you will be required to provide the full fqdn with the--fqdn FQDNswitch.%setmy53dns--fqdnweb01.example.comRoute53 Zone selection:The Route53 zone is selected from the FQDN, but can also explicity provided with the--zone ZONEswitch.If the--zoneswitch is used the the zone does not match the hostname determined above, the fqdn is constructed by appending the zone.%hostname
server1
%setmy53dns--fqdnserver1.example.com# server1.example.com%setmy53dns--fqdnserver1--zoneexample.com# server1.example.com%setmy53dns--zoneeample.com# server1.example.comThe above are identical. Note that thefqdndoes not have to be 'fully qualified' when the--zoneswitch is used.IPv6 SupportBoth ipv4Aand ipv6AAAADNS records are supported bysetmy53dns.  To update ipv6 records the-6switch is used - and required.%setmy53dns-6Installation and Configurationsetmy53dnsis easily installed usingpip%pipinstallsetmy53dnsAWS CredentialsThe AWS user or role used forsetmy53dnsmust have these permissions to make updates:route53:ListHostedZonesto Route53route:53ChangeResourceRecordSetsandroute53:ListResourceRecordSetsto the zones that will be updated.with IAM the smallest resource scope to assign privileges is a zone.For EC2 instances privileges can be granted with a role attached to an EC2 instance.Otherwise they are provided with an AWS credentials file containing API keys to an account that has these privileges granted. (though environment variables can be used.)Configuringsetmy53dnsto Run On Reboots (optional)The followingcrontabentry will runsetmy53dnseach time the server reboots.@reboot /usr/local/bin/setmy53dnsThe actual path depends on where you installsetmy53dnsConfiguringsetmy53dnsTo Run Post Hibernation (optional)This may differ some depending on the operating system. This example here works with RedHat flavors.Create the following file in/lib/systemd/system-sleep/Add these contents of the fileSet the file to be excutable%sudotouch/lib/systemd/system-sleep/20_cfdns
%sudochomd+x/lib/systemd/system-sleep/20_cfdns
%cat>/lib/systemd/system-sleep/20_cfdns<<EOF#!/usr/bin/env bashaction="$1/$2"case "$action" inpre/hibernate);;post/hibernate)/usr/local/bin/setmy53dns;;esacEOFThe actual path depends on where you installsetmy53dns