Linux 核对
Linux 核对
grep -v '^#' /etc/hosts
grep '^hosts' /etc/nsswitch.conf # 例:hosts: files dns
getent hosts example.com # 经 NSS 全链路(与 ping 行为一致)
strace -e trace=openat,connect getent hosts example.com 2>&1 | head -20 # 看实际走 hosts 还是 DNSWindows 核对
Windows 核对
Get-Content C:\Windows\System32\drivers\etc\hosts | Where-Object {$_ -notmatch '^\s*#' -and $_.Trim()}
Resolve-DnsName example.com -DnsOnly # 绕过 hosts 验证getent hosts 与 dig 都查一遍:两者不一致=走了 hosts 或 NSS 其它源;这对『同一域名两台机器结果不同』类问题特别有效。