GRE技術的講解---第一篇(可跟做)

通用路由封裝協議GRE(Generic Routing Encapsulation)提供了將一種協議的報文封裝在另一種協議報文中的機制,是一種隧道封裝技術。GRE可以封裝組播數據,並可以和IPSec結合使用,從而保證語音、視頻等組播業務的安全
 IPSec 用於在兩個端點之間提供安全的IP通信,但只能加密並傳播單播數據,無法加密和傳輸語音、視頻、動態路由協議信息等組播數據流量
 GRE屬於網絡層協議 IP協議號爲47
GRE技術的講解---第一篇(可跟做)
GRE的優點總結:
 GRE實現機制簡單,對隧道兩端的設備負擔小
 GRE隧道可以通過IPv4網絡連通多種網絡協議的本地網絡,有效利用了原有的網絡架構,降低成本
 GRE隧道擴展了跳數受限網絡協議的工作範圍,支持企業靈活設計網絡拓撲
 GRE隧道可以封裝組播數據,和IPSec結合使用時可以保證語音、視頻等組播業務的安全
 GRE隧道支持使能MPLS LDP,使用GRE隧道承載MPLS LDP報文,建立LDP LSP,實現MPLS骨幹網的互通
 GRE隧道將不連續的子網連接起來,用於組建
,實現企業總部和分支間安全的連接

GRE的應用場景

 GRE用來對某些網絡層協議如IPX(Internet Packet Exchange)的報文進行封裝,使這些被封裝的報文能夠在另一網絡層協議(如IP)中傳輸。GRE可以解決異種網絡的傳輸問題
GRE技術的講解---第一篇(可跟做)
使用GRE可以克服IGP協議的一些侷限性。例如,RIP路由協議是一種距離矢量路由協議,最大跳數爲15。如果網絡直徑超過15,設備將無法通信。這種情況下,可以使用GRE技術在兩個網絡節點之間搭建隧道,隱藏它們之間的跳數,擴大網絡的工作範圍
GRE技術的講解---第一篇(可跟做)
GRE和IPSEC技術的結合 GRE本身並不支持加密,因而通過GRE隧道傳輸的流量是不加密的。將IPSec技術與GRE相結合,可以先建立GRE隧道對報文進行GRE封裝,然後再建立IPSec隧道對報文進行加密,以保證報文傳輸的完整性和私密性
GRE技術的講解---第一篇(可跟做)

隧道接口

 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

GRE的報文

乘客協議(Passenger Protocol):封裝前的報文稱爲淨荷,封裝前的報文協議稱爲乘客協議
封裝協議(Encapsulation Protocol):GRE Header是由封裝協議完成並填充的,封裝協議也稱爲運載協議(Carrier Protocol)
傳輸協議(Transport Protocol或者Delivery Protocol):負責對封裝後的報文進行轉發的協議稱爲傳輸協議
GRE技術的講解---第一篇(可跟做)
GRE報文重要字段解釋:

Protocol Type       標識乘客協議的協議類型。常見的乘客協議爲IPv4協議,協議代碼爲0800
Key             關鍵字字段,隧道接收端用於對收到的報文進行驗證 Tunnel兩端的key一定要一樣

比如:
乘客協議爲IP或IPX協議 封裝協議爲GRE協議 傳輸協議爲IP協議
GRE技術的講解---第一篇(可跟做)
GRE技術的講解---第一篇(可跟做)
GRE技術的講解---第一篇(可跟做)

GRE的工作原理

 需求:運行IP協議的兩個子網網絡1和網絡2 通過在SZ***和BJ***之間使用三層隧道協議GRE實現互聯
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接口發出去

GRE的配置

GRE技術的講解---第一篇(可跟做)

第一步:基本配置

**SZ_*路由器的配置

#
 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***和BJ***啓動TUNNEL接口

**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
#

第四步:檢查GRE隧道是否成功

**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_***>

GRE的Keepalive檢測功能

 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 : --
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章