PPP(Point-to-Point Protocol)是數據鏈路層點對點通信的標準協議,廣泛應用於撥號接入、專線串口互聯。本文系統解析 PPP 組成、幀結構、工作狀態機、透明傳輸機制,並附 Cisco 路由器實戰配置範例。
旗標 0x7E | 位址 0xFF | 控制 0x03 | 協議 | 信息 | FCS (CRC) | 旗標 0x7E
| 特性 | 說明 |
|---|---|
| 簡單性 | 無序號/確認機制,依賴上層可靠傳輸;CRC 檢錯,錯誤即丟棄 |
| 多協議支援 | NCP 允許同一鏈路承載 IP、IPX、AppleTalk 等 |
| 多鏈路適應 | 同步/異步、光纖、電纜等物理介質 |
| 差錯檢測 | FCS (CRC-16/32) 保證無差錯接收 |
| 鏈路狀態檢測 | LCP Echo 請求/回應偵測鏈路活性 |
| 網路層地址協商 | IPCP 動態分配 IP、DNS、WINS |
| 數據壓縮協商 | Stac LZS、MPPC 等,節省頻寬 |
| 透明性 | 位元組填充(異步) / 零比特填充(同步) 避免旗標衝突 |
發送端:信息欄出現 0x7E → 0x7D 0x5E;0x7D → 0x7D 0x5D;0x00-0x1F → 0x7D (原值+0x20)。
接收端反向還原。
發送端:連續 5 個 1 後插入 1 個 0。
接收端:掃描到 5 個連續 1,刪除後緊鄰的 0。
Router> enable
Router# configure terminal
Router(config)# hostname Router0
Router0(config)# interface serial 2/0
Router0(config-if)# clock rate 64000 # DCE 端提供時鐘
Router0(config-if)# ip address 192.168.1.1 255.255.255.0
Router0(config-if)# no shutdown
Router0(config-if)# encapsulation ppp # 改為 PPP(預設 HDLC)
Router0(config-if)# exit
# 配置 CHAP 認證
Router0(config)# username Router1 password todd
Router0(config)# interface serial 2/0
Router0(config-if)# ppp authentication chap
驗證:show interface serial 2/0 顯示 Encapsulation PPP、LCP Open、IPCP Open 即成功。
避坑:兩端封裝必須一致(同為 PPP 或同為 HDLC);CHAP 需雙向配置 username/password,且 hostname 需與對端 username 一致。