Set DnsClientServerAddress - PowerShell


Overview

Set-DnsClientServerAddress configures the DNS client settings on a local or remote computer. It allows you to add, modify, or remove DNS server IP addresses from the client’s configuration, ensuring that the client can resolve domain names and connect to network resources effectively.

Syntax

Set-DnsClientServerAddress -InterfaceAlias <string> -ServerAddresses <string[]> [-Append [-Confirm] [-WhatIf]]

Options/Flags

  • -InterfaceAlias: Specifies the interface alias for which DNS server addresses should be configured.
  • -ServerAddresses: An array of one or more IP addresses of DNS servers to be added or modified.
  • -Append: Adds the specified DNS server addresses to the existing list instead of replacing them.
  • -Confirm: Prompts you for confirmation before executing the command.
  • -WhatIf: Simulates the command execution without actually making any changes.

Examples

Example 1: Add a DNS Server Address

Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddresses 8.8.8.8

Example 2: Replace DNS Server Addresses

Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddresses 1.1.1.1, 1.0.0.1

Example 3: Add a DNS Server Address and Confirm

Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddresses 9.9.9.9 -Append -Confirm

Common Issues

  • DNS Resolution Failure: If you encounter DNS resolution issues after changing server addresses, verify that the specified IP addresses are valid and accessible.
  • IPv6 Compatibility: Not all DNS servers support IPv6. Ensure that the specified DNS servers support IPv6 if your network uses it.
  • Firewall Restrictions: Check for any firewall rules blocking incoming or outgoing DNS traffic on the client or server.

Integration

Set-DnsClientServerAddress can be combined with other commands to automate DNS configuration tasks.

Example: Script to Set DNS Server Addresses on Multiple Computers

$computerNames = Get-Content -Path computerList.txt
foreach ($computer in $computerNames) {
    Set-DnsClientServerAddress -ComputerName $computer -InterfaceAlias Ethernet0 -ServerAddresses 8.8.8.8 -Append
}
  • Get-DnsClientServerAddress: Retrieves the current DNS client settings.
  • Resolve-DnsName: Resolves a domain name to its IP address.
  • Test-DnsServer: Tests the connectivity and responsiveness of a DNS server.