10 PowerShell Commands for Managing Your DNS Server

Share

In this article, we’ll reveal 10 PowerShell commands that you can use to manage your DNS server to keep everything under control as efficiently as possible.

In a previous article, we looked at how to deploy a DNS server using PowerShell commands, leaving you with a completely functional DNS server with very little effort.

Furthermore, we saw that by using scripts, you can replicate the process really easily for future deployments.

In this article, however, we’re going to see how you can use PowerShell commands to perform maintenance tasks. So, here are ten commands that you can use to manage your DNS server in the easiest way possible.

 

10 PowerShell Commands for Managing Your DNS Server

Below, we’ve listed ten cmdlets that you can use to manage your DNS server quickly and easily. In reality, all the tasks listed here can be performed using the graphic interface, which might seem easier, but PowerShell is much quicker.

 

1. Stop the DNS Service

One of the most basic tasks that you need to know how to do is how to stop the service. This command can actually be used to stop all kinds of services but to stop the DNS service specifically, it will look something like this:

Stop-Service DNS

This command will only work on servers, not on client devices. On client devices, you can stop the cache but not the service entirely.

Command 1 - Stop the DNS service on the server using PowerShell
Command 1 – Stop the DNS service on the server using PowerShell

 

2. Start the DNS Service

Just as important as being able to stop the service is being able to start it again. And once again, this command can be used to start all kinds of services. But to start the DNS service, it will look like this:

Start-Service DNS

Normally, you won’t see any confirmation message after running this command. Instead, if you want to check that the command has been run correctly, you can either launch the command “Get-Service DNS” or open the graphic interface.

Command 2 - Start the DNS service on the server using PowerShell
Command 2 – Start the DNS service on the server using PowerShell

 

3. Restart the DNS Service

You already know how to start and stop the service, but sometimes you might want to stop it and start again straight away.

Luckily, you can do this with a single reset command, which looks like this:

Restart-Service DNS

This command will order the server to re-read the configuration files, and that way, you can apply changes or resolve an error.

With these three commands, you’ve now got the basics taken care of.

 

Command 3 - Reset the DNS server using PowerShell
Command 3 – Reset the DNS server using PowerShell

 

4. Check DNS Resolution

Another common task is to check the name resolution to see whether the system can resolve a specific name.

The cmdlet “Resolve-DnsName” queries the DNS for the specified name.

This cmdlet performs a similar task to nslookup, which allows users to query names.

There are two ways of using this command, as you can choose to specify the server to use if you wish.

If you don’t want to specify a server to use, the command will look something like this (using the Jotelulu website as an example):

Resolve-DnsName -Name www.jotelulu.com

However, if you want to use a specific server to resolve the query, the command will look like this:

Resolve-DnsName -Name www.jotelulu.com -Server 10.0.0.1

Command 4 - Check name resolution
Command 4 – Check name resolution

 

5. Show the DNS Cache

Now and again, you might be interested to see what the resolver cache looks like, whether from a server or a client device. To do this, you can either use the classic command prompt or use our good old friend PowerShell.

To show the contents of the DNS cache using PowerShell, simply run the following command:

Show-DnsServerCache

This command will return pages and pages of entries, so you might want to dump the results into a text document so you can examine it in more detail.

Command 5 - Show the contents of the DNS cache
Command 5 – Show the contents of the DNS cache

 

6. Clear the DNS Cache

You can also clear the DNS cache for your server or client device. To do this, simply run the following command:

Clear-DnsServerCache

This command can be run in between two queries so that you can see that the entries have been deleted.

Command 6 - Clear the DNS cache
Command 6 – Clear the DNS cache

 

7. Review the DNS Server Statistics

Another interesting thing you can do with PowerShell is consult the DNS Server statistics, which will show you things like entries, queries, etc.

You can perform this task using the graphic interface too, but PowerShell is still quicker. Here’s the cmdlet:

Get-DnsServerStatistics

Again, there will be a lot of data here, so you’ll probably want to move it all into a text file for easier reading.

Command 7 - Review the DNS Server statistics
Command 7 – Review the DNS Server statistics

 

8. Review the DNS Service Settings

If you need to take a look at the settings for your DNS server, there’s a PowerShell command for that too!

