To change Ethernet DNS settings using PowerShell, you use the Set-DnsClientServerAddress cmdlet. You will need to specify the network adapter either by its InterfaceAlias (e.g., "Ethernet") or its InterfaceIndex (a number).
Prerequisites
You must run PowerShell as an administrator. Right-click the Windows Start button and select Windows PowerShell (Admin) or Windows Terminal (Admin).
1. Identify your network adapter
First, determine the InterfaceAlias or InterfaceIndex of your Ethernet adapter using the Get-NetAdapter or Get-NetIPConfiguration cmdlets:
powershell Get-NetAdapter | Select-Object Name, InterfaceIndex, Status
Note the name (e.g., "Ethernet") or index number (e.g., 12) of the adapter that is "Up".
2. Set the DNS server addresses
Choose one of the following commands, replacing the InterfaceAlias or InterfaceIndex and the example IP addresses with your desired values.
2.1 By Interface Alias:
powershell Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8", "8.8.4.4")
2.1 By Interface Index:
powershell Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses ("8.8.8.8", "8.8.4.4")
You can specify multiple DNS servers as a comma-separated array of strings
3. Verify the changes
After running the command, you can verify the new settings using Get-DnsClientServerAddress:
powershell Get-DnsClientServerAddress -InterfaceAlias "Ethernet"
4. Reset to automatic (DHCP)
If you need to revert the settings to obtain DNS addresses automatically via DHCP, use the -ResetServerAddresses parameter:
powershell Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses