# 为什么我的域名ping不通?
本文主要是复现 https://articles.zsxq.com/id_xjarfxn53dz9.html 的case并进行排查。
首先按照实验准备复制博主的hosts两行配置,成功复现问题,第一个域名ping不通,第二个可以:
127.0.0.1 test.unknow.host
127.0.0.1 test.localhost

其实这个问题在上面复现过程中问题原因我大概已经猜到了,在上面通过vim编辑hosts文件追加上面两行配置就可见一些蹊跷:

博主设计了一些特殊的不可见字符(看起来像是空格)在里面,对于这种情况,可以用xxd直接查看文本内容的字节表示

然后再分别看一下0xE3和0x80都是些什么字符?

当然上面是条件反射式,更通用和普适的方法可以用strace(1) (opens new window)
strace -e trace=%file,read -s 1024 ping test.unknow.host
这时候你去对一下ping命令实际去读hosts文件的read syscall就可见端倪

strace -e trace=%network -s 1024 ping test.unknow.host
既然本地hosts配置没有生效,ping就会向本地dns发起请求,如下127.0.0.11就是笔者测试环境的dns(docker容器环境)

另外一边用tcpdump抓包

这里有个关键字NXDomain,这时候就可以Google了
The DNS protocol RFC1035 (opens new window) defines response code 3 as "Name Error",
or "NXDOMAIN" RFC2308 (opens new window), which means that the queried domain name
does not exist in the DNS.
- So
NXDomainstands fornot exist domain?
# 参考
- https://datatracker.ietf.org/doc/html/rfc8020#section-1
- https://bytetool.web.app/en/ascii/