To see the configuration details for your DNS Server, simply run the following cmdlet:

Get-DnsServer

A useful thing to do with the output of this command is to save it in a text file for future consultation. That way, you’ll have a record of previous settings if you make any changes later on.

Command 8 - Review your DNS Server settings
Command 8 – Review your DNS Server settings

 

9. Add New Service and Device Records

Another command task when managing a DNS server is registering all the services, devices and servers that your infrastructure uses.

To do this, you need to use the different kinds of records stored on the DNS server.

 

Add-DnsServerResourceRecordCName -ZoneName <ZONE_NAME> -Name  <ENTRY>  -HostNameAlias <FULL_ALIAS>

Where:

  • Add-DnsServerResourceRecordCName is the command to add a CNAME record.
  • ZoneName <ZONE_NAME> specifies the zone.
  • Name <ENTRY> specifies the name of the record.
  • HostNameAlias <FULL_ALIAS> specifies an alias for the new input

Here’s an example:

Add-DnsServerResourceRecordCName -ZoneName jotelulu.com -Name nacho-test -HostNameAlias nacho-test-jotelulu.com

This example adds a CNAME record. For other types of records, this command will vary.

Here are a few more examples.

For a PTR Record:

Add-DNSServerResourceRecordPTR -ZoneName 1.168.192.in-jotelulu.com -Name 12 -PTRDomainName nacho1-jotelulu.com

For an A Record:

Add-DnsServerResourceRecordA -Name pointer -IPv4Address 192.168.1.122 -ZoneName server1.jotelulu.com -TimeToLive 01:00:00

For an AAA Record:

Add-DnsServerResourceRecordAAAA -Name “nachopc” -ZoneName “jotelulu.com” -AllowUpdateAny -IPv6Address “fff4::1” -TimeToLive 01:00:00

For an MX Record:

Add-DnsServerResourceRecordMX -Preference 10  -Name “.” -TimeToLive 01:00:00 -MailExchange “mail.jotelulu.com” -ZoneName “jotelulu.com”

For more examples, check out the PowerShell documentation for DNS.

Command 9 - Add new service and device records to the DNS
Command 9 – Add new service and device records to the DNS

 

10. Remove Service and Device Records

Just as you can add records using PowerShell, you can also remove records from your DNS really easily using the command “Remove-DnsServerResourceRecord”. In fact, it’s almost exactly the same as the command to add a service. You just need to change the verb at the beginning.

Remove-DnsServerResourceRecord -ZoneName <ZONE_NAME> -RRType <RECORD_TYPE> -Name <ENTRY> –Force

Where:

  • Remove-DnsServerResourceRecord is the command to remove the record.
  • ZoneName <ZONE_NAME> specifies the zone.
  • RRType <RECORD_TYPE> specifies the type of record, such as A, AAA, MX, CNAME, etc.
  • Name <ENTRY> is the name of the record that needs to be removed.
  • Force: Forces the deletion.

As with the previous command, you need to distinguish between the different types of records (A, AAA, MX, etc.).

Here’s an example:

Remove-DnsServerResourceRecord -ZoneName jotelulu.com -RRType A -Name pc-jioller –Force

Command 10 - Remove records from the DNS
Command 10 – Remove records from the DNS

 

Summary

By knowing just a few PowerShell commands, you can make managing your DNS server much simpler and more efficient.

Pretty much any basic administration task can be performed using these cmdlets. If you’d like to read more about this topic, take a look at our other article on this blog on deploying a DNS server using PowerShell commands.

And if you’d like to read more about DNS in general, check out this article on what to do when your DNS server doesn’t respond.

Thanks for choosing Jotelulu!

Category:Cloud and Systems

Other posts that may interest you

18 de December de 2023
Our Remote Desktop service just keeps getting better! We’ve recently developed some new features to improve service security and
15 de December de 2023
On 22 November, the Jotelulu Roadshow 2023  finally came to a close after seven fantastic events in seven different
12 de September de 2023
Today, we’re going to tell you all about RAID. We’ll explain exactly what it is, take a look at the

Fill out the form and one of our Sales team will contact you soon.

growth@jotelulu.com  |  jotelulu.com 

You can unsubscribe from these communications at any time. For more information,  check our Privacy Policy.