2. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen2
應用層 -- 簡介
本章主要介紹在應用層所常用的協定
HTTP (section 2.2)
FTP (section 2.3)
E-mail (section 2.4)
DNS (section 2.5)
並介紹用戶端( client )和伺服器端
( server )的關係
Service model
Socket programming (section 2.6)
3. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen3
用戶端( client )和伺服器端
( server )
用戶端和伺服器端是一種互相依持的關係
(一個用戶端,一個伺服器端)或
(一個用戶端,數個伺服器端)或
(數個用戶端,一個伺服器端)或
(數個用戶端,數個伺服器端)
在執行一般的網路應用程式情況下,一台機器
是用戶端亦是伺服器端
4. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen4
用戶端( client )和伺服器端( server
(cont.)
用戶端
通常為送出要求 (request) 的一方或
最初建立連線 (connection) 要求的一方
向伺服器端要求提供服務 (service) 的一方
例如:使用者端的瀏覽器 (browser)
伺服器端
通常為送出回應 (reply) 的一方
提供服務的一方
例如:網頁伺服器 (web server)
5. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen5
Presentation
Layer
Layer
1
2
3
4
Media
Code
MAC
LLC
IP
TCP/UDP
5
6
7
socket
Session
Presentation
Application
OSI 7 Layer
Physical Layer
Data_Link
Layer
Network Layer
Transort Layer
Session Layer
Application
Layer
6. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen6
用戶端( client )和伺服器端( server
(cont.)
Application
Transport
Network
Data link
Physical
Application
Transport
Network
Data link
Physical
Client Server
Request
Reply
7. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen7
應用層 (Application Layer)
應用層是位於 OSI 七層中的最上層
為什麼我們需要應用層 ?呢
因為應用層提供了一個平台,可以讓許多的網路應用程式在
應用層執行
這一些應用程式都是在對等的應用層做溝通
Application
Transport
Network
Data link
Physical
Application
Transport
Network
Data link
Physical
Application
Transport
Network
Data link
Physical
Host A Host B Host C
8. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen8
應用程式 (applications)
這裡泛指網路應用程式 (Network Application)
應用程式分別於使用者的機器上執行
兩個或兩個 (multicast application) 以上應用程
式透過網路溝通
由於上述的交換動作,所以應用層得以存在
例如:
電子郵件( E-mail )
案交換(檔 FTP )
網頁瀏覽( Web browsing )
9. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen9
應用層協定 (Application-layer Protocol)
屬於應用程式的一部份
協定 (protocol) 中定義
使用此應用程式所需要的流程
所交換的訊息格式
訊息所表示的意義
與下層協定溝通的方法
…
例如:
我們瀏覽網頁需要 HTTP 協定
10. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen10
應用層協定 (Application-layer Protocol)
(cont.)
Q: 網路應用程式跟應用層的協定有什麼關係?
應用層的協定只是網路應用程式的一部份而已
例如: HTTP 和網頁應用程式的關係
11. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen11
應用層協定 (Application-layer Protocol)
(cont.)
應用程式介面( API, Application Programmer‘s Interface )
API 就像是進出應用程式的一扇門
應用程式透過 API 與下層協定溝通
在這裡網路程式所指的 API 就是常見的 Socket
Socket 在後面有專節介紹
定址 (Addressing)
IP (ch. 4) 或是主機名稱 ( 需搭配 DNS)
指定應用程式 (Socket port)
Socket port 就像是門的鑰匙
12. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen12
應用程式所需要的條件
資料流失 (data loss)
在資料傳輸的過程難免會有資料流失,我們要注意
應用程式所能 接受的範圍,並加以改善夠
網路頻寬 (Network Bandwidth)
我們需要考慮每一個應用程式所需要的頻 需求寬
時間的影響 (Time delay)
我們需要考慮時間對於應用程式的影響
例如:播放影片或是聲音,就不允許資料延遲過久
13. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen13
應用程式所需要的條件 (cont.)
Application Data loss Bandwidth Time Sensitive
File transfer No loss elastic No
E-mail No loss elastic No
Web documents Loss-tolerant elastic No
Real-time audio/video Loss-tolerant Audio: 5kb-1Mb
Video: 10kb-5Mb
Yes, 100’s
msec
Stored audio/video Loss-tolerant Same as above Yes, few secs
Interactive games Loss-tolerant Few Kbps up Yes, 100’s
msec
Financial apps No loss elastic Yes and no
14. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen14
網路傳輸層 (Transport layer) -- overview
傳輸層屬於 OSI 第四層
在應用層的下層傳輸層 (ch. 3) 提供了兩種不
同的服務協定
TCP (Transmission Control Protocol )
UDP (User Datagram Protocol)
在應用層所執行的網路應用程式都是透過這兩
種協定來與網路溝通
15. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen15
網路傳輸層 (Transport layer) – overview
(cont.)
TCP service
連結導向 (connection-oriented)
要透過 TCP 溝通需要先建立連線 (three way handshake)
提供可靠的傳輸 (reliable transport)
提供流量控制 (flow control)
提供壅塞控制 (congestion control)
UDP service
非連結導向 (connectionless)
要透過 UDP 溝通不需要先建立連線
提供盡力的傳送 (best effort transport)
16. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen16
TCP—Three way handshake
w in d o w s iz e
s e n d
b u f f e r
r e c e iv e r
b u f f e r
Connect, Seq i, window size N
Connect, Seq j, window size M
ACK i+1 i+1( 以前全收到)
ACK j+1
T C P 建 c o n n e c tio n 的 方 法
3 w a y h a n d s h a k e
17. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen17
常見的網路應用程式所使用的 service
應用程式 應用層協定 傳輸層協定
電子郵件
Smtp[RFC 821] TCP
遠端裝置存取
telnet[RFC 854] TCP
網頁
http[RFC2068] TCP
案傳輸檔
ftp[RFC959] TCP
多媒體串流 (stream)
Proprietary TCP or UDP
遠端 案伺服器檔
NSF TCP or UDP
網路電話
Proprietary Typically UDP
18. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen18
World Wide Web (WWW) Elements
URL: Uniform resource locator
HTTP: Hypertext Transfer Protocol
HTML: Hypertext Markup Language
Java Language
19. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen19
URL: Uniform Resource Locator
RFC 編號: 1738, 1808.
A URL is compact representation of the
location and access method for a resource
available via the Internet.
一個 resource 是一個可以透過網路存取的任
何物件 , 包括 案目錄、 案、文件聲音和影檔 檔
像…等
URL 的一般表示法
<scheme>:<scheme-specific-part>
20. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen20
RFC 1738 為了下列存取機制所定義之 URL formats
ftp File Transfer Protocolftp File Transfer Protocol
http Hypertext Transfer Protocolhttp Hypertext Transfer Protocol
gopher The Gopher Protocolgopher The Gopher Protocol
mailto Electronic mail addressmailto Electronic mail address
news USNET newsnews USNET news
nntp USNET news using NNTP accessnntp USNET news using NNTP access
telnet Reference to interactive sessionstelnet Reference to interactive sessions
wais Wide-Area Information Serverswais Wide-Area Information Servers
file Host-specific file namesfile Host-specific file names
prospero Prospero Directory Serviceprospero Prospero Directory Service
22. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen22
URI: Universal Resource Identifier (URI)
RFC 編號 1630.
是一種將用在網際網路中的物件的名稱和位址
的表示一致的語法
URL 是 URI 的一種。
Decouple resource 的名稱從它所在的位置或
是從它所存取的方法
23. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen23
HTTP
HTTP: Hyper Text Transfer Protocol
Web 的應用層協定
採用用戶端和伺服器端的服務架構
用戶端:要求、接收並顯示所接收的 web pages
伺服器端:接受要求並回應所要求的 web pages
Application
Transport
Network
Datalink
Physical
Application
Transport
Network
Datalink
Physical
browser web server
http request
http reply
24. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen24
HTTP
Web page 所包含的原件有
Objects
HTML file, jpeg image, java applet…
Base HTML file
HTML 是用來描述 web page 的一種語言
URL :是用來表示一個 page 或是 object
www.nthu.edu.tw/index-c.html (hostname + path name)
目前 HTTP 有兩種標準
http 1.0 (RFC 1945)
http 1.1 (RFC 2068)— 目前所使用
25. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen25
HTML: Hypertext Markup Language
使一種用來描述網頁的文件要如何定義的語言
Embedding markup commands with each
HTML files so that a browser can reformat
the files.
HTML 的標準化 由 WWW 組織所制訂
ex: W3C
26. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen26
HTTP
HTTP 下層協定使用 TCP 傳送服務
由用戶端初始化連線 (setup TCP connection) ,使
用 socket port 80 與伺服器端溝通
伺服器端回應後,兩端開始交換訊息直到結束
(TCP connection close)
HTTP 是一個 stateless 的協定
Stateless 意指伺服器端不需要保有任何有關過去
用戶端的要求訊息 (request message)
通常協定要保有過去的 state ,就會變的很複雜
27. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen27
Non-persistent 和 persistent 連線的不同
Non-persistent
HTTP/1.0
每一個 TCP 連線都會在
server 送完物件後結束
所以每一個連線都只會
有一個 request 和一個
respond
Respond time = 2 RTTs
+ Ttrans
每一個所傳送的物件,
都會受到 slow start 影
響
Persistent
Default for HTTP/1.1
在同一個用戶端會一直
使用同一個 TCP 連線,
直到 time out 才關掉
有較少的 RTT 和 slow
start
有分成 pipeline 和 non-
pipeline
28. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen28
HTTP 的訊息格式 -- request
訊息是使用 ASCII text 所寫(易於閱讀)
Http 的要求訊息格式
GET /somedir/page.html HTTP/1.0
User-agent: Mozilla/4.0
Accept: text/html, image/gif,image/jpeg
Accept-language:fr
(extra carriage return, line feed)
request line
(GET, POST,
HEAD commands)
header
lines
Carriage return,
line feed
indicates end
of message
30. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen30
HTTP 的訊息格式 -- response
status line
(protocol
status code
status phrase)
HTTP/1.0 200 OK
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 …...
Content-Length: 6821
Content-Type: text/html
data data data data data ...data, e.g.,
requested
html file
header
lines
31. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen31
常見的回應訊息
200 OK
要求成功 , 所要求的物件會夾帶在接下來的訊息
301 Moved Permanently
所要求的物件已經一到別處,新的位置將會出現在下一個訊
息中 (Location:)
400 Bad Request
所要求的訊息,伺服器無法判讀
404 Not Found
所要求的物件並不存在伺服器裡
505 HTTP Version Not Supported
所要求使用的協定,伺服器端並不支援
32. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen32
Java Language ( 爪窪語言 )
在 1995 年,由昇揚公司 (Sun Microsystems
Inc.) 所制訂
For waiting interactive web pages.
A small Java program, called an applet, is
associated with a web page and downloaded
to the client machine to interpret the web
page.
36. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen36
Web 快取( proxy 伺服器)
目的:為了可以使用戶端
送出的 request 不用直接
到原來的伺服器,如此一
來便可以加速網頁的取得
及瀏覽
所以大部分的用戶端都會
透過 proxy server 來存取
網路資源,而 proxy
server 會保有一些 web
的快取資料,以利存取
如果現在的網頁資料不是最
新的,則 proxy 會去原始的
網站去更新目前保有的資料
client
Proxy
server
client
http request
http request
http response
http response
http request
http response
http requesthttp response
origin
server
origin
server
37. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen37
為什麼使用 web catching
因為 proxy 一般會離用
戶端較近,會使的存取
的速度較快
可以減少一些較長距離
的 traffic
同一筆資料可以統一由
proxy 來維持更新
右圖為示意圖
1.5 Mbps access link 是
一個 bottleneck
origin
servers
public
Internet
institutional
network
10 Mbps LAN
1.5 Mbps
access link
38. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen38
FTP: File Transfer Protocol
FTP 是現在較普遍也較常用的一個 案傳輸的檔
協定
採用用戶端與伺服器端模式溝通
RFC 編號: 959
所使用的 port:21
file transfer
FTP
server
FTP
user
interface
FTP
client
local file
system
remote file
system
user
at host
39. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen39
FTP: File Transfer Protocol (cont.)
FTP 使用 TCP 作為傳輸層所使用的協定
在 FTP 的連結中有分為兩種
Control :在 client 和 server 之間交換 commands 和 response ,
屬於” out of band control”
Data :在 client 和 server 之間的 data 交換
FTP 和 HTTP 不同,他會 maintain state
目前所在目錄
登錄所做的認證
FTP
client
FTP
server
TCP control connection
port 21
TCP data connection
port 20
40. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen40
FTP: File Transfer Protocol (cont.)
Commands
Open: 連接 FTP server
User: 使用者帳號
Pass: 密碼
RETR filename: 取得 案檔
STOR filename: 上傳 案檔
Bye: 結束連線
回應訊息
331 帳號 OK, 需要密碼
125 data connection
已經開啟 ; 傳送開始
425 無法開啟 data
connection
452 案寫入錯誤檔
如何連結上 FTP server?
>>ftp xxx.xxx.xxx.xxx port
>>get file.xxx ( 取得檔案 )
>>put file.xxx ( 上傳檔案 )
41. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen41
Electronic-mail (E-mail, 電子郵件 )
包含三個部分
使用者代理人
(user agent)
郵件伺服器
(mail server)
SMTP 協定
mail
server
user
agent
user
agent
user
agent
mail
server
user
agent
user
agent
mail
server
user
agent
SMTP
SMTP
SMTP
user mailbox
outgoing
message queue
42. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen42
E-mail– user agent
有時亦稱為郵件讀取者 (mail reader)
它可以讓 user 讀取、回復、轉發、儲存和建
構訊息 (message, mail…)
使用者需要讀取信息時, user agent 會去跟郵
件伺服器溝通,取回信息,或是送出信息
User agent 常見的有:
Microsoft Outlook or Outlook Express
Netscape Messenger
43. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen43
E-mail– Mail server
每一個 user 都會有一個信箱 (mail box) 來存
放尚未讀取的信件
尚未傳送出去的信件會暫時存在 message
queue
SMTP 扮演了兩種角色
Client :當作傳送信件的 server
Server :當作接收信件的 server
Client 和 server 這兩種服務都會執行在每一台
郵件伺服器上
44. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen44
E-mail– SMTP
SMTP: Simple Mail Transfer Protocol
RFC 編號 : 821
使用 TCP 作為下層溝通的協定
Port: 25
傳送三部曲
Handshaking
Transfer of messages
closure
所有信息資訊必須是 7-bit ASCII
45. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen45
SMTP 和 HTTP 的比較
相同處
使用 TCP 為傳輸層協定
Client and server model
使用 persistent connections
不同處
http 是 pull protocol 而 SMTP 是 push protocol
SMTP 的 message 限定在 7 bit ASCII
文件組成方式不同
46. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen46
SMTP 溝通範例
S: 220 cs.nthu.edu.tw
C: HELO oz.nthu.edu.tw
S: 250 Hello oz.nthu.edu.tw, pleased to meet you
C: MAIL FROM: <alice@oz.nthu.edu.tw >
S: 250 alice@oz.nthu.edu.tw... Sender ok
C: RCPT TO: <bob@cs.nthu.edu.tw >
S: 250 bob@cs.nthu.edu.tw ... Recipient ok
C: DATA
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 cs.nthu.edu.tw closing connection
47. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen47
信息格式
RFC 822 為 text
message exchange
標準
Header lines
To:
From:
Subject:
Body
The message, ASCII
character only
header
body
blank
line
54. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen54
MIME 的種類 (types)
Content-Type: 種類 / 副檔名 ; 參數
(type/subtype; parameters)
文字 (Text)
例如:副 名為檔 plain,
html
圖片 (Image)
例如:副 名為檔 jpeg,
gif
聲音 (Audio)
例如:副 名為檔 basic (8-
bit mu-law encoded),
32kadpcm (32 kbps
coding)
影像 (Video)
例如:副 名為檔 mpeg,
quicktime
應用程式 (Application)
other data that must be
processed by reader before
“viewable”
例如:副 名為檔
msword, octet-stream
55. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen55
郵件存取協定 (mail access protocol)
SMTP 負責接收端 server 的傳送及儲存信息
Mail access protocol: 從 server 取回信件
POP: Post Office Protocol
RFC 1939
提供認證及下載服務
IMAP
RFC 2060
可以遠端操作信件,不需下載信件至機器上
HTTP (web mail)
Hot mail, mail2000, yahoo…
56. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen56
POP3 協定
authorization phase
client commands:
user: declare username
pass: password
server responses
+OK
-ERR
transaction phase, client:
list: list message numbers
retr: retrieve message by
number
dele: delete
quit
C: list
S: 1 498
S: 2 912
S: .
C: retr 1
S: <message 1 contents>
S: .
C: dele 1
C: retr 2
S: <message 1 contents>
S: .
C: dele 2
C: quit
S: +OK POP3 server signing off
S: +OK POP3 server ready
C: user alice
S: +OK
C: pass hungry
S: +OK user successfully logged on
57. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen57
Email Security ( 電子郵件的安全性 )
PGP: Pretty Good Privacy, by Phil Zimmermaun in 1995.
Support text compression, secrecy and digital signatures.
59. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen59
PEM: Privacy Enhanced Mail
An official Internet standard described in RFC
1421-1424.
Support privacy and authentication for RFC 822
based email systems.
The message together with its message digest is
encrypted using DES with a one-time key that is
enclosed along with the message.
The key can be protected with RSA and certified
by certification authorities.
61. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen61
DNS (Domain Name System)
-- Overview
名稱我們可以拿來做什麼?
確認、識別一個物件 (object)
幫助我們放置 (allocate) 一個物件
定義在一個團體中的關係
明確定義一個角色 (role)
傳送一個機密訊息
Name space( 名稱空間 )
定義一組可用的名稱
由一組名稱與數 的配對所組成值
62. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen62
DNS (Domain Name System) (cont.)
為什麼我們要使用 DNS ?
可以幫助我們對應 IP 位址和主機名字 (hostname)
無須記憶 IP 位址,只需記憶名字
DNS 是一個分散式的資料庫
將許多 name servers 變成階層式架構
DNS 是屬於應用層的協定
Host, routers, name server 透過溝通來達成解析名
稱的目的 (address/name translation)
63. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen63
DNS (Domain Name System) (cont.)
Hierarchy
Name
chinstrap.cs.princeton.edu
edu com
princeton …mit
cs ee
ux01 ux04
physics
cisco …yahoo nasa …nsf arpa …navy acm …ieee
gov mil org net uk fr
64. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen64
DNS (Domain Name System)
-- Example
Hosts
cheltenham.cs.princeton.edu
192.12.69.17
192.12.69.17 80:23:A8:33:5B:9F
Files
/usr/llp/tmp/foo (server, fileid)
Users
Larry Peterson llp@cs.princeton.edu
65. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen65
DNS (Domain Name System)
-- Example (cont.)
Mailboxes
Name
server
Mail
program
User
TCP
IP
2
cs.princeton.edu
192.12.69.5
3
user @ cs.princeton.edu
1
192.12.69.5 4
192.12.69.5 5
66. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen66
DNS name server
為什麼我們不採取集中式 DNS ?
如果單一 DNS server 壞了,會影響很大
Traffic volume ( 一台 server 不可能處理全部的位
址解析 )
Server 所放置的位置過遠
維護不易
DNS server 可分為
當地名稱伺服器 (Local name server)
根名稱伺服器 (Root name server)
認證名稱伺服器 (Authoritative name server)
67. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen67
DNS name server
Local name server
負責當地 (local) 名稱解析,如解析不成,往上詢問
root server
Root name server
負責解析當地 DNS 無法解析之 name
Authoritative name server
Host 都會來此主機註冊
當 root server 亦無法解析名稱時,就會詢問
authoritative name server
68. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen68
FQDN (Fully Qualify Domain Name)
一個將名稱與位址對應的機制
為的避免名稱重複
做流量控制
一個 DNS name = 一個 FQDN
一個 FQDN 名稱可以對應到多個 IP
名稱解析的流程: Interactive Query
以下為範例:
Search www.microsoft.com
69. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen69
名稱解析範例
DNS
Root
DNS
.org
DNS
.com
DNS
.edu
DNS
.tw
DNS
.microsoft
DNS
.ibm
DNS
.nthu
DNS
.cs
DNS
.mis
DNS
.web
1
2
3
4
5
ZONE
ZONE
www
70. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen70
名稱解析範例 (cont.)
Step1 : web.→ nthu.
Step2 : nthu. → Root (所以 Root 需要很多台)
(→ Q : com. 的 IP )(← com. DNS 的 IP )
Step3 : nthu. → com.
(→ Q : microsoft.com. 的 IP )(← microsoft.com. DNS
的 IP )
Step4 : nthu. → microsoft.
(→ Q : www.microsoft.com. 的 IP )(←
www.microsoft.com. DNS 的 IP )
取得名稱解析的 IP ,此 IP 會存放在 nthu 的 catch 中,存
放 TTL 的時間
Step5 : nthu. → web.
71. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen71
ZONE
ZONE :是一個特殊單位。一個 ZONE 一定要有一
個 DNS 來管,但是一個 DNS 可以管理許多的
ZONE ,而每一個 ZONE 都有一個 ZONE File
ZONE File
1. SOA ( Start-of-Authority )
Version Number (判斷新舊,但 clock 要相同)
Refresh timer (一個 ZONE 有兩個 DNS Server,
Secondary Server 每隔一段時間去跟 Master Server 複
製)
Entry timer
Expire time
TTL (問到機器的 IP 後可存放在 catch 中的時間。 if
TTL=0 ,多用於 Proxy, DHCP )
72. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen72
ZONE (cont.)
Administrator mail
Domain name
2. NS ( Name Server )
3. MX ( Mail Exchange Server )
4. A ( Host ): ZONE 有多少台機器,需要
Dynamic update
5. CN ( alias ):多 IP 對應一台主機
6. PTR ( Pointer ):
有 IP 名稱(逆向 詢)查 查
正向 詢查 : ---.ZONE
逆向 詢查 : 97.25.163.in-addr.arpa
73. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen73
Recursive Query
我們為了 Load balance 還有一種 Recursive
Query ,使用 Forward 方式進行(以 DNS 為單位,
對象不一定為上游)
執行順序:
Interactive Query
Recursive Query
If 要直接則使用 Forward
如下圖為 Recursive Query 動作流程
在圖中的 Catch DNS 為 Slave only ,它不用經過流程 1.
(詢問 Root )直接問 Catch DNS Forward 的 DNS ,如果
DNS 也不知道的話,就會使用 Interactive Query 詢查 。
74. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen74
Recursive Query (cont.)
DNS
Catch
DNS
Catch
DNS
Catch
DNS
Catch
DNS
Client
Forward
Recursive
Interactive
catch
catch
catch
Interactive
75. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen75
DNS 的種類
Interactive Query 和 Recursive Query 的分別
:
Interactive Query :已經找到全部的名稱
Recursive Query :為了 Load balance 的目的
DNS 的種類區分
Primary DNS :自己 ZONE
Secondary DNS :有從別人那一邊 copy 的
ZONE (只要有就算)
Master DNS :自己的 ZONE 被別人 Copy
Catch DNS :每一台 DNS Server 都算是
76. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen76
DNS 的種類 (cont.)
Master DNS
Primary DNS Secondary DNS
COPY
77. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen77
DNS 的紀錄檔
DNS: distributed db storing resource records (RR)
Type=NS
name is domain (e.g. foo.com)
value is IP address of
authoritative name server for
this domain
RR format: (name, value, type,ttl)
Type=A
name is hostname
value is IP address
Type=CNAME
name is an alias name
for some “cannonical”
(the real) name
value is cannonical
name
Type=MX
value is hostname of
mailserver associated with
name
79. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen79
DNS 協定的訊息格式
DNS 的 query 和 reply 訊息格式是一樣的
訊息標頭欄位
Identification: 一個 16 bit 的代號, query 和 reply
都使用同一個代號
Flags:
query 或 reply
Recursion desired
Recursion available
Reply is authoritative
80. Ch.2 Application-Layer(C) All rights reserved by Professor Wen-Tsuen80
DNS 協定的訊息格式 (cont.)
identification flags
number of
question
number ofanswer
RRs
number of
authorityRRs
number of
additional RRs
additional imformation
(variable number of resource records)
question
(variable number of question)
answers
(variable number of resource records)
authority
(variable number of resource records)
Name, type of
fieldsfor a query
RRsin response
to query
recordsfor
authoritative servers
additional helpful
info that may be
used
12
bytes