Powershell - View and manage DNS configuration of network interfaces

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!

Hello,

Still on the subject of networking, here’s a set of commands for displaying and modifying the DNS configuration of network interfaces

# Display DNS cache (ipconfig /displaydns)
Get-DnsClientCache
# Display DNS cache items with a specific lifetime
Get-DnsClientCache -TimeToLive 86400
# Display specific DNS cache resource records (A, PTR, CNAME...)
Get-DnsClientCache -Type A
# Display failed DNS cache items
Get-DnsClientCache -Status NoRecords
# Display DNS cache items filtered by record name
Get-DnsClientCache -Entry www.altf4-formation.fr
# Display DNS cache items filtered by record value
Get-DnsClientCache -Data 192.168.0.254
# Clear dns cache (ipconfig /flushdns)
Clear-DnsClientCache
# Display DNS suffixes, DNS suffix lookup list and whether interface registers with DNS server
Get-DnsClient
# Display DNS suffixes for a specific network interface, the DNS suffix lookup list and whether the interface registers with the DNS server
Get-DnsClient -InterfaceAlias Ethernet
# Displays interfaces configured to register with the DNS server
Get-DnsClient -RegisterThisConnectionsAddress $true
# Displays interfaces configured to register with the DNS server using a DNS suffix
Get-DnsClient -UseSuffixWhenRegistering $true
# Displays interfaces configured with a specific DNS suffix
Get-DnsClient -ConnectionSpecificSuffix home
# Disable DNS registration for network interface
Set-DnsClient -InterfaceAlias ethernet -RegisterThisConnectionsAddress $false
# Set DNS suffix for interface
Set-DnsClient -InterfaceAlias ethernet -ConnectionSpecificSuffix
# Remove DNS suffix for network interface
Set-DnsClient -InterfaceAlias ethernet -ResetConnectionSpecificSuffix
# Enable use of DNS suffix for registration
Set-DnsClient -InterfaceAlias ethernet -UseSuffixWhenRegistering $true
# Register ip with DNS server (ipconfig /registerdns)
Register-DnsClient
# Display list of DNS servers configured on network interfaces
Get-DnsClientServerAddress
# Display list of DNS servers configured on a specific network interface
Get-DnsClientServerAddress -InterfaceAlias Ethernet
# Display DNS-over-HTTPS (DoH) configuration
Get-DnsClientDohServerAddress
# Display global DNS client configuration
Get-DnsClientGlobalSetting
# Display DNS client NRPT configuration
Get-DnsClientNrptGlobal
# Reset DNS server settings
Get-DnsClient | Set-DnsClientServerAddress -ResetServerAddresses
# Set DNS on a network interface
Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 192.168.0.254,192.168.0.253
# Set DNS on a network interface, checking that the IP addresses set are DNS servers
Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 192.168.0.254,192.168.0.253 -Validate

Warning: Test-DnsServer must be run from at least Windows Server 2008 R2 (no Windows client).

# Checks whether the indicated server is a DNS server
Test-DnsServer -IPAddress 10.0.0.3
# Test whether the DNS server is functional and configured as a redirector
Test-DnsServer -IPAddress 192.168.0.254 -Context Forwarder
# Test if DNS server is functional and configured with root servers
Test-DnsServer -IPAddress 1.1.1.1 -Context RootHints
# Test if DNS server is functional and hosts a specific zone
Test-DnsServer -IPAddress 185.199.110.153 -ZoneName “altf4-formation.fr

Related links