PPP協議

 
本文出自 “狼窟” 博客,請務必保留此出處[url]http://yangyangdedipan.blog.51cto.com/286500/61504[/url]
 
 
廣域網連接使用的數據鏈路層協議有幀中繼,PPPATM等,其中應用最廣泛的時PPP協議,PPPPoint to Point Protocol點對點協議的簡稱,PPP以及  生出的PPPoE,PPPoA等協議成爲目前廣域網連接和寬帶接入中使用最多的數據鏈路層協議
 
PPP協議的優點:
PPP協議提供了一種在點對點鏈路上封裝多種網絡數據報文(IPIPX,和AppleTalk)的標準方法,與SLIP協議相比,PPP協議具有以下優點:
(1) 支持同步,異步串行鏈路
(2) 支持多種網絡層協議
(3) 支持各種連接參數的協商
(4) 支持錯誤檢測
(5) 支持用戶認證
(6) 允許進行數據壓縮
PPP協議由3個部分組成:協議封裝方式,LCP協議和NCP協議

 

協議封裝方式:提供了一種將網絡層協議封裝到串行鏈路的方法,PPP既支持面向字符的異步串行鏈路,也支持面向比特的同步串行鏈路

 

LCP(Link Control Protocols 鏈路控制協議):爲了能適應複雜多變網絡環境,PPP協議提供一種鏈路控制協議來配置和測試數據通信鏈路,他能用來協商PPP協議的一些配置參數選項;處理不同大小的數據幀;檢測鏈路環路,一些鏈路的錯誤;終止一條鏈路。

 

NCP(Network Control Protocols 網絡控制協議)PPP的網絡控制協議根據不同的網絡層協議可提供一族網絡控制協議,常用的提供給TCP/IP網絡使用的IPCP網絡控制協議和提供給SPX/IPX網絡使用的IPXCP網絡控制協議等,但最爲常用的是IPCP協議,當點對點的兩端進行NCP參數配置協商時,主要是用來協商通信雙方的網絡層地址等。
PPP鏈路的工作過程
(1) 鏈路不可用階段(Link Dead Phase)在最開始,整條鏈路處於鏈路不可用狀態,此階段有時也稱爲物理不可用階段,PPP鏈路都需從這個階段開始和結束,當通信雙方的兩端檢測到物理線路激活時,就會從當前這個階段進入到鏈路建立階段
(2) 鏈路建立階段 (Link Establishment Phase) 在此階段,PPP鏈路將進行LCP相關協商,協商內容包括工作方式,認證方式,連路壓縮等,LCP在協商成功後進入Opened狀態,表示底層鏈路已經建立,如果鏈路協商失敗,則會返回到第一階段,在鏈路建立階段成功後,如果配置了PPP認證,則會進入認證階段,如果沒有配置PPP認證,則會直接進入網絡層協議階段
(3) 認證階段 (Authentication Phase) 在此階段,PPP將進行用戶認證工作,PPP支持PAPCHAP兩種認證方式,關於這兩種認證方式在後面將會詳細介紹,如果認證失敗,PPP鏈路會進入鏈路終止階段,拆除鏈路,LCP狀態轉爲DOWN,如果認證成功就進入網絡層協議階段
(4) 網絡層協議階段 (Network-Layer Protocol Phase) 一旦PPP完成了前面幾個階段,每種網絡層協議(IPIPX等)會通過各自相應網絡控制協議進行配置,只有相應的網絡層協議協商成功後,該網絡層協議纔可以通過這條PPP鏈路發送報文,對於IPCP協議,協商的內容主要包括雙方的IP地址等
(5) 鏈路終止階段 (Link Termination Phase) PPP能在任何時候終止鏈路,載波丟失,認證失敗後用戶人爲關閉鏈路等情況均會導致鏈路終止,PPP協議通過交換LCP的鏈路之中報文來關閉鏈路,當鏈路關閉時,連路層會通知網絡層做相應的操作,而且也會通過物理層強制關斷鏈路
PPP協議的封裝
   PPP協議屬於數據鏈路層協議,他可以將多種網絡協議封裝在PPP幀中,從而達到支持多種網絡層協議的目的,PPP協議才用了同HDLC協議很相似的幀格式,
