DNS Lookup Utility with Examples

DNS Lookup Utility with Examples

The dog command is a DNS lookup utility that can be used to query DNS servers and retrieve information about DNS records. It supports various protocols like DNS-over-TLS and DNS-over-HTTPS, and can also emit JSON.

In this article, we will explore different use cases of the dog command and provide code examples for each case. Each example will be accompanied by a motivation for using it, an explanation of every argument used, and an example output.

Example 1: Lookup the IP(s) associated with a hostname (A records)

dog example.com

Motivation:

This example allows you to retrieve the IP addresses associated with a given hostname. It can be useful when you want to verify the IP address of a website or check if the DNS records are properly configured.

Explanation:

The command dog example.com queries the DNS server for the IP address(es) associated with the hostname “example.com”. It uses the default DNS server configured on the system.

Example output:

example.com.            779     IN      A       93.184.216.34

Example 2: Query the MX records type associated with a given domain name

dog example.com MX

Motivation:

This example allows you to retrieve the mail exchange (MX) records associated with a domain name. MX records specify the mail server responsible for accepting email messages on behalf of the domain.

Explanation:

The command dog example.com MX queries the DNS server for the MX records associated with the domain name “example.com”. It retrieves the mail servers responsible for handling email for the domain.

Example output:

example.com.            299     IN      MX      10 mail.example.com.

Example 3: Specify a specific DNS server to query

dog example.com MX @1.1.1.1

Motivation:

This example allows you to specify a specific DNS server to query. It can be useful when you want to test the DNS resolution using a different DNS server than the default one.

Explanation:

The command dog example.com MX @1.1.1.1 queries the DNS server at IP address “1.1.1.1” for the MX records associated with the domain name “example.com”.

Example output:

example.com.            299     IN      MX      10 mail.example.com.

Example 4: Query over TCP rather than UDP

dog example.com MX @1.1.1.1 --tcp

Motivation:

This example allows you to query DNS over TCP rather than the default UDP. TCP can handle larger responses and is useful when dealing with DNS queries that generate large replies.

Explanation:

The command dog example.com MX @1.1.1.1 --tcp queries the DNS server at IP address “1.1.1.1” for the MX records associated with the domain name “example.com” using TCP instead of UDP.

Example output:

example.com.            299     IN      MX      10 mail.example.com.

Example 5: Query the MX records type associated with a given domain name over TCP using explicit arguments

dog --query example.com --type MX --nameserver 1.1.1.1 --tcp

Motivation:

This example illustrates how to query DNS records using explicit command-line arguments instead of relying on the positional arguments. It provides more flexibility when constructing complex queries.

Explanation:

The command dog --query example.com --type MX --nameserver 1.1.1.1 --tcp queries the DNS server at IP address “1.1.1.1” for the MX records associated with the domain name “example.com” using TCP. It uses the --query flag to specify the domain name, the --type flag to specify the record type, the --nameserver flag to specify the DNS server, and the --tcp flag to indicate TCP protocol.

Example output:

example.com.            299     IN      MX      10 mail.example.com.

Example 6: Lookup the IP(s) associated with a hostname (A records) using DNS over HTTPS (DoH)

dog example.com --https @https://cloudflare-dns.com/dns-query

Motivation:

This example demonstrates the use of DNS over HTTPS (DoH) protocol, which encrypts the DNS queries and responses using HTTPS. It provides privacy and security while performing DNS lookups.

Explanation:

The command dog example.com --https @https://cloudflare-dns.com/dns-query queries the DNS server at “https://cloudflare-dns.com/dns-query" for the IP address(es) associated with the hostname “example.com” using DNS over HTTPS.

Example output:

example.com.            779     IN      A       93.184.216.34

Conclusion

In this article, we explored various use cases of the dog command for performing DNS lookups. We illustrated different scenarios, including looking up IP addresses, querying MX records, specifying custom DNS servers, using TCP instead of UDP, and utilizing DNS over HTTPS. These examples serve as a starting point for utilizing the dog command effectively in your DNS-related tasks.

Related Posts

Using getopt (with examples)

Using getopt (with examples)

Using getopt to parse optional verbose/version flags getopt --options vV --longoptions verbose,version -- --version --verbose Motivation: In some scripts or programs, it may be useful to offer command-line options to control the behavior of the program.

Read More
w32tm Command Examples (with examples)

w32tm Command Examples (with examples)

Example 1: Show the current status of time synchronization w32tm /query /status /verbose Motivation The motivation for checking the current status of time synchronization is to ensure that the clock on the system is synchronized correctly with a reliable time source.

Read More
How to use the command 'pio system' (with examples)

How to use the command 'pio system' (with examples)

The ‘pio system’ command provides various system-level functionalities for PlatformIO. It allows users to install and uninstall shell completion, display system-wide information, and remove unused or cached data.

Read More