簡介:
PPPoE(PPP over Ethernet)協議是一種把PPP幀封裝到以太網幀中的鏈路層協議。PPPoE可以使以太網網絡中的多臺主機連接到遠端的寬帶接入服務器。
目的:
運營商希望把一個站點上的多臺主機連接到同一臺遠程接入設備,同時接入設備能夠提供與撥號上網類似的訪問控制和計費功能。在衆多的接入技術中,把多個主機連接到接入設備的最經濟的方法就是以太網,而PPP協議可以提供良好的訪問控制和計費功能,於是產生了在以太網上傳輸PPP報文的技術,即PPPoE。
PPPoE利用以太網將大量主機組成網絡,通過一個遠端接入設備連入因特網,並運用PPP協議對接入的每個主機進行控制,具有適用範圍廣、安全性高、計費方便的特點。
PPPoE典型組網:
PPPoE組網結構採用Client/Server模型,PPPoE的客戶端爲PPPoE Client,PPPoE的服務器端爲PPPoE Server。PPPoE Client向PPPoE Server發起連接請求,PPPoE Server爲PPPoE Client提供接入控制、認證等功能。
常見企業或者家庭組網模式:路由器設備作爲PPPoE Client:
Router A作爲PPPoE Client下行連接局域網用戶,Router B是運營商的設備。所有主機不用安裝PPPoE Client撥號軟件,同一個局域網中的所有主機共享一個賬號,通過Router A與Router B建立PPPoE會話。
PPPoE撥號的工作原理:
PPPoE撥號是爲了實現PPPoE Client與PPPoE Server之間的連接,建立PPPoE會話。
PPPoE撥號可分爲三個階段,即Discovery階段、Session階段和Terminate階段。
如下圖:
Discovery階段由四個過程組成。
1.PPPoE Client廣播發送一個PADI(PPPoE Active Discovery Initial)報文,在此報文中包含PPPoE Client想要得到的服務類型信息。
2.所有的PPPoE Server收到PADI報文之後,將其中請求的服務與自己能夠提供的服務進行比較,如果可以提供,則單播回覆一個PADO(PPPoE Active Discovery Offer)報文。
3.根據網絡的拓撲結構,PPPoE Client可能收到多個PPPoE Server發送的PADO報文,PPPoE Client選擇最先收到的PADO報文對應的PPPoE Server做爲自己的PPPoE Server,並單播發送一個PADR(PPPoE Active Discovery Request)報文。
4.PPPoE Server產生一個唯一的會話ID(Session ID),標識和PPPoE Client的這個會話,通過發送一個PADS(PPPoE Active Discovery Session-confirmation)報文把會話ID發送給PPPoE Client,會話建立成功後便進入PPPoE Session階段。
完成之後通信雙方都會知道PPPoE的Session_ID以及對方的以太網地址,它們共同確定了唯一的PPPoE Session。
Session階段:
PPPoE Session階段可劃分爲兩部分,一是PPP協商階段,二是PPP數據傳輸階段。
PPPoE Session上的PPP協商和普通的PPP協商方式一致,分爲LCP、認證、NCP三個階段。
1.LCP階段主要完成建立、配置和檢測數據鏈路連接。
2.LCP協商成功後,開始進行認證,認證協議類型由LCP協商結果(CHAP或者PAP)決定。
3.認證成功後,PPP進入NCP階段。NCP是一個協議族,用於配置不同的網絡層協議,常用的是IP控制協議(IPCP),它主要負責協商用戶的IP地址和DNS服務器地址。
PPPoE Session的PPP協商成功後,就可以承載PPP數據報文。
在PPPoE Session階段所有的以太網數據包都是單播發送的。
Terminate階段:
PPP通信雙方可以使用PPP協議自身來結束PPPoE會話,當無法使用PPP協議結束會話時可以使用PADT(PPPoE Active Discovery Terminate)報文。
進入PPPoE Session階段後,PPPoE Client和PPPoE Server都可以通過發送PADT報文的方式來結束PPPoE連接。PADT數據包可以在會話建立以後的任意時刻單播發送。在發送或接收到PADT後,就不允許再使用該會話發送PPP流量了。
拓撲:
配置:
R1(config)#host Server
Server(config)#username qytang password cisco //設備本地用戶數據庫
Server(config)#ip local pool PPPOE_POOL 201.100.98.42 //設置本地地址池
Server(config)#int virtual-template 1 //設置虛擬模版
Server(config-if)#ip add 201.100.98.41 255.255.255.252 //配置IP地址,模擬公網地址
Server(config-if)#peer default ip address pool PPPOE_POOL //調用本地地址池
Server(config-if)#ppp authentication chap //設置CHAP認證
Server(config)#bba-group pppoe CISCO //設置bba-group
Server(config-bba-group)#virtual-template 1 //調用虛擬模版
Server(config)#int e0/0
Server(config-if)#pppoe enable group CISCO //接口調用bba-group
Server(config-if)#no shut
Client:
R2(config)#host Client
Client(config)#int dialer 1 //撥號接口1
Client(config-if)#ip add negotiated //地址自動協商
Client(config-if)#encapsulation ppp //封裝模式PPP
Client(config-if)#ppp chap hostname qytang //CHAP認證用戶名
Client(config-if)#ppp chap password cisco //CHAP認證密碼
Client(config)#int e0/0
Client(config-if)#pppoe-client dial-pool-number 1 //調用撥號接口1
Client(config-if)#no shut
Server#show ip int b
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 unassigned YES unset up up
Ethernet0/1 unassigned YES unset administratively down down
Ethernet0/2 unassigned YES unset administratively down down
Ethernet0/3 unassigned YES unset administratively down down
Virtual-Access1 unassigned YES unset down down
Virtual-Access2 unassigned YES unset up up
Virtual-Access2.1 201.100.98.41 YES manual up up
Virtual-Template1 201.100.98.41 YES manual down down
Client#show ip int b
Interface IP-Address OK? Method Status Protocol
Ethernet0/0 unassigned YES unset up up
Ethernet0/1 unassigned YES unset administratively down down
Ethernet0/2 unassigned YES unset administratively down down
Ethernet0/3 unassigned YES unset administratively down down
Dialer1 201.100.98.42 YES IPCP up up
Virtual-Access1 unassigned YES unset up up
Server#show ppp all //查看PPP協商認證
Interface/ID OPEN+ Nego* Fail- Stage Peer Address Peer Name
------------ --------------------- -------- --------------- --------------------
Vi2.1 LCP+ CHAP+ IPCP+ LocalT 201.100.98.42 qytang
Server#
Server#show pppoe session //查看PPPOE會話
1 session in LOCALLY_TERMINATED (PTA) State
1 session total
Uniq ID PPPoE RemMAC Port VT VA State
SID LocMAC VA-st Type
2 2 aabb.cc00.2000 Et0/0 1 Vi2.1 PTA
aabb.cc00.1000 UP
Server#
測試:
Client#ping 201.100.98.41
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 201.100.98.41, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Server#
*Dec 3 08:29:39.255: PPPoE 0: I PADI R:aabb.cc00.2000 L:ffff.ffff.ffff Et0/0
*Dec 3 08:29:39.255: Service tag: NULL Tag
*Dec 3 08:29:39.255: PPPoE 0: O PADO, R:aabb.cc00.1000 L:aabb.cc00.2000 Et0/0
*Dec 3 08:29:39.255: Service tag: NULL Tag
Server#
*Dec 3 08:29:41.341: PPPoE 0: I PADR R:aabb.cc00.2000 L:aabb.cc00.1000 Et0/0
*Dec 3 08:29:41.341: Service tag: NULL Tag
*Dec 3 08:29:41.341: PPPoE : encap string prepared
*Dec 3 08:29:41.341: [2]PPPoE 2: Access IE handle allocated
*Dec 3 08:29:41.341: [2]PPPoE 2: AAA unique ID E allocated
*Dec 3 08:29:41.341: [2]PPPoE 2: No AAA accounting method list
*Dec 3 08:29:41.341: [2]PPPoE 2: Service request sent to SSS
*Dec 3 08:29:41.341: [2]PPPoE 2: Created, Service: None R:aabb.cc00.1000 L:aabb.cc00.2000 Et0/0
*Dec 3 08:29:41.341: [2]PPPoE 2: State NAS_PORT_POLICY_INQUIRY Event SSS MORE KEYS
*Dec 3 08:29:41.345: [2]PPPoE 2: data path set to PPP
*Dec 3 08:29:41.346: [2]PPPoE 2: Segment (SSS class): PROVISION
*Dec 3 08:29:41.346: [2]PPPoE 2: State PROVISION_PPP Event SSM PROVISIONED
*Dec 3 08:29:41.346: [2]PPPoE 2: O PADS R:aabb.cc00.2000 L:aabb.cc00.1000 Et0/0
*Dec 3 08:29:41.390: [2]PPPoE 2: State LCP_NEGOTIATION Event SSS CONNECT LOCAL
*Dec 3 08:29:41.398: [2]PPPoE 2: Segment (SSS class): UPDATED
*Dec 3 08:29:41.398: [2]PPPoE 2: Segment (SSS class): BOUND
*Dec 3 08:29:41.398: [2]PPPoE 2: data path set to Virtual Acess
*Dec 3 08:29:41.398: [2]PPPoE 2: State LCP_NEGOTIATION Event SSM UPDATED
*Dec 3 08:29:41.398: [2]PPPoE 2: State PTA_BINDING Event STATIC BIND RESPONSE
Server#
*Dec 3 08:29:41.398: [2]PPPoE 2: Connected PTA
*Dec 3 08:29:41.432: PPPoE : ipfib_encapstr prepared
Server#
通過wireshark抓包顯示如下:
PPPoE優化:
二次封裝耗費資源,降低了傳輸效能
MTU1492:
以太網最大負載1500,pppoe頭爲6字節,PPP協議爲2字節,而整個二層幀爲1518,那麼PPPoE的MTU=1518-18-6-2=1492字節
MSS(Maxitum Segment Size )是TCP數據包每次能夠傳輸的最大數據分段。爲了達到最佳的傳輸效能TCP協議在建立連接的時候通常要協商雙方的MSS值,這個值TCP協議在實現的時候爲1460
interface Dialer1
ip mtu 1492 //修改 MTU 爲1492
ip tcp adjust-mss 1452 //修改最大數據分段大小爲1452 MSS=1500byte-IP 20byte-tcp 20byte- pppoe 6byte-ppp 2byte=1452