Remote and Local DNS Configuration Guide

Published: March 21, 2024 | Last Modified: May 13, 2025

Tags: windows dns networking powershell command-line system-administration

Categories: Shell Networking



This guide provides comprehensive steps for managing DNS configurations, both remotely and locally. It’s particularly useful for resolving network issues caused by incorrect DNS settings.

Remote DNS Configuration

When you need to change DNS settings on a remote machine, you can use the following commands. In these examples, we’ll use a computer with the hostname “HOSTNAME” and set Google’s DNS (8.8.8.8) as the primary and Cloudflare’s DNS (1.1.1.1) as the secondary.

Using WMIC from Command Prompt

# List network adapters
wmic /node:"HOSTNAME" nicconfig get Description, SettingID, IPEnabled

# Set primary DNS (replace SettingID with the actual ID from the previous command)
wmic /node:"HOSTNAME" nicconfig where SettingID='{4C2E5961-1B25-4AE9-852C-0A285E891244}' call SetDNSServerSearchOrder ("8.8.8.8")

# Set both primary and secondary DNS
wmic /node:"HOSTNAME" nicconfig where SettingID='{4C2E5961-1B25-4AE9-852C-0A285E891244}' call SetDNSServerSearchOrder ("8.8.8.8", "1.1.1.1")

Using PowerShell

# Check current DNS settings
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName HOSTNAME -Filter "IPEnabled = True" | Select-Object -Property Description, DNSServerSearchOrder

# Set DNS servers
$adapter = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName HOSTNAME -Filter "IPEnabled = True"
$adapter.SetDNSServerSearchOrder(@("8.8.8.8", "1.1.1.1"))

Local DNS Configuration

For local DNS management, netsh commands are particularly useful. Here are various scenarios and their corresponding commands:

View All Network Interfaces

Use netsh to list all network interfaces:

netsh interface ipv4 show interfaces

View Current DNS Settings

netsh interface ipv4 show dns "Wi-Fi"

Set Primary and Secondary DNS

netsh interface ipv4 set dns name="Wi-Fi" static 8.8.8.8
netsh interface ipv4 add dns name="Wi-Fi" 1.1.1.1

Remove a Specific DNS Server

netsh interface ipv4 delete dns name="Wi-Fi" addr=1.1.1.1

Reset to DHCP (Automatic DNS)

netsh interface ipv4 set dns name="Wi-Fi" source=dhcp

Display All DNS Settings

ipconfig /all | findstr "DNS"

View and Modify Hosts File

notepad C:\Windows\System32\drivers\etc\hosts

Reset Network Stack

If you’re experiencing persistent network issues, you can try resetting the entire network stack:

netsh winsock reset && netsh int ip reset && ipconfig /release && ipconfig /renew && ipconfig /flushdns