眾所周知,IPSec可用於封裝各種諸如路由器到路由器,防火牆到路由器,PC到路由器和PC到服務器之間的數據包,以保證數據包在這些設備之間的傳輸安全。它包含2種數據封裝方式,他們是通道模式和傳輸模式。傳輸模式僅封裝數據包的有效負載,而通道模式還會額外封裝數據包的報頭。
在本文中,讓我們一起關注IPSec通道模式中的一個比較常用的封裝方法:通用路由封裝(Generic Routing Encapsulation,以下簡稱GRE)。
GRE會使用一種GRE專有的封裝報頭來加密數據包的報頭和有效負載。網絡設計者通常會使用這種封裝方法來隱藏數據包的IP報頭並以此作為GRE封裝負載的一部分。通過隱藏此類信息,網絡設計者可以讓數據通過“隱藏通道”傳輸至另一個網絡並且無須改變任何網絡的底層架構。
以下介紹GRE的基礎配置方法:
首先大致介紹一下本網絡拓撲圖中的大致信息:網絡中包含了3台思科路由器。R1和R2,R2和R3通過串行的方式互聯。我們將在R1和R3之間配置一條GRE通道。
在R1路由器中,串行接口S0/0/0的地址為:192.168.12.1/24,另一端連接至R2的串行接口,地址為:192.168.12.2/24。R2串行接口S0/0/1地址為:192.168.23.2/24,連接至R3串行接口S0/0/1,地址為:192.168.23.1,此區域內所有接口均通過增強型內部網關路由協議(Enhanced Interior Gateway Routing Protocol,以下簡稱EIGRP)相連接,區域1。另外,這里特別為R1和R3建立2個回路接口(Loopback),用於本次實驗環境。
在正式開始配置GRE通道之前,請允許本人解釋一下本拓撲結構在實際應用環境中的意義。在本圖中,R2可以被看作是一個連接2個(R1和R3)遠程站點的中間機構,在R1和R3之間建立一個GRE通道可以允許兩者之間建立起一個簡單的VPN並且相互提供路由。此類基於GRE通道的VPN在缺省前提下是不會被封裝的,不過通過簡單的配置即可實現數據封裝。
下面開始在R1和R3之間配置GRE通道:
GRE通道是一個被用作連接2個節點設備的邏輯接口。它和之前提到Loopback接口有些類似,它們都是被軟件創造出的虛擬接口。在此環境中,由於涉及到2台設備,您就必須在2台設備上分別配置通道端口並將其連接。
在思科互聯網操作系統12.0以上版本中,首先您需要進入配置模式,創建通道接口,在此環境中,通道號碼定義為0。然后,指定通道的源端口名稱和目標端口的IP地址,再為其手動配置通道接口的IP地址和子網掩碼即可。相關命令如下:
R1(config)# int tunnel0
R1(config-if)# tunnel source serial0/0/0
R1(config-if)# tunnel destination 192.168.23.3
R1(config-if)# ip address 172.16.13.1 255.255.255.0
R3(config)# int tunnel0
R3(config-if)# tunnel source serial0/0/1
R3(config-if)# tunnel destination 192.168.12.1
R3(config-if)# ip address 172.16.13.3 255.255.255.0
在完成配置后,您可以通過Ping命令來檢查通道端口的連通性:
R1# ping 172.16.13.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.13.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 68/69/72 ms
R3# ping 172.16.13.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.13.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 68/68/72 ms
正如前文所述,在GRE通道配置完成后,我們仍然需要配置一個動態路由協議來確保遠程站點可以動態學習到哪些IP網絡正在訪問它們。這里,我們依舊使用EIGRP協議,不過我們把這個GRE通道定義為區域2。相關命令如下:
R1(config)# router eigrp 2
R1(config-router)# no auto-summary
R1(config-router)# network 172.16.0.0
R3(config)# router eigrp 2
R3(config-router)# no auto-summary
R3(config-router)# network 172.16.0.0
完成后我們可以使用show ip eigrp neighbors 2命令來檢查是否在路由協議中已經包括對方。
R1# show ip eigrp neighbors 2
IP-EIGRP neighbors for process 2
H Address Interface Hold Uptime SRTT RTO Q Seq
(sec) (ms) Cnt Num
0 172.16.13.3 Tu0 10 00:01:14 100 5000 0 3
R3# show ip eigrp neighbors 2
IP-EIGRP neighbors for process 2
H Address Interface Hold Uptime SRTT RTO Q Seq
(sec) (ms) Cnt Num
0 172.16.13.1 Tu0 13 00:02:47 1608 5000 0 2
最后我們可以查看3台路由器的路由表:
R1# show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Serial0/0/0
172.16.0.0/24 is subnetted, 3 subnets
C 172.16.13.0 is directly connected, Tunnel0
C 172.16.1.0 is directly connected, Loopback0
D 172.16.3.0 [90/297372416] via 172.16.13.3, 00:04:23, Tunnel0
D 192.168.23.0/24 [90/2681856] via 192.168.12.2, 03:06:16, Serial0/0/0
R2# show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.12.0/24 is directly connected, Serial0/0/0
C 192.168.23.0/24 is directly connected, Serial0/0/1
R3# show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
D 192.168.12.0/24 [90/2681856] via 192.168.23.2, 03:06:54, Serial0/0/1
172.16.0.0/24 is subnetted, 3 subnets
C 172.16.13.0 is directly connected, Tunnel0
D 172.16.1.0 [90/297372416] via 172.16.13.1, 00:05:12, Tunnel0
C 172.16.3.0 is directly connected, Loopback0
C 192.168.23.0/24 is directly connected, Serial0/0/1
從三個路由表中可以看到R1和R3可以互相識別對方的通道路由(回路地址),然而,R2並沒有參與在其中,所以它並不能顯示出任何關於GRE通道的信息。
在這些配置完成之后,R2並不需要被告知在R1和R3后面會有一個私有網絡,它所做的僅是根據數據包的指向目標傳遞IP數據。在此實驗中,因為在GRE通道中的傳輸數據都會被一個新的IP報頭給封裝,所以R2僅根據最外面的IP報頭來傳輸數據。此時需要在GRE通道的兩側配置一個路由協議,這樣就可以保證遠程站點可以動態學習到哪些IP網絡正在訪問它們。