
Are you tired of long, complex dig
commands cluttering your terminal? Wouldn’t it be great to consolidate all the essential DNS information into a single, well-organized report?
With a simple shell script, you can streamline your dig
output into a clean, easy-to-read table. Let’s build a tool called dnsreport
that presents all the critical DNS details at a glance.
Creating the dnsreport
Script
1: Create the Script File
First, let’s create a new script file:
touch ~/bin/dnsreport.sh
2: Open the File in Your Favourite Editor
vi ~/bin/dnsreport.sh
3: Add the Following Code
#!/bin/bash
# Check if the required arguments are provided
if [ $# -ne 4 ]; then
echo "Usage: $0 <DOMAIN> <NS1> <NS2> <PARENT_SERVER>"
exit 1
fi
# Set the variables from the command line arguments
DOMAIN=$1
NS1=$2
NS2=$3
PARENT_SERVER=$4
echo "# DNS Report"
echo ""
echo "## Parent and Domain Name Servers"
echo "| Category | Value |"
echo "| --- | --- |"
echo "| Parent Server | $PARENT_SERVER |"
echo "| Name Servers | $(dig +short NS $DOMAIN @$PARENT_SERVER) |"
echo ""
echo "## Name Servers A Records"
echo "| Name Server | A Record |"
echo "| --- | --- |"
echo "| $NS1 | $(dig +short A $NS1) |"
echo "| $NS2 | $(dig +short A $NS2) |"
echo ""
echo "## Name Servers AAAA Records"
echo "| Name Server | AAAA Record |"
echo "| --- | --- |"
echo "| $NS1 | $(dig +short AAAA $NS1) |"
echo "| $NS2 | $(dig +short AAAA $NS2) |"
echo ""
echo "## Name Servers and NS Records"
echo "| Name Server | NS Records |"
echo "| --- | --- |"
echo "| $NS1 | $(dig +short NS $DOMAIN @$NS1) |"
echo "| $NS2 | $(dig +short NS $DOMAIN @$NS2) |"
echo ""
echo "## DNS Servers Responded"
echo "| Category | Value |"
echo "| --- | --- |"
echo "| DNS Servers | $(dig +short NS $DOMAIN) |"
echo ""
echo "## Mismatched NS Records"
echo "| Category | Value |"
echo "| --- | --- |"
echo "| Mismatched NS | $(dig +short NS $DOMAIN @$PARENT_SERVER) |"
echo ""
echo "## Recursive Queries"
echo "| Name Server | Recursive Query |"
echo "| --- | --- |"
echo "| $NS1 | $(dig +short NS $DOMAIN @$NS1 +norecurse) |"
echo "| $NS2 | $(dig +short NS $DOMAIN @$NS2 +norecurse) |"
echo ""
echo "## Multiple Name Servers and Multiple Subnets"
echo "| Category | Value |"
echo "| --- | --- |"
echo "| Multiple Name Servers | $(dig +short NS $DOMAIN) |"
echo "| Multiple Subnets | $(dig +short NS $DOMAIN) |"
echo ""
echo "## Public IPs for Name Servers"
echo "| Name Server | Public IP |"
echo "| --- | --- |"
echo "| $NS1 | $(dig +short A $NS1) |"
echo "| $NS2 | $(dig +short A $NS2) |"
echo ""
echo "## Name Servers Respond by TCP"
echo "| Name Server | TCP Response |"
echo "| --- | --- |"
echo "| $NS1 | $(dig +tcp +short NS $DOMAIN @$NS1) |"
echo "| $NS2 | $(dig +tcp +short NS $DOMAIN @$NS2) |"
echo ""
echo "## SOA Record"
echo "| Category | Value |"
echo "| --- | --- |"
echo "| SOA Record | $(dig +short SOA $DOMAIN @$NS1) |"ervers responded"
dig +short NS $DOMAIN
echo "Mismatched NS records"
dig +short NS $DOMAIN @$PARENT_SERVER
echo "Recursive Queries"
dig +short NS $DOMAIN @$NS1 +norecurse
dig +short NS $DOMAIN @$NS2 +norecurse
echo "Multiple name servers\tMultiple subnets"
dig +short NS $DOMAIN
echo "Public IPs for name servers"
dig +short A $NS1
dig +short A $NS2
echo "Name servers respond by TCP"
dig +tcp +short NS $DOMAIN @$NS1
dig +tcp +short NS $DOMAIN @$NS2
echo "SOA\tSOA record"
dig +short SOA $DOMAIN @$NS1
4: Make the Script Executable
chmod +x ~/bin/dnsreport.sh
5: Run the Script
.~/bin/dnsreport.sh example.com ns1.example.com ns2.example.com parent-dns.com
Conclusion
You now have a powerful one-command solution to get a structured, readable DNS report using dig
. This script makes it easy to check multiple DNS records without running long, repetitive commands.
Want to customize the output further? Modify the script to include additional dig
queries or format the results differently.
What's next?!
Try modifying dnsreport on your terminal and show us what you've done in the comments!