## setmy53dns - DNS updates for Route53
The 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.
### Limitations
`setmy53dns` will update ***existing*** DNS records - the records must ***already exist*** in your Route53 zone.
`setmy53dns` doesn't create or remove records.
This is by design to prevent things from going wrong.
`setmy53dns` updates **A** and **AAAA** DNS records; other records are not supported.
## setmy53dns Command Usage and Options
After configuring `setmy53dns` is simple to use and in most instances does not require any special switchs.
```bash
% setmy53dns
```
This will **automatically** find your public IP address and update the dns zone record based on the *fully qualifed domain name* (fqdn) of your computer.
In a more complex configuration you can use a different name or multiple ip address.
```bash
% setmy53dns --fqdn first.example.com
% setmy53dns --fqdn second.example.com -ip 100.100.22.23
```
A 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 2025 v2
```
#### Automatic IP detection:
By default `setmyip` automatically detects the public IP address by sending an HTTP request to [ipv4.icanhazip.com](http://ipv4.icanhazip.com). This site returns the IPv4 address of the sender.
You can optionally use a different site to autodetect the public ip by setting the environment variable `IPAPIURL` to that URL:
```bash
% IPAPIURL='http://api.ipify.org'
% setmy53dns
```
When ipv6 is selected with the `-6` switch automatic detection uses the ipv6 stack. [ipv6.icanhazip.com](http://ipv6.icanhazip.com). This can be overriden with the environment variable `IPV6APIURL`.
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 IP` command line switch.
```bash
% setmy53dns --ip 100.123.4.56
% setmy53dns -6 --ip 2600:1f16:a44:1701:1be3:f8b7:aa51:410b
```
#### Automatic Hostname Determination:
The fqdn of the host is acquired with the Python `socket.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 FQDN` switch.
```bash
% setmy53dns --fqdn web01.example.com
```
#### Route53 Zone selection:
The Route53 zone is selected from the FQDN, but can also explicity provided with the `--zone ZONE` switch.
If the `--zone` switch is used the the zone does not match the hostname determined above, the fqdn is constructed by appending the zone.
```bash
% hostname
server1
% setmy53dns --fqdn server1.example.com # server1.example.com
% setmy53dns --fqdn server1 --zone example.com # server1.example.com
% setmy53dns --zone eample.com # server1.example.com
```
The above are identical. Note that the `fqdn` does not have to be 'fully qualified' when the `--zone` switch is used.
#### IPv6 Support
Both ipv4 **A** and ipv6 **AAAA** DNS records are supported by `setmy53dns`. To update ipv6 records the `-6` switch is used - and required.
```bash
% setmy53dns -6
```
# Installation and Configuration
`setmy53dns` is easily installed using `pip`
```bash
% pip install setmy53dns
```
#### AWS Credentials
* The AWS user or role used for `setmy53dns` must have these permissions to make updates:
* `route53:ListHostedZones` to Route53
* `route:53ChangeResourceRecordSets` and `route53:ListResourceRecordSets` to 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.)
#### Configuring `setmy53dns` to Run On Reboots (optional)
The following `crontab` entry will run `setmy53dns` each time the server reboots.
```
@reboot /usr/local/bin/setmy53dns
```
The actual path depends on where you install `setmy53dns`
#### Configuring `setmy53dns` To 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 file
* Set the file to be excutable
```bash
% sudo touch /lib/systemd/system-sleep/20_cfdns
% sudo chomd +x /lib/systemd/system-sleep/20_cfdns
% cat > /lib/systemd/system-sleep/20_cfdns <<EOF
#!/usr/bin/env bash
action="$1/$2"
case "$action" in
pre/hibernate)
;;
post/hibernate)
/usr/local/bin/setmy53dns
;;
esac
EOF
```
The actual path depends on where you install `setmy53dns`
Raw data
{
"_id": null,
"home_page": "https://github.com/Glocktober/setmy53dns",
"name": "setmy53dns",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "'route53 cloud dns'",
"author": "gunville",
"author_email": "rk13088@yahoo.com",
"download_url": "https://files.pythonhosted.org/packages/50/a0/931312022c9892e4e29ef35ab8ebbbc06837fcf44a8437cfffc31cdcb147/setmy53dns-24.12.25.tar.gz",
"platform": null,
"description": "\n## setmy53dns - DNS updates for Route53\n\nThe scenerio exists where a servers public (external) IP address can change over time. This is especially true with cloud computing. \n\nThis 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.\n\n### Limitations\n`setmy53dns` will update ***existing*** DNS records - the records must ***already exist*** in your Route53 zone. \n\n`setmy53dns` doesn't create or remove records. \n\nThis is by design to prevent things from going wrong.\n\n`setmy53dns` updates **A** and **AAAA** DNS records; other records are not supported.\n\n## setmy53dns Command Usage and Options\nAfter configuring `setmy53dns` is simple to use and in most instances does not require any special switchs.\n```bash\n % setmy53dns \n```\nThis will **automatically** find your public IP address and update the dns zone record based on the *fully qualifed domain name* (fqdn) of your computer.\n\nIn a more complex configuration you can use a different name or multiple ip address.\n```bash\n % setmy53dns --fqdn first.example.com\n % setmy53dns --fqdn second.example.com -ip 100.100.22.23\n```\nA list of all availabe options:\n```\n% setmy53dns --help\nusage: setmy53dns [-h] [-v] [-ip IP] [-fqdn FQDN] [-q] [-z ZONE] [-6]\n\nUpdate Route53 IP record\n\noptional arguments:\n -h, --help show this help message and exit\n -v, --version show program's version number and exit\n -ip IP, --ip IP set specific IP address to use\n -fqdn FQDN, --fqdn FQDN\n Fully Qualified Domain Name (rkmbp.sunyocc.edu)\n -q, --query Query only - no updates are made\n -z ZONE, --zone ZONE Route53 Zone to update (optional)\n -6 Update AAAA record (default is A record)\n\nsetmy53dns gunville 2025 v2\n```\n#### Automatic IP detection:\n\nBy default `setmyip` automatically detects the public IP address by sending an HTTP request to [ipv4.icanhazip.com](http://ipv4.icanhazip.com). This site returns the IPv4 address of the sender.\n\nYou can optionally use a different site to autodetect the public ip by setting the environment variable `IPAPIURL` to that URL:\n```bash\n% IPAPIURL='http://api.ipify.org'\n% setmy53dns\n```\nWhen ipv6 is selected with the `-6` switch automatic detection uses the ipv6 stack. [ipv6.icanhazip.com](http://ipv6.icanhazip.com). This can be overriden with the environment variable `IPV6APIURL`.\n\nIf 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 IP` command line switch.\n\n```bash\n% setmy53dns --ip 100.123.4.56\n% setmy53dns -6 --ip 2600:1f16:a44:1701:1be3:f8b7:aa51:410b \n```\n\n#### Automatic Hostname Determination:\n\nThe fqdn of the host is acquired with the Python `socket.gethostname()` function. (Several solutions were tried, none worked perfect, but this one seems to work best.)\n\nThere are some limitations to hostname determination:\n* 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. \n\n* 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).\n\n* Likewise, cloud VPCs by default provide hostnames in a similar fashion (e.g. *ip-172-31-84-22.ec2.internal*)\n\nIn these cases you will be required to provide the full fqdn with the `--fqdn FQDN` switch.\n```bash\n% setmy53dns --fqdn web01.example.com \n```\n\n#### Route53 Zone selection:\n\nThe Route53 zone is selected from the FQDN, but can also explicity provided with the `--zone ZONE` switch.\n\nIf the `--zone` switch is used the the zone does not match the hostname determined above, the fqdn is constructed by appending the zone.\n```bash\n% hostname\nserver1\n% setmy53dns --fqdn server1.example.com # server1.example.com\n% setmy53dns --fqdn server1 --zone example.com # server1.example.com\n% setmy53dns --zone eample.com # server1.example.com\n```\n\nThe above are identical. Note that the `fqdn` does not have to be 'fully qualified' when the `--zone` switch is used.\n\n#### IPv6 Support\n\nBoth ipv4 **A** and ipv6 **AAAA** DNS records are supported by `setmy53dns`. To update ipv6 records the `-6` switch is used - and required.\n\n```bash\n% setmy53dns -6\n```\n\n# Installation and Configuration\n`setmy53dns` is easily installed using `pip`\n```bash\n% pip install setmy53dns\n```\n\n#### AWS Credentials\n\n* The AWS user or role used for `setmy53dns` must have these permissions to make updates:\n * `route53:ListHostedZones` to Route53\n * `route:53ChangeResourceRecordSets` and `route53:ListResourceRecordSets` to the zones that will be updated.\n * with IAM the smallest resource scope to assign privileges is a zone.\n* For EC2 instances privileges can be granted with a role attached to an EC2 instance.\n* 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.)\n\n#### Configuring `setmy53dns` to Run On Reboots (optional)\n\nThe following `crontab` entry will run `setmy53dns` each time the server reboots. \n```\n@reboot /usr/local/bin/setmy53dns\n```\nThe actual path depends on where you install `setmy53dns`\n\n#### Configuring `setmy53dns` To Run Post Hibernation (optional)\nThis may differ some depending on the operating system. This example here works with RedHat flavors.\n* Create the following file in `/lib/systemd/system-sleep/`\n* Add these contents of the file \n* Set the file to be excutable\n\n```bash\n% sudo touch /lib/systemd/system-sleep/20_cfdns\n% sudo chomd +x /lib/systemd/system-sleep/20_cfdns\n% cat > /lib/systemd/system-sleep/20_cfdns <<EOF\n#!/usr/bin/env bash\naction=\"$1/$2\"\ncase \"$action\" in\n pre/hibernate)\n ;;\n post/hibernate)\n\t/usr/local/bin/setmy53dns\n ;;\nesac\nEOF\n```\nThe actual path depends on where you install `setmy53dns`\n",
"bugtrack_url": null,
"license": null,
"summary": "Updates a hosts Route53 record for use on reboot or waken from hibernation",
"version": "24.12.25",
"project_urls": {
"Homepage": "https://github.com/Glocktober/setmy53dns",
"overview": "https://github.com/Glocktober/setmy53dns/blob/master/README.md",
"repo": "https://github.com/Glocktober/setmy53dns.git"
},
"split_keywords": [
"'route53",
"cloud",
"dns'"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "da4c2f035799b67ba232644de79812d72bd06b6c5cde82d35b6667bd80ef75a7",
"md5": "4581a2d613df6a2410151ceb48c9dfaa",
"sha256": "3e3abf62c1d78f4f61dd8f3fd0f8516297150b3239648fd62d825da7f9415577"
},
"downloads": -1,
"filename": "setmy53dns-24.12.25-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4581a2d613df6a2410151ceb48c9dfaa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9488,
"upload_time": "2024-12-26T03:39:00",
"upload_time_iso_8601": "2024-12-26T03:39:00.533848Z",
"url": "https://files.pythonhosted.org/packages/da/4c/2f035799b67ba232644de79812d72bd06b6c5cde82d35b6667bd80ef75a7/setmy53dns-24.12.25-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "50a0931312022c9892e4e29ef35ab8ebbbc06837fcf44a8437cfffc31cdcb147",
"md5": "c7553497ce75ba090f869fa0c5cc7222",
"sha256": "bdd2481dbde63b81468d4fdcf176a9ee1cc5f23b39e20c91e35d162bd01fbd51"
},
"downloads": -1,
"filename": "setmy53dns-24.12.25.tar.gz",
"has_sig": false,
"md5_digest": "c7553497ce75ba090f869fa0c5cc7222",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11072,
"upload_time": "2024-12-26T03:39:03",
"upload_time_iso_8601": "2024-12-26T03:39:03.455075Z",
"url": "https://files.pythonhosted.org/packages/50/a0/931312022c9892e4e29ef35ab8ebbbc06837fcf44a8437cfffc31cdcb147/setmy53dns-24.12.25.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-26 03:39:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Glocktober",
"github_project": "setmy53dns",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "boto3",
"specs": [
[
"==",
"1.20.54"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.27.1"
]
]
}
],
"lcname": "setmy53dns"
}