比如说在自己电脑 host 如下:
202.xxx.xxx.xxx examplehost
在 dns server 设置 A 记录如下:
examplehost IN A 202.xxx.xxx.xxx
如果只设置后者,则在本机 ping 不通,但是 dig 可以出来正确结果,请问二者有什么不一样?
换个问法好了:
dns server在局域网内的PC1架设,自己的电脑PC2把dns设置改为PC1的IP
如果A记录是这样的
examplehost.com IN A 123.123.123.123
则PC2直接ping examplehost.com 会显示IP地址123.123.123.123
-----------------------------------------------------------------------------------------------------------
如果A记录改成这样
examplehostA IN A 123.123.123.123
则PC2直接ping examplehost 不会显示IP地址,会提示Ping request could not find host testabc. Please check the name and try again.
-----------------------------------------------------------------------------------------------------------
但是在PC2的hosts文件添加
123.123.123.123 examplehost
PC2直接ping examplehost 会显示IP地址123.123.123.123
|  |      1b821025551b      2017-12-19 11:23:20 +08:00 ping 是会先查找本地 host 的,但是走的 ICMP 协议,所以有时候目标服务器防火墙禁掉就 ping 不通了。 | 
|      27DLNU56W      2017-12-19 11:28:08 +08:00 hosts 属于缓存,系统会优先通过 hosts 解析的,这里面查不到才会提交给递归服务器。 | 
|      3nullcoder      2017-12-19 11:30:54 +08:00 不光是 ping,本地有 host 先按 host 连 ping 不通可能是 ICMP 被服务器禁掉的原因,你设 Host 之后能 ping 通了? dig 是什么?会不会有 DNS 生效时间的问题? | 
|  |      4Mutoo      2017-12-19 11:50:02 +08:00 hosts 是在互联网初期还没有 DNS 的时候使用的域名 /IP 映射文件,后来随着互联网壮大,以文件方式管理太麻烦了,所以产生了 DNS 服务。但是 hosts 依然被保留使用,且优先级比 DNS 高。 | 
|  |      5Devin OP @b821025551b ping 主机名的时候一般会显示 IP 地址,但是这里提示 Ping request could not find host testabc. Please check the name and try again. @nullcoder 是的这添加 hosts 后可以 ping 通,dig 是命令 我把主机名改成这样形式的 examplehost.com ,ping 的时候会显示 IP 地址,原本这种形式的 examplehost 不行,奇怪 | 
|  |      7Devin OP 貌似写成 examplehost 形式的话,不会通过 dns server 解析 局域网内同网段的主机名不会通过 dns server 解析,类似 localhost 也不会通过 dns server 解析 | 
|      80TSH60F7J2rVkg8t      2017-12-19 12:30:02 +08:00 假如你每天要拿起办公桌上的电话,打 10020 问一下当天的天气。 那么 hosts 就是 ,你办公桌旁边有张纸条,写了“今天晴天”。 dig 就是你拿起话筒,转拨号盘,打 10020 看看通了没。 | 
|      9957204459      2017-12-19 12:38:30 +08:00 via iPhone 差不多吧 | 
|      10kknd22      2017-12-19 12:43:03 +08:00 DNS 解析过程,可以搜一下,网上有,大概步骤 1 )先检查是不是本机 2 )检查浏览器缓存 3 )检查 DNS 缓存 4 )检查 hosts 5 )向主 DNS 服务器发起请求 6 )主 DNS 无响应则向副 DNS 服务器,如主 DNS 有响应则跳过该步骤 7 )两 DNS 服务器都不响应则检查 NETBIOS 缓存 8 ) WINS 服务器解析 9 )局域网广播 10 ) LMHOSTS 文件 | 
|      11kknd22      2017-12-19 12:44:03 +08:00 PS:开机后,如果 DNS 缓存服务开着,则自动把所有 hosts 文件内容加载到 DNS 缓存,这 94 为毛我都把 DNS 缓存关掉的缘故 | 
|  |      12WillTimeCondense      2017-12-19 13:35:29 +08:00 via Android ipconfig /flushdns | 
|  |      13Devin OP @WillTimeCondense 试过,无效 | 
|      14julyclyde      2017-12-19 13:55:22 +08:00 /etc/hosts 里边 x.x.x.x Ahost Bhost 然后 ping x.x.x.x 的时候会显示 Pinging Ahost | 
|  |      15goofool      2017-12-19 14:30:30 +08:00  1 windows 上你需要 ping examplehost. linux 上不需要 |