PowerShell: Get DNS Server Address
Need to check which DNS server a machine is using - for network troubleshooting, confirming DHCP configuration, or verifying a custom DNS setup? This one-liner pulls it straight from the system.
Prerequisites:
- Privileges: None
- Module: Built-in, no import needed
Quick Command:
Get-DnsClientServerAddress -AddressFamily IPv4 | Where-Object { $_.InterfaceAlias -notlike "*Loopback*" } | Select-Object InterfaceAlias, ServerAddresses
Example Output:
InterfaceAlias ServerAddresses
-------------- ---------------
Ethernet {10.211.55.1}
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.
How It Works:
- Get-DnsClientServerAddress returns the configured DNS servers for every network adapter, across both IPv4 and IPv6 - by default this includes the loopback interface and empty entries, which aren't useful for a quick check.
- -AddressFamily IPv4 filters down to only IPv4 DNS entries.
- Where-Object { $_.InterfaceAlias -notlike "*Loopback*" } excludes the loopback interface, keeping only the real network adapter.
- Select-Object InterfaceAlias, ServerAddresses trims the output down to just the adapter name and its configured DNS server(s).