changed 6 years ago
Linked with GitHub

[筆記] 網路基礎概論-DNS Server

tags: mentor-program

DNS server

今天我們在網址上輸入 github.com,照理說就要能連到管理 github.com 的這台主機,但是電腦看不懂 github.com ,它只認得 IP 位址。

就像跟計程車司機說:「我要去 中正紀念堂 」,假設司機不知道中正紀念堂在哪不知道怎麼去,這時它就要用 Google Map 找中正紀念堂的地址,透過 Google Map 得知地址在 台北市中正區中山南路21號 ,這樣司機就知道在哪了。如果事先知道地址也能直接跟司機說:「我要去台北市中正區中山南路21號」,這樣就不用透過 Google Map 到目的地了。

所以可以想成:

中正紀念堂 -> Domain Name
台北市中正區中山南路21號 -> Ip
Google Map -> DNS Server

所以簡單的來說,DNS Server 就是一個負責把 domain name 轉成 ip 位置的地方。

我們也能自己查詢 Ip

可以在 commane line 上輸入

nslookup google.com

得到的結果:

Server:		192.168.1.1
Address:	192.168.1.1#53

Non-authoritative answer:
Name:	google.com
Address: 172.217.160.78 <-- ip

/etc/hosts

每個人的電腦裡都會有一個這樣的檔案,它會紀錄什麼 Ip 對應到什麼 domain,當我們在網址列上輸入 domain name 時,其實會優先在這個檔案裡搜尋,沒有的會才到 DNS server 查詢

這份檔案裡大概長這樣:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost.com
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1 是個特殊的 Ip,就是指本機(自己電腦的主機)的意思

補充:如何用 hosts 破解正版

假設是 adobe 軟體有個檢查是否是盜版的 request,假設 domain name 為 adobe.com ,而我們在 hosts 裡將 adobe.com 設為一個不存在的 ip 位址,這樣 request 就會被導到那個不存在的地方然後就沒有回應了(沒試過好想試)

Select a repo