Resolve-DNSname: PowerShell DNS Lookup
Let’s look at a very cool and powerful DNS troubleshooting tool that is included as a PowerShell cmdlet. The Resolve-DnsName PowerShell cmdlet is a tool that includes the features of many of the legacy command line tools. Let’s see how to use it.
Table of contents
- Understanding DNS
- Resolve-DnsName
- Resolve-DnsName can replace other tools
- Resolve-DnsName Parameters
- Use Case: Mail Routing Information
- The Impact of Hosts File on DNS Resolution
- Resolve-DnsName examples
- Example 1: Simple DNS Query
- Example 2: Specifying DNS Query Type
- Example 3: Querying a Specific DNS Server
- Example 4: Resolving CNAME Records
- Example 5: Finding Authority Zone
- Example 6: Getting TXT Records
- Example 7: Resolving PTR Records
- Example 8: Utilizing the Pipeline
- Example 9: Obtaining Fully Qualified Domain Names (FQDNs)
- Awesome DNS Server for home
- Wrapping Up
Understanding DNS
DNS has been called by many the “phone book” of the Internet. It allows us to resolve or translate IP addresses that aren’t very easy to remember, into domain names that are much easier to remember. So, it is a very important layer in modern computer networking.
Resolve-DnsName
PowerShell has a cmdlet called Resolve-DnsName. It can do DNS lookups and return a lot of information about the name of the resource. It can look up different DNS record types and is a tool that is good to remember when troubleshooting connectivity issues or any other problem where DNS could be in play.
PowerShell is built into Windows and is readily available with handy cmdlets for troubleshooting.
Below, we are running the Resolve-DNSName
cmdlet.
Resolve-DnsName can replace other tools
Here are a few of those traditional tools that PowerShell’s Resolve-DnsName can replace if you want to use it instead of other tools.
NSLookup
NSLookup is a command-line tool for querying the DNS system to obtain domain names or IP address mapping or other DNS records. It’s been a default component of Windows for many years. However, Resolve-DnsName provides a more PowerShell-friendly DNS query experience with enhanced functionality and more flexible output.
Dig
Dig (Domain Information Groper) is a Linux utility for querying DNS servers. It is known for being a great tool for investigating DNS records. However, it’s not installed by default on many systems, and its use involves a syntax that can be challenging for some users. Resolve-DnsName is a tool for Windows users that can perform the same types of queries without installing additional software or having access to a Linux box.
Resolve-DnsName Parameters
Resolve-DnsName cmdlet provides many different parameters that allow the customization of DNS queries. For instance, you can tell the cmdlet you want the DNS query type to be a certain type and the DNS record you want, such as A, AAAA, CNAME, MX, NS, PTR, SOA, SRV, or TXT.
Use Case: Mail Routing Information
A common use case for Resolve-DnsName is checking mail routing information. You can determine a domain’s mail forwarder by querying MX records. This information is critical for troubleshooting mail delivery issues or configuring mail servers.
The Impact of Hosts File on DNS Resolution
The hosts file can affect the outcome of DNS queries. Before the Resolve-DnsName cmdlet hits the DNS server, it checks the local hosts file for entries. This can provide a means to test DNS changes without modifying actual DNS records.
Also, if you are looking to bypass the hosts file, Resolve-DNSName has a parameter that allows easily using only DNS resolution to help determine if a stale hostname is in play. We will show an example of that below.
Resolve-DnsName examples
Below are a few examples of using the Resolve-DNSName cmdlet to investigate DNS records.
Example 1: Simple DNS Query
The most basic use of Resolve-DnsName is to perform a simple DNS query. The syntax is straightforward:
Resolve-DnsName -Name "www.example.com"
This command will return different DNS records associated with “www.example.com“. By default, this includes A (IPv4) and AAAA (IPv6) records which provide the IP address(es) for the queried domain.
Example 2: Specifying DNS Query Type
The Resolve-DnsName cmdlet can take parameters where you tell it what kind of DNS record you wish to query using the -Type parameter. For example, if you want to retrieve MX (Mail Exchange) records, use the following command:
Resolve-DnsName -Name "example.com" -Type MX
This command will return MX records, providing mail routing and mail destination information for “example.com“.
Example 3: Querying a Specific DNS Server
Sometimes you may need to perform DNS lookups against a specific DNS server. You can do this using the -Server parameter:
Resolve-DnsName -Name "www.example.com" -Server "8.8.8.8"
This command will run the cmdlet and perform the DNS lookup for “www.example.com” using Google’s public DNS server (IP address 8.8.8.8) and look up the server address.
Example 4: Resolving CNAME Records
CNAME records map a domain (alias) to another (canonical name) domain. To retrieve CNAME records, use the -Type parameter with “CNAME”:
Resolve-DnsName -Name "www.example.com" -Type CNAME
This will display the canonical name for “www.example.com“, if a CNAME record exists.
Example 5: Finding Authority Zone
You can get the Name Server (NS) records, which indicate the authority zone for a specific domain:
Resolve-DnsName -Name "example.com" -Type NS
This command will list the authoritative DNS servers (name servers) for the domain “example.com“.
Example 6: Getting TXT Records
TXT records hold various types of textual information and can be used, for example, for domain verification or to retrieve SPF records. Here’s how to retrieve them:
Resolve-DnsName -Name "example.com" -Type TXT
This command returns the TXT records for “example.com“.
Replacing “example.com” with your target domain is always good practice. These examples are a mere glimpse into the capabilities of Resolve-DnsName. By exploring the other parameters and types, you can perform comprehensive DNS investigations and troubleshoot with this cmdlet.
Example 7: Resolving PTR Records
Pointer (PTR) records, also known as Reverse DNS records, map an IP address to a hostname. This can be useful for reverse lookups, where you have an IP address and want to find the associated hostname.
Resolve-DnsName -Name "8.8.8.8" -Type PTR
This command performs a reverse lookup on Google’s public DNS server IP address.
Example 8: Utilizing the Pipeline
PowerShell is famous for its pipeline input feature, which allows you to pass the output of one command as input to another. Here is an example of using Resolve-DnsName with a pipeline:
"www.example.com", "www.google.com" | Resolve-DnsName
In this command, DNS resolution is performed for both “www.example.com” and “www.google.com“. The pipe operator (|) passes each domain name to the Resolve-DnsName cmdlet.
Example 9: Obtaining Fully Qualified Domain Names (FQDNs)
The -DnsOnly switch is used to get only the DNS protocol result of a query without the potential influences of NetBIOS or local hosts files. For instance:
Resolve-DnsName -Name "example" -DnsOnly
The result will be the Fully Qualified Domain Name (FQDN) of the “example” that is obtained purely from the DNS resolution.
Awesome DNS Server for home
Speaking of DNS, check out my video on how to easily install and configure Unbound DNS for your home lab:
Wrapping Up
While looking at Resolve-DnsName more closely, we’ve highlighted how it allows for detailed DNS queries that surpass the capabilities of traditional tools like NSLookup, Dig, and the Host command. With it, admins can quickly investigate DNS queries, extract DNS records, and troubleshoot DNS issues.