GRE是一項由美國思科公司開發的輕量級隧道協議,它能夠將各種網絡層協議進行封裝到IP包中,通過隧道創建一個虛擬的點到點鏈路,把兩臺路由器連接起來,實現數據傳輸的功能。GRE本身是不加密的,但可以使用IPSEC對GRE中的數據進行保護,即GRE Over IPSEC,我們常用的DM***也是GRE的一種。
封裝:
抓包:
GRE實驗
拓撲圖:
實驗介紹:
R1和R3模擬一家公司在不同兩個地方的路由器,R2模擬運營商路由器。R1在北京,R3在上海,要想讓上海的員工能夠訪問北京的服務器,在R1和R3之間建立一條GRE隧道,並啓用動態路由協議,實現R1和R3路由器身後的網絡能夠互通。
網絡基本配置:
R1(config)#int f0/0
R1(config-if)#ip add 12.1.1.1255.255.255.0
R1(config-if)#no shut
R1(config-if)#int lo 0
R1(config-if)#ip add 1.1.1.1255.255.255.0
R1(config)#ip route 0.0.0.0 0.0.0.012.1.1.2
R2(config)#int f0/0
R2(config-if)#ip add 12.1.1.2255.255.255.0
R2(config-if)#no shut
R2(config-if)#int f1/0
R2(config-if)#ip add 23.1.1.2255.255.255.0
R2(config-if)#no shut
R3(config)#int f1/0
R3(config-if)#ip add 23.1.1.3255.255.255.0
R3(config-if)#no shut
R3(config-if)#int lo 0
R3(config-if)#ip add 3.3.3.3255.255.255.0
R3(config)#ip route 0.0.0.0 0.0.0.023.1.1.2
GRE配置:
R1:
R1(config)#int tunnel 0
R1(config-if)#ip add 172.16.1.1255.255.255.0
R1(config-if)#tunnel source f0/0
R1(config-if)#tunnel destination23.1.1.3
R3:
R3(config)#int tunnel 0
R3(config-if)#ip add 172.16.1.2255.255.255.0
R3(config-if)#tunnel source f1/0
R3(config-if)#tunnel destination12.1.1.1
測試:
R1#ping 172.16.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to172.16.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5),round-trip min/avg/max = 56/84/104 ms
動態路由協議:
R1:
R1(config)#router ospf 110
R1(config-router)#net 1.1.1.0 0.0.0.255a 0
R1(config-router)#net 172.16.1.00.0.0.255 a 0
R3:
R3(config)#router ospf 110
R3(config-router)#net 3.3.3.0 0.0.0.255a 0
R3(config-router)#net 172.16.1.00.0.0.255 a 0
測試:
查看OSPF鄰居:
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 0 FULL/ - 00:00:38 172.16.1.2 Tunnel0
Ping測試:
R1#ping 3.3.3.3 source 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to3.3.3.3, timeout is 2 seconds:
Packet sent with a source address of1.1.1.1
!!!!!
Success rate is 100 percent (5/5),round-trip min/avg/max = 44/79/100 ms
可以看到R1和R3身後的網絡已經連通了,需要注意,這時的數據都是沒有加密的,只要中間有人捕獲到這些數據就可以看到裏面的內容,是不安全的。可以使用GRE Over IPSEC,即把GRE的數據再封裝在IPSEC ***中。這樣數據即被加了密,還可以使用GRE的接口,啓用動態路由協議,添加ACL等進行路由控制,比單純的L2L IPSEC ***要靈活很多。
附件是GRE的抓包,感興趣的同學可以下載下來分析。