The purpose of this article is to demonstrate how to use the AWS CLI Route53 Query functionality to search your DNS managed in Route53. This article will demonstrate two specific types of searches based on a single query parameter. One example for an IP based search and one example for a DNS name search.
AWS CLI Route53 DNS name search
To search for any DNS record by name, run the following aws cli route53 command.
aws route53 list-resource-record-sets --hosted-zone-id $HOSTED_ZONE --query "ResourceRecordSets[?Name == '$value.']"
Note the period after the $value parameter. It is required when searching by DNS name.
AWS CLI Route53 IP address search
To search for any DNS record by IP address, run the following aws cli route53 command.
aws route53 list-resource-record-sets --hosted-zone-id $HOSTED_ZONE --query "ResourceRecordSets[?ResourceRecords[?Value == '$value']]"
Take note of the different syntax of the DNS name search vs the IP address search.
AWS CLI Route53 Options
Here is a breakdown of each option in the route53 commands.
Option | Description |
list-resource-record-sets | Lists the DNS records |
–hosted-zone-id | The hosted zone id you are searching in |
–query | The query including the IP Address or name. Note the difference in syntax between the two different queries. |
Notably, the query is not intuitive and rather difficult to memorize. For that reason we have written a convenience bash script for searching route53 DNS by zone.
This example bash script simply checks the first digit of the value to determine the correct query syntax. To better validate the IP address consider this article: https://www.linuxjournal.com/content/validating-ip-address-bash-script
Additionally, you must populate the HOSTED_ZONE variable with your hosted zone id. The hosted zone id can be found using both the aws cli and in the aws console.
Conclusion
In conclusion, this article has demonstrated how to use the AWS CLI Route53 Query functionality to search your Amazon hosted DNS. If you would like to see more examples or have any questions, please leave us a comment. If you found this article, read more of our content.
Leave a Reply