Mastering DNS Configuration: Remote and Local Techniques

Overview

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

1# List network adapters
2wmic /node:"HOSTNAME" nicconfig get Description, SettingID, IPEnabled
3
4# Set primary DNS (replace SettingID with the actual ID from the previous command)
5wmic /node:"HOSTNAME" nicconfig where SettingID='{4C2E5961-1B25-4AE9-852C-0A285E891244}' call SetDNSServerSearchOrder ("8.8.8.8")
6
7# Set both primary and secondary DNS
8wmic /node:"HOSTNAME" nicconfig where SettingID='{4C2E5961-1B25-4AE9-852C-0A285E891244}' call SetDNSServerSearchOrder ("8.8.8.8", "1.1.1.1")

Using PowerShell

1# Check current DNS settings
2Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName HOSTNAME -Filter "IPEnabled = True" | Select-Object -Property Description, DNSServerSearchOrder
3
4# Set DNS servers
5$adapter = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName HOSTNAME -Filter "IPEnabled = True"
6$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:

1netsh interface ipv4 show interfaces

View Current DNS Settings

1netsh interface ipv4 show dns "Wi-Fi"

Set Primary and Secondary DNS

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

Remove a Specific DNS Server

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

Reset to DHCP (Automatic DNS)

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

Display All DNS Settings

1ipconfig /all | findstr "DNS"

View and Modify Hosts File

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

Reset Network Stack

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

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