通用路由封裝協議GRE(Generic Routing Encapsulation)提供了將一種協議的報文封裝在另外一種協議報文中的機制,是一種隧道封裝技術。GRE能夠封裝組播數據,並能夠和IPSec結合使用,從而保證語音、視頻等組播業務的安全
IPSec 用於在兩個端點之間提供安全的IP通訊,但只能加密並傳播單播數據,沒法加密和傳輸語音、視頻、動態路由協議信息等組播數據流量
GRE屬於網絡層協議 IP協議號爲47
GRE的優勢總結:
GRE實現機制簡單,對隧道兩端的設備負擔小
GRE隧道能夠經過IPv4網絡連通多種網絡協議的本地網絡,有效利用了原有的網絡架構,下降成本
GRE隧道擴展了跳數受限網絡協議的工做範圍,支持企業靈活設計網絡拓撲
GRE隧道能夠封裝組播數據,和IPSec結合使用時能夠保證語音、視頻等組播業務的安全
GRE隧道支持使能MPLS LDP,使用GRE隧道承載MPLS LDP報文,創建LDP LSP,實現MPLS骨幹網的互通
GRE隧道將不連續的子網鏈接起來,用於組建,實現企業總部和分支間安全的鏈接安全
GRE用來對某些網絡層協議如IPX(Internet Packet Exchange)的報文進行封裝,使這些被封裝的報文可以在另外一網絡層協議(如IP)中傳輸。GRE能夠解決異種網絡的傳輸問題
使用GRE能夠克服IGP協議的一些侷限性。例如,RIP路由協議是一種距離矢量路由協議,最大跳數爲15。若是網絡直徑超過15,設備將沒法通訊。這種狀況下,可使用GRE技術在兩個網絡節點之間搭建隧道,隱藏它們之間的跳數,擴大網絡的工做範圍
GRE和IPSEC技術的結合 GRE自己並不支持加密,於是經過GRE隧道傳輸的流量是不加密的。將IPSec技術與GRE相結合,能夠先創建GRE隧道對報文進行GRE封裝,而後再創建IPSec隧道對報文進行加密,以保證報文傳輸的完整性和私密性
網絡
GRE隧道是經過隧道兩端的Tunnel接口創建的,因此須要在隧道兩端的設備上分別配置Tunnel接口。對於GRE的Tunnel接口,須要指定其協議類型爲GRE、源地址或源接口、目的地址和Tunnel接口IP地址
隧道接口(tunnel接口)是爲實現報文的封裝而提供的一種點對點類型的虛擬接口 與loopback接口相似 都是一種邏輯接口
GRE隧道接口包含源地址、目的地址和隧道接口IP地址和封裝類型
Tunnel的源地址:配置報文傳輸協議中的源地址。
當配置地址類型時,直接做爲源地址使用
當配置類型爲源接口時,取該接口的IP地址做爲源地址使用
Tunnel的目的地址:配置報文傳輸協議中的目的地址
Tunnel接口IP地址:爲了在Tunnel接口上啓用動態路由協議,或使用靜態路由協議發佈Tunnel接口,須要爲Tunnel接口分配IP地址。Tunnel接口的IP地址能夠不是公網地址,甚至能夠借用其餘接口的IP地址以節約IP地址。可是當Tunnel接口借用IP地址後,該地址不能直接經過tunnel口互通,所以在借用IP地址狀況下,必須配置靜態路由或路由協議先實現借用地址的互通性,才能實現Tunnel的互通。
命令行配置以下:架構
[Huawei]interface Tunnel 0/0/1 [Huawei-Tunnel0/0/1]ip address 123.1.1.1 24 [Huawei-Tunnel0/0/1]tunnel-protocol gre [Huawei-Tunnel0/0/1]source 202.1.1.1 [Huawei-Tunnel0/0/1]destination 101.1.1.1 [Huawei]ip route-static 192.168.2.0 24 Tunnel 0/0/1
乘客協議(Passenger Protocol):封裝前的報文稱爲淨荷,封裝前的報文協議稱爲乘客協議
封裝協議(Encapsulation Protocol):GRE Header是由封裝協議完成並填充的,封裝協議也稱爲運載協議(Carrier Protocol)
傳輸協議(Transport Protocol或者Delivery Protocol):負責對封裝後的報文進行轉發的協議稱爲傳輸協議
GRE報文重要字段解釋:ide
Protocol Type 標識乘客協議的協議類型。常見的乘客協議爲IPv4協議,協議代碼爲0800 Key 關鍵字字段,隧道接收端用於對收到的報文進行驗證 Tunnel兩端的key必定要同樣
好比:
乘客協議爲IP或IPX協議 封裝協議爲GRE協議 傳輸協議爲IP協議
oop
需求:運行IP協議的兩個子網網絡1和網絡2 經過在SZ***和BJ***之間使用三層隧道協議GRE實現互聯
加密
在PC1上面ping PC2 SZ_*接收到PC1的ICMP報文後,首先交由轉發模塊處理
轉發模塊根據報文頭中的目的地址在路由表或轉發表中查找出接口,肯定如何轉發此報文。若是發現出接口是GRE Tunnel0/0/1接口,系統會讀取tunnel0/0/1接口的配置 發現隧道封裝協議爲GRE協議 而且隧道的SIP和DIP都有 會交給GRE模塊進行處理,則對報文進行GRE封裝,即添加GRE頭。GRE協議模塊工做就作完了
而後回交給路由器的轉發模塊**處理 此時的SIP是202.1.1.1 DIP是101.1.1.1的數據報文 路由器根據DIP查找轉發表 會匹配默認路由從G0/0/0發出去命令行
BJ*從G0/0/0接口收到該報文,交給轉發模塊**處理 分析DIP頭髮現報文的目的地址爲本設備,而且protocol數值爲47 則BJ*去掉IP頭後交給GRE模塊處理。GRE首先會進行覈對 發過來的GRE報文中的SIP和DIP是否和我自身tunnel接口配置同樣 若是同樣的話 GRE模塊會接收 若是不同的話 直接進行丟棄。
GRE協議剝掉GRE報頭,獲取ICMP協議報文,再交由ICMP協議對此數據報文進行後續的轉發模塊**處理。查找路由表 從接口G0/0/1接口發出去設計
**SZ_*路由器的配置code
# sysname SZ_*** # interface GigabitEthernet0/0/0 ip address 202.1.1.1 255.255.255.0 # interface GigabitEthernet0/0/1 ip address 192.168.1.254 255.255.255.0 # ip route-static 0.0.0.0 0.0.0.0 202.1.1.254 #
**BJ_*路由器的配置視頻
# sysname BJ_*** # interface GigabitEthernet0/0/0 ip address 101.1.1.1 255.255.255.0 # interface GigabitEthernet0/0/1 ip address 192.168.2.254 255.255.255.0 # ip route-static 0.0.0.0 0.0.0.0 101.1.1.254 #
internet的配置
# interface GigabitEthernet0/0/0 ip address 202.1.1.254 255.255.255.0 # interface GigabitEthernet0/0/1 ip address 101.1.1.254 255.255.255.0 #
檢查以下:
**檢查SZ_*和PC1的通訊
<SZ_***>ping 192.168.1.1 PING 192.168.1.1: 56 data bytes, press CTRL_C to break Reply from 192.168.1.1: bytes=56 Sequence=1 ttl=128 time=40 ms Reply from 192.168.1.1: bytes=56 Sequence=2 ttl=128 time=60 ms Reply from 192.168.1.1: bytes=56 Sequence=3 ttl=128 time=40 ms Reply from 192.168.1.1: bytes=56 Sequence=4 ttl=128 time=60 ms Reply from 192.168.1.1: bytes=56 Sequence=5 ttl=128 time=50 ms --- 192.168.1.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 40/50/60 ms
**檢查BJ_*和PC2的通訊
<SZ_***>ping 192.168.1.1 PING 192.168.1.1: 56 data bytes, press CTRL_C to break Reply from 192.168.1.1: bytes=56 Sequence=1 ttl=128 time=40 ms Reply from 192.168.1.1: bytes=56 Sequence=2 ttl=128 time=60 ms Reply from 192.168.1.1: bytes=56 Sequence=3 ttl=128 time=40 ms Reply from 192.168.1.1: bytes=56 Sequence=4 ttl=128 time=60 ms Reply from 192.168.1.1: bytes=56 Sequence=5 ttl=128 time=50 ms --- 192.168.1.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 40/50/60 ms
檢查SZ***和BJ*的通訊**
<SZ_***>ping 101.1.1.1 PING 101.1.1.1: 56 data bytes, press CTRL_C to break Reply from 101.1.1.1: bytes=56 Sequence=1 ttl=254 time=30 ms Reply from 101.1.1.1: bytes=56 Sequence=2 ttl=254 time=20 ms Reply from 101.1.1.1: bytes=56 Sequence=3 ttl=254 time=40 ms Reply from 101.1.1.1: bytes=56 Sequence=4 ttl=254 time=20 ms Reply from 101.1.1.1: bytes=56 Sequence=5 ttl=254 time=30 ms --- 101.1.1.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/28/40 ms
檢查PC1和PC2的通訊
PC>ping 192.168.2.2 Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break Request timeout! Request timeout! Request timeout! Request timeout! Request timeout! --- 192.168.2.2 ping statistics --- 5 packet(s) transmitted 0 packet(s) received 100.00% packet loss
**SZ_*的配置
# interface Tunnel0/0/1 ip address 123.1.1.1 255.255.255.0 tunnel-protocol gre source 202.1.1.1 destination 101.1.1.1 #
**BJ_*的配置
# interface Tunnel0/0/1 ip address 123.1.1.2 255.255.255.0 tunnel-protocol gre source 101.1.1.1 destination 202.1.1.1 #
**SZ_*的配置
# ip route-static 192.168.2.0 255.255.255.0 Tunnel0/0/1 #
**BJ_*的配置
# ip route-static 192.168.1.0 255.255.255.0 Tunnel0/0/1 #
**SZ_*的檢查
<SZ_***>display interface Tunnel 0/0/1 **Tunnel0/0/1 current state : UP Line protocol current state : UP** Last line protocol up time : 2020-02-25 17:50:10 UTC-08:00 Description:HUAWEI, AR Series, Tunnel0/0/1 Interface Route Port,The Maximum Transmit Unit is 1500 Internet Address is 123.1.1.1/24 Encapsulation is TUNNEL, loopback not set **Tunnel source 202.1.1.1 (GigabitEthernet0/0/0), destination 101.1.1.1 Tunnel protocol/transport GRE/IP, key disabled keepalive disabled** Checksumming of packets disabled Current system time: 2020-02-25 20:19:16-08:00 300 seconds input rate 0 bits/sec, 0 packets/sec 300 seconds output rate 0 bits/sec, 0 packets/sec 0 seconds input rate 0 bits/sec, 0 packets/sec 0 seconds output rate 0 bits/sec, 0 packets/sec 0 packets input, 0 bytes 0 input error 0 packets output, 0 bytes 0 output error Input bandwidth utilization : -- Output bandwidth utilization : -- <SZ_***>
**BJ_*的檢查
<BJ_***>display interface Tunnel 0/0/1 **Tunnel0/0/1 current state : UP Line protocol current state : UP** Last line protocol up time : 2020-02-25 17:50:53 UTC-08:00 Description:HUAWEI, AR Series, Tunnel0/0/1 Interface Route Port,The Maximum Transmit Unit is 1500 Internet Address is 123.1.1.2/24 Encapsulation is TUNNEL, loopback not set **Tunnel source 101.1.1.1 (GigabitEthernet0/0/0), destination 202.1.1.1 Tunnel protocol/transport GRE/IP, key disabled keepalive disabled** Checksumming of packets disabled Current system time: 2020-02-25 20:21:08-08:00 300 seconds input rate 0 bits/sec, 0 packets/sec 300 seconds output rate 0 bits/sec, 0 packets/sec 0 seconds input rate 0 bits/sec, 0 packets/sec 0 seconds output rate 0 bits/sec, 0 packets/sec 0 packets input, 0 bytes 0 input error 0 packets output, 0 bytes 0 output error Input bandwidth utilization : -- Output bandwidth utilization : -- <BJ_***>
Keepalive檢測功能用於在任意時刻檢測隧道鏈路是否處於Keepalive狀態,即檢測隧道對端是否可達。若是對端不可達,隧道鏈接就會及時關閉,避免造成數據空洞。使能Keepalive檢測功能後,GRE隧道本端會按期向對端發送Keepalive探測報文。若對端可達,則本端會收到對端的迴應報文;若對端不可達,則收不到對端的迴應報文。
若是在隧道一端配置了Keepalive功能,不管對端是否配置Keepalive,配置的Keepalive功能在該端都生效。隧道對端收到Keepalive探測報文,不管是否配置Keepalive,都會給源端發送一個迴應報文。
使能Keepalive檢測功能後,GRE隧道的源端會建立一個計數器,並週期性地發送Keepalive探測報文,同時進行不可達計數。每發送一個探測報文,不可達計數加1
若是源端在計數器值達到預先設置的值以前收到迴應報文,則代表對端可達。若是計數器值達到預先設置的重試次數,源端仍是沒有收到迴應報文,則認爲對端不可達。此時,源端將關閉隧道鏈接。
# interface Tunnel0/0/1 ip address 123.1.1.1 255.255.255.0 tunnel-protocol gre keepalive period 3 ---默認值爲5秒 source 202.1.1.1 destination 101.1.1.1 #
[SZ_***]display interface Tunnel 0/0/1 Tunnel0/0/1 current state : UP Line protocol current state : UP Last line protocol up time : 2020-02-25 17:50:10 UTC-08:00 Description:HUAWEI, AR Series, Tunnel0/0/1 Interface Route Port,The Maximum Transmit Unit is 1500 Internet Address is 123.1.1.1/24 Encapsulation is TUNNEL, loopback not set Tunnel source 202.1.1.1 (GigabitEthernet0/0/0), destination 101.1.1.1 Tunnel protocol/transport GRE/IP, key disabled keepalive enable period 3 retry-times 3 Checksumming of packets disabled Current system time: 2020-02-25 20:36:57-08:00 300 seconds input rate 0 bits/sec, 0 packets/sec 300 seconds output rate 0 bits/sec, 0 packets/sec 0 seconds input rate 0 bits/sec, 0 packets/sec 0 seconds output rate 0 bits/sec, 0 packets/sec 0 packets input, 0 bytes 0 input error 4 packets output, 192 bytes 0 output error Input bandwidth utilization : -- Output bandwidth utilization : --