SLIP協議類似,PPP協議也規定了幀的定界字節,每一個PPP數據幀均是一個標誌字節起始和結束的,該字節爲0x7E

 

緊接在起始標誌字節後的一個字節是地址域,該字節爲0xFF,OSI 7 層模型中,網絡的數據鏈路層要進行通信,首先必須獲知對方的地址。

 

同地址域一樣,PPP數據幀的控制域也沒有實際意義,按照協議的規定通信雙方將該字節的內容填充爲 0x03

 

協議域用來說明PPP所封裝的協議報文類型,它可用來區分PPP數據幀中信息域所承載的數據報文的內容,協議域的取值不同,後面的信息字段所代表的類型就不同協議域的具體取值見下表
幀校驗序列域主要是對PPP數據幀傳輸的正確性進行檢測的,它採用CRC算法,當數據幀在傳輸時因爲噪聲干擾等因素髮生變化時,接收端就可以根據幀校驗域的內容判斷出來,將錯誤的幀丟棄,幀校驗域的長度默認爲2字節,但是通過LCP協商,它也可以爲4個字節
 
LCP協議
   
        LCP協議負責數據鏈路的建立,配置,維護,測試和終止,在數據建立階段,LCP協議進行鏈路層參數的協商,此時PPP數據幀的協議域爲0xC021,信息域的內容爲LCP數據報文
LCP協議在對鏈路配置過程中需要進行一些可選配置參數選項的協商,其中比較重要的協商選項由以下幾個
1.  MRU(Maxium Receive Unit 最大接收單元)
2.  Magic Number (魔術字)
3.  認證方式
4.  鏈路壓縮
5.  多鏈路捆綁
 
NCP協議
 
NCP協議的數據報文是在網絡層協議階段被交換的,在這個階段所需的一些配置參數選項協商完後,就可以進行網絡層的通信,也即是在點對點的鏈路上可以開始傳送網絡層的數據報文了,NCP協議主要包括IPCP(IP Control Protocol ,IP 控制協議) IPXCP(IPXControl Protocol ,IPX控制協議) 等,但在實際應用當中最常預見的只有IPCP協議,
IPCP控制協議主要是負責協商IP網絡層協議通信所需配置參數的選項,IPCP協議主要協商的參數有以下幾個,
 
1.  IP
2.  TCP/IP頭壓縮
 
PPP認證
 
PPP支持兩種認證方式,PAP認證和CHAP認證
 
1.  PAP認證
PAPPassword Authentication Protocol,密碼認證協議)PAP爲兩次握手認證協議,
被認證方發起認證請求,發送用戶名和口令到主認證方
主認證讓根據本端用戶表查看是否有此用戶以及口令是否正確,然後返回認證通過或不通過,
2.  CHAP認證
CHAPChallenge Hand Authentication Protocol 質詢握手認證協議的簡稱,與PAP認證比起來,CHAP認證更具有安全性,在PAP認證中,被認證方採用明文的方式直接將用戶名和密碼發送給主認證方,這很容易引起密碼的泄漏
CHAP爲三次握手協議,它只在網絡上傳送用戶名而不傳送口令,因此安全性比PAP高,CHAP認證的程序如下
       (1).主認證方主動發起認證請求,主認證方向被認證方發送一些隨機產生的報文                                                                         (Challenge),並同時將本端的用戶名附帶上一起發送給被認證方
(2).被認證方接到主認證方的認證請求後,被認證方根據此報文中主認證方的用戶名查                                                                     找用戶密碼
(3).主認證方接受到該報文後,根據此報文中被認證方的用戶名,在自己的本地用戶數據庫中查找被認證方用戶名對應的被認證方密碼(CHAP認證密碼),利用報文ID,該密碼和MD5算法對原隨機報文加密,然後將加密的結果和被認證方發來的加密結果進行比較
 
 
配置實例:
 
 
 
                                                                               PPP(pap)

