1. 程式人生 > >嘗試利用剛學的計算機網絡知識對域名綁定和解析做出解釋

嘗試利用剛學的計算機網絡知識對域名綁定和解析做出解釋

網站 owin company master ngs 2.3 添加 IT main

之前寫過一篇博文,利用github pages五分鐘建好個人網站+個人博客 ,在這篇
博文裏,做了一件什麽事呢?

  1. 利用github pagesJekyll創建了個人網站,這個個人網站的原始域名是: logos23333.github.io
  2. 在aliyun購買了logos23333.top域名
  3. logos23333.toplogos23333.github.io綁定,當用戶在瀏覽器鍵入logos23333.top時,自動解析到logos23333.github.io

我現在是大二下,開了computer networking 這門課程,所以我就想著用所學的知識具體解釋一下這個第3點是怎麽實現的,如果有不對的地方請不吝賜教!

當初我們綁定域名時做了兩件事情:

  1. 在aliyun的域名管理界面,找到了自己購買的域名logos23333.top,對其進行解析,添加了三條記錄。
    技術分享圖片
  2. 在倉庫(服務器)裏創建名為CNAME的文件,並將其內容改為logos23333.top

第一步有什麽作用呢?

Computer Networking A Top-Down Approach 一書中,我們對於一條DNS記錄有以下的認識:

A resource record is a four-tuple that contains the following fields: (Name, Value, Type, TTL)
TTL is the time to live of the resource record; it determines when a resource should be removed from a cache.

TTL決定了一條記錄在緩存中存在的時間,也就是說,TTL時間越長,緩存時間越長,更新越不容易及時生效,增加TTL值,可以加速網站訪問速度,節約域名解析時間,相反,TTL時間越短,緩存時間越短,生效時間也就更快。
在下面的討論中,我們忽略TTL,只關註Name ValueType

If Type=A, then Name is a hostname and Value is the IP address for the hostname. Thus, a Type A record provides the standard hostname-to-IP address mapping. As an example, (relay1.bar.foo.com, 145.37.93.126, A)
is a Type A record.
If Type=NS, then Name is a domain (such as foo.com) and Value is the hostname of an authoritative DNS server that knows how to obtain the IP addresses
for hosts in the domain. This record is used to route DNS queries further along in the query chain. As an example, (foo.com, dns.foo.com, NS) is a Type
NS record.
If Type=CNAME, then Value is a canonical hostname for the alias hostname Name. This record can provide querying hosts the canonical name for a hostname. As an example, (foo.com, relay1.bar.foo.com, CNAME) is a
CNAME record.
If Type=MX, then Value is the canonical name of a mail server that has an alias hostname Name. As an example, (foo.com, mail.bar.foo.com, MX) is an MX record. MX records allow the hostnames of mail servers to have simple aliases. Note that by using the MX record, a company can have the same
aliased name for its mail server and for one of its other servers (such as its Web server). To obtain the canonical name for the mail server, a DNS client would query for an MX record; to obtain the canonical name for the other server, the
DNS client would query for the CNAME record.

再來分析我們添加的三條記錄:

  1. CNAME @ logos23333.github.io,這條DNS記錄的type是CNAME,也就是添加一個別名@的意思是直接解析,也就是說當我們解析logos23333.top時,會自動去解析logos23333.github.io的ip地址。
  2. A www 192.30.252.153,這條DNS記錄的type是A,這裏的192.30.252.153是github服務器的名字。第3條記錄也是一樣的意思。

我現在有以下幾個點不明白:

  1. 添加那兩條A類型的記錄有什麽意義?如果我只是想實現解析logos23333.top時去解析logos23333.github.io這樣的功能,只提供一個CNAME記錄不就可以了?
  2. 我在github倉庫添加一個CNAME文件,裏面寫著logos23333.top的意義在哪?似乎只添加那一條CNAME記錄就能實現了。

2018/3/12 23:51 在github pages的幫助界面,似乎官方並不是通過創建CNAME文件這種方式,而是直接在倉庫的settings裏改,好像是一樣的效果。

嘗試利用剛學的計算機網絡知識對域名綁定和解析做出解釋