今天用nslookup命令解析查看了www.baidu.com的IP地址,却意外发现百度的CNAME居然是www.a.shifen.com

解析过程

1
2
3
4
5
6
7
8
9
10
11
nslookup www.baidu.com
>>>
Server: 119.29.29.29
Address: 119.29.29.29#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 220.181.111.188
Name: www.a.shifen.com
Address: 220.181.112.244

接下来看看一个详细的baidu的dns解析过程

理论上,目前我的电脑通过ISP接入互联网,ISP就会分配一个本地DNS服务器(非权威服务器),然后我的电脑向这个ISP DNS服务器发起请求,查询www.baidu.com的IP地址。

首先DNS会检查自己的缓存里面有没有这个地址,如果有的话直接返回,没有的话,ISP会把请求发送给根DNS服务器(13台),然后根DNS服务器发现是.com结尾,是.com这个顶级域名下的,就告诉请求者负责解析.com的DNS服务器,ISP DNS再次向baidu.com这个域的权威服务器发起请求,服务器收到之后,查一下www这台主机,然后把IP返回给IPS DNS,然后把地址返回给PC,并且存入缓存中,以便再次访问。

使用dig命令:

1
2
+trace 表示将显示从根域逐级查询的过程,追踪dns解析中的问题
+tcp dig默认使用udp协议,使用tcp方式

dig www.baidu.com的结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
kevin:~ $ dig www.baidu.com
# 版本信息和全局设置选项
; <<>> DiG 9.8.3-P1 <<>> www.baidu.com
;; global options: +cmd
# DNS返回的技术信息
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20158
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
# 问题,查询的名字和类型字段,A记录
;; QUESTION SECTION:
;www.baidu.com. IN A
# 回答,对查询的响应中的RR
;; ANSWER SECTION:
www.baidu.com. 1014 IN CNAME www.a.shifen.com.
www.a.shifen.com. 114 IN A 220.181.111.188
www.a.shifen.com. 114 IN A 220.181.112.244
# 查询的统计数据
;; Query time: 60 msec
;; SERVER: 119.29.29.29#53(119.29.29.29)
;; WHEN: Sun Feb 19 15:07:00 2017
;; MSG SIZE rcvd: 90

然后使用trace功能,从头显示dns解析过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
kevin@duguangtingdeMacBook-Pro:~ $ dig +trace www.baidu.com
# 查询根DNS服务器
; <<>> DiG 9.8.3-P1 <<>> +trace www.baidu.com
;; global options: +cmd
. 335103 IN NS m.root-servers.net.
. 335103 IN NS a.root-servers.net.
. 335103 IN NS j.root-servers.net.
. 335103 IN NS e.root-servers.net.
. 335103 IN NS c.root-servers.net.
. 335103 IN NS i.root-servers.net.
. 335103 IN NS b.root-servers.net.
. 335103 IN NS g.root-servers.net.
. 335103 IN NS h.root-servers.net.
. 335103 IN NS k.root-servers.net.
. 335103 IN NS l.root-servers.net.
. 335103 IN NS d.root-servers.net.
. 335103 IN NS f.root-servers.net.
;; Received 228 bytes from 119.29.29.29#53(119.29.29.29) in 3126 ms
# 查询到的com顶级域dns服务器
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
;; Received 503 bytes from 198.41.0.4#53(198.41.0.4) in 5139 ms
# 查询到的baidu.com权威dns服务器
baidu.com. 172800 IN NS dns.baidu.com.
baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.
;; Received 201 bytes from 192.52.178.30#53(192.52.178.30) in 1697 ms
# 查询到的别名
www.baidu.com. 1200 IN CNAME www.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
;; Received 228 bytes from 61.135.165.235#53(61.135.165.235) in 123 ms

首先获取13个根服务器的13个IP和主机名,然后向其中一个198.41.0.4发送www.baidu.com请求,返回.com顶级域的服务器IP,接着向.com域的一台服务器192.52.178.30请求,返回baidu.com域名服务器IP和名称,向百度的顶级域名服务器dns.baidu.com请求www.baidu.com,他发现这个www有别名叫www.a.shifen.com

一般来讲,dns请求到别名的时候,查询就会终止,然后重新发起查询别名的请求,所以应该返回www.a.shifen.com,但是其实它返回了a.shifen.com的NS