r1
Router>enable
Router#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#line Console 0
Router(config-line)#exec-timeout 0 0
Router(config-line)#logging synchronous
Router(config-line)#exit
Router(config)#no ip domain lookup
Router(config)#no cdp run
Router(config)#exit
00:01:55: %SYS-5-CONFIG_I: Configured from console by console
Router#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#hostname r1
r1(config)#username benet password cisco                         \\主認證端數據庫,是被認證的用戶名和密碼
r1(config)#interface s0/0
r1(config-if)#ip address 192.168.1.1 255.255.255.0
r1(config-if)#encapsulation ppp                                           \\端口封裝成PPP協議
r1(config-if)#ppp authentication pap                                   \\啓用PAP認證
r1(config-if)#no shutdown
r1(config-if)#exit
00:05:51: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
r1(config)#exit
00:05:56: %SYS-5-CONFIG_I: Configured from console by console
00:06:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
r1#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  192.168.1.1     YES manual up                    up     
Serial0/1                  unassigned      YES unset  administratively down down   
Serial0/2                  unassigned      YES unset  administratively down down   
Serial0/3                  unassigned      YES unset  administratively down down
r1#ping 192.168.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/66/72 ms

r2
Router>enable
Router#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#line console 0
Router(config-line)#exec-timeout 0 0
Router(config-line)#logging synchronous
Router(config-line)#exit
Router(config)#no ip domain lookup
Router(config)#no cdp run
Router(config)#exit
00:03:04: %SYS-5-CONFIG_I: Configured from console by console
Router#config terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#hostname r2
r2(config)#exit
00:03:21: %IP_SNMP-3-SOCKET: can't open UDP socket
r2#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
r2(config)#interface s0/0
r2(config-if)#ip address 192.168.1.2 255.255.255.0
r2(config-if)#encapsulation ppp                                                  \\將端口封裝成PPP協議
r2(config-if)#ppp pap sent-username benet password cisco       \\被認證端PAP認證的用戶名和密碼
r2(config-if)#no shutdown
r2(config-if)#exit
r2(config)#exit
00:06:45: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
00:06:46: %SYS-5-CONFIG_I: Configured from console by console

r2#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  192.168.1.2     YES manual up                    up     
Serial0/1                  unassigned      YES unset  administratively down down   
Serial0/2                  unassigned      YES unset  administratively down down   
Serial0/3                  unassigned      YES unset  administratively down down   
r2#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/77/96 ms
                                            
 
                                                                                       (chap)
r1>enable
r1#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
r1(config)#username r2 password cisco                                      \\被認證端用戶名和密碼
r1(config)#interface s0/0
r1(config-if)#ip address 192.168.1.1 255.255.255.0
r1(config-if)#encapsulation ppp
r1(config-if)#ppp authentication chap                                          \\啓用chap認證
r1(config-if)#no shutdown
r1(config-if)#exit
r1(config)#exit
00:09:23: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
00:09:23: %SYS-5-CONFIG_I: Configured from console by console
00:11:01: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up

r1#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  192.168.1.1     YES manual up                    up     
Serial0/1                  unassigned      YES unset  administratively down down   
Serial0/2                  unassigned      YES unset  administratively down down   
Serial0/3                  unassigned      YES unset  administratively down down   
r1#ping 192.168.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 52/77/96 ms

r2>enable
r2#config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
r2(config)#interface s0/0
r2(config-if)#ip address 192.168.1.2 255.255.255.0
r2(config-if)#encapsulation ppp     
r2(config-if)#ppp chap password cisco                                        \\向主認證端發送自己的密碼
r2(config-if)#no shutdown
r2(config-if)#exit
r2(config)#exit
00:10:45: %SYS-5-CONFIG_I: Configured from console by console
00:10:45: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
00:10:47: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up

r2#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
Serial0/0                  192.168.1.2     YES manual up                    up     
Serial0/1                  unassigned      YES unset  administratively down down   
Serial0/2                  unassigned      YES unset  administratively down down   
Serial0/3                  unassigned      YES unset  administratively down down   
r2#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 36/64/72 ms
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章