{"id":9162,"date":"2024-09-15T22:12:08","date_gmt":"2024-09-15T22:12:08","guid":{"rendered":"https:\/\/www.linuxandotherstuff.com\/?p=9162"},"modified":"2024-09-15T22:20:20","modified_gmt":"2024-09-15T22:20:20","slug":"dig-multiple-dns-records","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2024\/09\/15\/dig-multiple-dns-records\/","title":{"rendered":"Dig Multiple DNS records"},"content":{"rendered":"\n<p>Here is a script to dig multiple DNS records for a domain.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\nddig(){\n    domain=$1\n    if &#x5B;&#x5B; &quot;$domain&quot; == *.* ]]; then\n        dig1=$(dig +short $domain @8.8.4.4)\n        if &#x5B;&#x5B; -z &quot;$dig1&quot; ]]; then\n            echo &quot;No A record found for $domain&quot;\n        else\n            echo -e &quot;\\nA:\\t$dig1&quot;\n\n            ns_records=$(dig +short NS $domain @8.8.4.4)\n            if &#x5B;&#x5B; -z &quot;$ns_records&quot; ]]; then\n                echo -e &quot;NS:\\tNo NS records found&quot;\n            else\n                echo -e &quot;NS:\\t$ns_records&quot;\n            fi\n\n            # Handle multiple IPs by looping over them\n            for ip in $dig1; do\n                rdns=$(dig +short -x $ip @8.8.4.4)\n                if &#x5B;&#x5B; -z &quot;$rdns&quot; ]]; then\n                    echo -e &quot;rDNS:\\tNo PTR record for $ip&quot;\n                else\n                    echo -e &quot;rDNS:\\t$rdns&quot;\n                fi\n            done\n\n            mx_records=$(dig +short MX $domain @8.8.4.4)\n            if &#x5B;&#x5B; -z &quot;$mx_records&quot; ]]; then\n                echo -e &quot;MX:\\tNo MX records found&quot;\n            else\n                echo -e &quot;MX:\\t$mx_records&quot;\n            fi\n\n            txt_records=$(dig +short TXT $domain @8.8.4.4)\n            if &#x5B;&#x5B; -z &quot;$txt_records&quot; ]]; then\n                echo -e &quot;TXT:\\tNo TXT records found&quot;\n            else\n                echo -e &quot;TXT:\\t$txt_records&quot;\n            fi\n\n            dmarc_record=$(dig +short TXT _dmarc.$domain @8.8.4.4)\n            if &#x5B;&#x5B; -z &quot;$dmarc_record&quot; ]]; then\n                echo -e &quot;DMARC:\\tNo DMARC record found\\n&quot;\n            else\n                echo -e &quot;DMARC:\\t$dmarc_record\\n&quot;\n            fi\n        fi\n    else\n        echo &quot;Not a domain&quot;\n    fi\n}\n\n<\/pre><\/div>\n\n\n<p>To run the ddig function and get DNS information for a domain, you can follow these steps:<\/p>\n\n\n\n<p>Save the Script: Save the script as a .sh file, for example, ddig_script.sh.<\/p>\n\n\n\n<p>Make the Script Executable: Open your terminal, navigate to the directory where you saved the script, and make it executable using the following command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nchmod +x ddig_script.sh\n<\/pre><\/div>\n\n\n<p>Source the Script: To use the ddig function defined in the script, you need to source it in your current shell session:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsource ddig_script.sh\n<\/pre><\/div>\n\n\n<p>Alternatively, you can add the function directly to your .bashrc or .bash_profile file to have it available in all future terminal sessions.<\/p>\n\n\n\n<p>Run the Function: Now, you can use the ddig function by calling it with a domain as an argument. For example, to get the DNS information for example.com, run:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nddig example.com\n<\/pre><\/div>\n\n\n<p>This will execute the function and display the DNS records for the specified domain. Make sure you&#8217;re using a valid domain format (e.g., <code>example.com<\/code>) when passing the argument.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a script to dig multiple DNS records for a domain. To run the ddig function and get DNS information for a domain, you can follow these steps: Save the Script: Save the script as a .sh file, for example, ddig_script.sh. Make the Script Executable: Open your terminal, navigate to the directory where you &#8230; <a title=\"Dig Multiple DNS records\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2024\/09\/15\/dig-multiple-dns-records\/\" aria-label=\"Read more about Dig Multiple DNS records\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-9162","post","type-post","status-publish","format-standard","hentry","category-dns"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/9162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=9162"}],"version-history":[{"count":3,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/9162\/revisions"}],"predecessor-version":[{"id":9167,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/9162\/revisions\/9167"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=9162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=9162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=9162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}