How to use the command 'kdig' (with examples)
Kdig is an advanced DNS lookup utility that allows users to perform DNS queries with a great deal of precision and flexibility. Its features cater to network administrators, developers, and tech enthusiasts who need detailed DNS information for diagnostics or configuration purposes. The tool is versatile, capable of querying different DNS record types, using specific DNS servers, or employing privacy-focused protocols like DNS over TLS (DoT) and DNS over HTTPS (DoH). Below, we explore several use cases of kdig to illustrate its capabilities.
Use case 1: Lookup the IP(s) associated with a hostname (A records)
Code:
kdig example.com
Motivation:
This use case represents the most basic yet highly essential functionality of kdig, which is to resolve a domain name into its corresponding IP address(es). It is a fundamental operation needed by any networking application that relies on domain names to connect to the correct web server. Whether you are troubleshooting DNS issues or checking if a domain resolves correctly, fetching A records is a typical entry point for DNS investigation.
Explanation:
kdig
: This is the command itself, which initiates the DNS query tool.example.com
: This is the domain name for which we’re requesting A records. An A record maps a domain to its corresponding IPv4 address.
Example Output:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49426
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 300 IN A 192.0.2.1
;; Query time: 22 msec
;; SERVER: 192.0.2.53#53(192.0.2.53)
;; WHEN: Fri Oct 8 22:58:41 2021
;; MSG SIZE rcvd: 65
Use case 2: Specify a specific DNS server to query (e.g. Google DNS)
Code:
kdig example.com @8.8.8.8
Motivation:
In situations where the default DNS resolver might not be reliable or fast enough, or when testing configurations, selecting a specific DNS server like Google’s public DNS can yield results that are potentially more reliable or faster. It allows network professionals to test domain resolution in different contexts, for example, comparing results from different DNS providers.
Explanation:
kdig
: The command for the DNS lookup utility.example.com
: The target domain whose A records are being queried.@8.8.8.8
: Specifies Google’s public DNS server. The “@” character is used to denote a specific DNS resolver IP address.
Example Output:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57512
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 300 IN A 192.0.2.1
;; Query time: 19 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Oct 8 23:08:01 2021
;; MSG SIZE rcvd: 56
Use case 3: Query a specific DNS record type associated with a given domain name
Code:
kdig example.com A|AAAA|NS|SOA|DNSKEY|ANY
Motivation:
This command caters to situations where detailed information about a domain’s DNS configuration is required, beyond just the IP address. By querying for specific record types like AAAA (for IPv6), NS (nameservers), SOA (start of authority), or DNSKEY (DNSSEC keys), a user can gain insights vital for advanced diagnostics or configuration tasks. It lends a more comprehensive view of the domain and its DNS state.
Explanation:
kdig
: The DNS lookup command.example.com
: The domain name to query.A|AAAA|NS|SOA|DNSKEY|ANY
: Specifies the type of DNS record(s) to be queried. The use of a pipe (|
) allows the user to target multiple record types if supported in the terminal session.
Example Output:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19444
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2
;; QUESTION SECTION:
;example.com. IN ANY
;; ANSWER SECTION:
example.com. 300 IN A 192.0.2.1
example.com. 300 IN AAAA 2001:0db8::1
;; Query time: 23 msec
;; SERVER: 192.0.2.53#53(192.0.2.53)
;; WHEN: Fri Oct 8 23:20:02 2021
;; MSG SIZE rcvd: 108
Use case 4: Lookup the IP(s) associated with a hostname (A records) using DNS over TLS (DoT)
Code:
kdig -d @8.8.8.8 +tls-ca +tls-host=dns.google example.com
Motivation:
This example demonstrates querying a DNS server using DNS over TLS, an enhanced privacy protocol that encrypts DNS queries and responses to mitigate on-path attacks and provide confidentiality. It is suitable in scenarios where security is a concern, as it encrypts communication to prevent eavesdropping.
Explanation:
kdig
: The DNS command used to perform the lookup.-d
: Enables debug mode for detailed output, useful for troubleshooting.@8.8.8.8
: Specifies Google’s DNS server.+tls-ca
: This option uses the client’s certificate authority to validate the TLS connection.+tls-host=dns.google
: Indicates the host expected in the server’s certificate for verification.example.com
: The domain for which the A record is requested.
Example Output:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34926
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; TLS version: TLS 1.2
;; TLS session id: 3d2e2f2f982170ef5fef27d5dcda08f1...
;; TLS cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 300 IN A 192.0.2.1
;; Query time: 87 msec
;; SERVER: 8.8.8.8#853(dns.google)
;; WHEN: Fri Oct 8 23:28:41 2021
;; MSG SIZE rcvd: 65
Use case 5: Lookup the IP(s) associated with a hostname (A records) using DNS over HTTPS (DoH)
Code:
kdig -d @1.1.1.1 +https +tls-hostname=1dot1dot1dot1.cloudflare-dns.com example.com
Motivation:
DNS over HTTPS is an innovation similar to DNS over TLS, yet it uses HTTPS, a protocol widely accepted in modern web traffic, providing encryption and data integrity. It is particularly useful for users concerned with privacy and who want to ensure that their DNS queries are as secure as any web transaction.
Explanation:
kdig
: The tool to perform DNS queries.-d
: Debug mode for verbose output.@1.1.1.1
: Cloudflare’s DNS IP address.+https
: Enables DNS over HTTPS, ensuring the query and response are encrypted.+tls-hostname=1dot1dot1dot1.cloudflare-dns.com
: The endpoint validating the HTTPS connection, typical for DoH.example.com
: The domain name for which the user requests information.
Example Output:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5945
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; HTTP/2 200
;; Content-Type: application/dns-message
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 300 IN A 192.0.2.1
;; Query time: 102 msec
;; SERVER: 1.1.1.1#443(1dot1dot1dot1.cloudflare-dns.com)
;; WHEN: Fri Oct 8 23:35:18 2021
;; MSG SIZE rcvd: 72
Conclusion:
The kdig utility shines as a powerful, versatile command-line solution for performing DNS queries with an array of modern options tailored for security, speed, and flexibility. By enabling queries over encrypted channels and allowing specific DNS resolver selection, kdig addresses both standard needs and advanced cases, making it a must-have tool for network professionals and security-conscious individuals exploring the domain name system.