再使用dig工具来查询一下shifen.com:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
kevin@duguangtingdeMacBook-Pro:~ $ dig +trace shifen.com
# 查询的根DNS服务器
; <<>> DiG 9.8.3-P1 <<>> +trace shifen.com
;; global options: +cmd
. 188674 IN NS a.root-servers.net.
. 188674 IN NS b.root-servers.net.
. 188674 IN NS h.root-servers.net.
. 188674 IN NS d.root-servers.net.
. 188674 IN NS g.root-servers.net.
. 188674 IN NS l.root-servers.net.
. 188674 IN NS m.root-servers.net.
. 188674 IN NS f.root-servers.net.
. 188674 IN NS j.root-servers.net.
. 188674 IN NS c.root-servers.net.
. 188674 IN NS i.root-servers.net.
. 188674 IN NS e.root-servers.net.
. 188674 IN NS k.root-servers.net.
;; Received 228 bytes from 119.29.29.29#53(119.29.29.29) in 1573 ms
# com顶级域dns服务器
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
;; Received 488 bytes from 192.33.4.12#53(192.33.4.12) in 2454 ms
# shifen.com 权威dns服务器
shifen.com. 172800 IN NS dns.baidu.com.
shifen.com. 172800 IN NS ns2.baidu.com.
shifen.com. 172800 IN NS ns3.baidu.com.
shifen.com. 172800 IN NS ns4.baidu.com.
;; Received 170 bytes from 192.33.14.30#53(192.33.14.30) in 430 ms
# 最终的A记录和NS记录
shifen.com. 7200 IN A 202.108.250.218
shifen.com. 86400 IN NS ns4.baidu.com.
shifen.com. 86400 IN NS ns3.baidu.com.
shifen.com. 86400 IN NS ns2.baidu.com.
shifen.com. 86400 IN NS ns1.baidu.com.
;; Received 186 bytes from 61.135.165.235#53(61.135.165.235) in 24 ms

从这里可以看出来shifen.combaidu.com的域名服务器是同一台,当拿到别名www.a.shifen.com的时候,本来要重新到com域查找shifen.com的NS,又因为两个域在同一台NS上,所以直接本机发起了shifen.com请求,发现www.a.shifen.com是属于a.shifen.com这个域的,所以直接访问shifen.com所返回的IP地址,结果是403 Forbidden,所以应该去到a.shifen.com这个域获取,于是把a.shifen.com这个NS和IP返回,然后在a.shifen.com这个域的域名服务器上查询www.a.shifen.com,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
kevin@duguangtingdeMacBook-Pro:~/Desktop/work/capacity $ dig www.a.shifen.com +trace
# 根dns服务器
; <<>> DiG 9.8.3-P1 <<>> www.a.shifen.com +trace
;; global options: +cmd
. 174188 IN NS a.root-servers.net.
. 174188 IN NS b.root-servers.net.
. 174188 IN NS h.root-servers.net.
. 174188 IN NS d.root-servers.net.
. 174188 IN NS g.root-servers.net.
. 174188 IN NS l.root-servers.net.
. 174188 IN NS m.root-servers.net.
. 174188 IN NS f.root-servers.net.
. 174188 IN NS j.root-servers.net.
. 174188 IN NS c.root-servers.net.
. 174188 IN NS i.root-servers.net.
. 174188 IN NS e.root-servers.net.
. 174188 IN NS k.root-servers.net.
;; Received 228 bytes from 119.29.29.29#53(119.29.29.29) in 39 ms
# com域
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
;; Received 494 bytes from 192.203.230.10#53(192.203.230.10) in 523 ms
# 先查的是shifen.com
shifen.com. 172800 IN NS dns.baidu.com.
shifen.com. 172800 IN NS ns2.baidu.com.
shifen.com. 172800 IN NS ns3.baidu.com.
shifen.com. 172800 IN NS ns4.baidu.com.
;; Received 176 bytes from 192.33.14.30#53(192.33.14.30) in 27 ms
# 发现是属于 a.shifen.com这个域的
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
;; Received 204 bytes from 61.135.165.235#53(61.135.165.235) in 82 ms
# 在a.shifen.com这个域上查找
www.a.shifen.com. 300 IN A 61.135.169.125
www.a.shifen.com. 300 IN A 61.135.169.121
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
;; Received 236 bytes from 61.135.162.215#53(61.135.162.215) in 38 ms

直接访问之,正是百度的页面。

彩蛋-shifen.com由来

http://shifen.com是百度当年为了竞价排名这个广告系统注册的,这个后台系统被命名为Shifen竞价排名,以前的销售系统现在还叫shifen销售系统。因为当年百度那个广告最低点击10分起价。为什么有这么一个奇怪的名字呢?在《相信中国》中,梁冬先生这样写道:“这个将来成就了百度80%收入的商业模式,最初的管理平台是由一个叫刘子正的实习生主持开发的。这也是唯一一个除http://baidu.com以外,外人所知的百度公司所拥有的国际域名。

另外:大公司都跟“十分”有关系啊,比如腾讯——TenCent⋯⋯