最基本的GRE實(shí)現是連接兩個(gè)對等路由器GRE-1和GRE-2的GRE隧道。在本實(shí)例中,兩個(gè)路由器通過(guò)串行鏈路連接,然后將GRE隧道創(chuàng )建在該鏈路之上。為了將通信嵌入到GRE隧道中,而不是讓無(wú)封裝的通信在普通串行鏈路上傳輸,兩個(gè)路由器中都加入了一個(gè)靜態(tài)的路由聲明。這個(gè)靜態(tài)路由基本規定了要到達另一個(gè)路由器后的專(zhuān)用網(wǎng)絡(luò ),最佳路徑就是通過(guò)隧道接口傳輸。在這些配置上還需要注意的是, 隧道接口的命名對于建立該隧道接口的路由器來(lái)說(shuō)完全是局部的。連接到的另一個(gè)路由器則沒(méi)有這個(gè)命名。另一個(gè)路由器關(guān)心隧道接口的配置而不是其命名。
tunnel source與tunnel destination命令基本確定了在GRE協(xié)議外部頭里IP地址是多少。顯然,如果你在Internet上發(fā)送GRE分組,則這些地址應當是全局可路由的。不過(guò),封裝在GRE分組中的分組不需要包含全局可路由的地址,因為GRE封裝使這些地址對Internet隱藏。
從12.2版開(kāi)始,Cisco IOS 軟件就開(kāi)始支持GRE keepalive。它允許GRE檢查GRE隧道中源地址與目標地址間的路徑是否已不再可用,在不可用時(shí)GRE隧道實(shí)際上轉入了線(xiàn)協(xié)議。
在隧道接口中另一個(gè)選項也可啟用。它們在本章前面RFC 1701的描述中已討論過(guò)。
在這個(gè)實(shí)例研究中的場(chǎng)景是很典型的,即兩個(gè)辦公室使用GRE隧道相連接。這樣的GRE隧道目的是使兩個(gè)辦公室的用戶(hù)可以像訪(fǎng)問(wèn)同一網(wǎng)絡(luò )一樣訪(fǎng)問(wèn)對方的專(zhuān)用網(wǎng)絡(luò )。盡管GRE允許兩個(gè)網(wǎng)絡(luò )連接到一起,但是GRE不提供安全性,例如它沒(méi)有對通信加密。必須在應用層或是網(wǎng)絡(luò )層中使用其他的方式提供這樣的安全性。當使用帶IPSec的GRE時(shí),GRE keepalives將像其他通信一樣被加密。同用戶(hù)數據分組一樣,如果IKE 和IPSec安全聯(lián)盟在GRE隧道中并不是已經(jīng)激活的,則第一個(gè)GRE keepalive分組將觸發(fā)IKE/IPSec初始化。圖11-5展示了本案例學(xué)習中討論的GRE實(shí)現,同時(shí)例11-1展示了兩個(gè)路由器的配置。
(點(diǎn)擊查看大圖)圖11-5 本實(shí)例研究的GRE實(shí)現
例11-1 本實(shí)例研究中用到的兩個(gè)路由器的配置
GRE-1#
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname GRE-1
!The tunnel interface is set up using the interface tunnel command. It is a
!logical interface.
interface Tunnel0
ip unnumbered Serial1
!The command below sets up the keepalive feature for GRE tunnels. Based on the
!parameters entered into this command, GRE keepalive packets are sent every 5
!seconds. 4 is the number of times this router continues sending keepalive
!packets without response before bringing the tunnel interface protocol down.
keepalive 5 4
!Tunnel source and destination specify the IP addresses that will be used as the
!source address and the destination address in the GRE header
(待續)
tunnel source Serial1
tunnel destination 50.1.1.2
!
interface Ethernet0
ip address 10.1.1.2 255.255.255.0
!
!
interface Serial1
ip address 50.1.1.1 255.255.255.0
encapsulation ppp
!
ip classless !The static route below is used to push traffic
destined for the network behind the
!other router, into the GRE tunnel
ip route 10.1.2.0 255.255.255.0 Tunnel0
! line con 0
line aux 0
line vty 0 4
login
!
end GRE-1# GRE-2#
!
version 12.2
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname GRE-2
ip subnet-zero
!The command below defines the tunnel interface
on this router. Please note that
!the numbering of the tunnels has only local significance. interface Tunnel0
ip unnumbered Serial0
keepalive 5 4
tunnel source Serial0
tunnel destination 50.1.1.1
!
interface Ethernet0
ip address 10.1.2.1 255.255.255.0
! !
interface Serial0
ip address 50.1.1.2 255.255.255.0
(待續)
encapsulation ppp
no fair-queue
clockrate 9600 !
ip classless
!The static route below is used to push traffic
destined for the network behind
!the other router, into the GRE tunnel
ip route 10.1.1.0 255.255.255.0 Tunnel0
no ip http server
!
!
line con 0
transport input none
line aux 0
line vty 0 4
!
end GRE-2#
這里的配置展示的是一個(gè)非常簡(jiǎn)單的使用靜態(tài)路由的GRE實(shí)現。GRE也可以使用路由協(xié)議創(chuàng )建。在該例中GRE接口的功能同任何物理接口完全一樣。