14.3 GRE协议基础配置

原理概述

        GRE(Generic Routing Encapsulation,通用路由封装协议)提供了将一种协议的报文封装在另一种协议报文中的机制,使报文能够在异种网络(如IPv4网络)中传输,而异种报文传输的通道称为Tunnel。

        GRE协议也可以作为VPN的第三层隧道(Tunnel)协议,为VPN数据提供透明传输隧道。Tunnel是一个虚拟的点对点连接,可以看出仅支持点对点连接的虚拟接口,这个接口提供了一条通路,使封装的数据报能够在这个通路上传输,并在一个Tunnel的两端分别对数据报进行封装及解封装。

实验目的

  •         理解GRE协议的使用场景
  •         掌握配置GRE隧道的方法
  •         掌握配置基于GRE接口的动态路由协议的方法

实验内容

        本实验模拟企业网络场景。R1为企业总部的网关设备,并且内部有一台服务器,R3连接这企业分公司的网关设备,R2为公网ISP设备。一般情况下,运营商只会维护自身的公网路由信息,而不会维护企业内部私网的路由信息,即运营商设备上的路由表中不会出现任何企业内部私网的路由条目。通过配置GRE实现公司总部和分部间私网路由信息的透传即数据通信。

实验编址

设备接口  IP地址子网掩码默认网关
serverEthernet0/0/0192.168.10.10255.255.255.0192.168.10.1
R1GE 0/0/0192.168.10.1 255.255.255.0N/A
Serial 1/0/010.1.12.1255.255.255.0N/A
R2Serial 1/0/010.1.12.2255.255.255.0N/A
Serial 1/0/110.1.23.2255.255.255.0N/A
R3Serial 1/0/010.1.23.1255.255.255.0N/A
GE0/0/0192.68.20.1255.255.255.0N/A
PCEthernet 0/0/1192.168.20.20255.255.255.0192.168.20.1

实验拓扑

实验步骤

1.基本配置

        根据实验编址进行相应的基本配置,并检测各直连链路的连通性。在R1和R3上分别配置访问公网路由器R2的默认路由。

        [R1]ip route-static 0.0.0.0 0.0.0.0 10.1.12.2

        [R3]ip route-static 0.0.0.0 0.0.0.0 10.1.23.2

        配置完成后,在PC上测试与总部服务器的连通性。

        PC>ping 192.168.10.10

        Ping 192.168.10.10: 32 data bytes, Press Ctrl_C to break
        Request timeout!
        Request timeout!
        Request timeout!
        Request timeout!
        Request timeout!

        可以看到,跨越了互联网的两个私网网段之间默认是无法直接通信的。此时可以通过GRE协议来实现通信。

2.配置GRE Tunnel

        在路由器R1和R3上配置GRE Tunnel,使用 interface tunnel命令创建隧道端口,指定隧道模式为GRE。配置R1 Tunnel接口的源地址为其S1/0/0接口IP地址,目的地址为R3的S1/0/0接口IP地址;配置R3 Tunnel接口源地址为其S1/0/0接口IP地址,目的地之为R1S1/0/0接口IP地址。还要用ip address 命令配置Tunnel接口的IP地址,注意要在同一网段。

        [R1]int tun 0/0/0
        [R1-Tunnel0/0/0]tunnel-protocol gre
        [R1-Tunnel0/0/0]source 10.1.12.1 
        [R1-Tunnel0/0/0]destination 10.1.23.1
        [R1-Tunnel0/0/0]ip add 172.16.1.1 24

        [R3]int tun 0/0/0
        [R3-Tunnel0/0/0]tunnel-protocol gre
        [R3-Tunnel0/0/0]source 10.1.23.1
        [R3-Tunnel0/0/0]destination 10.1.12.1
        [R3-Tunnel0/0/0]ip add 172.16.1.2 24

        配置完成后,在R1上测试本端隧道接口地址与目的端隧道接口地址的连通性。

        <R1>ping -a 172.16.1.1 172.16.1.2
          PING 172.16.1.2: 56  data bytes, press CTRL_C to break
            Reply from 172.16.1.2: bytes=56 Sequence=1 ttl=255 time=40 ms
            Reply from 172.16.1.2: bytes=56 Sequence=2 ttl=255 time=30 ms
            Reply from 172.16.1.2: bytes=56 Sequence=3 ttl=255 time=30 ms
            Reply from 172.16.1.2: bytes=56 Sequence=4 ttl=255 time=30 ms
            Reply from 172.16.1.2: bytes=56 Sequence=5 ttl=255 time=40 ms

        可以观察到,通信正常。

        在R1和R3分别执行display interface tunnel 命令查看隧道接口状态。

        <R1>dis int tun
        Tunnel0/0/0 current state : UP
        Line protocol current state : UP
        Last line protocol up time : 2021-11-30 22:36:15 UTC-08:00
        Description:
        Route Port,The Maximum Transmit Unit is 1500
        Internet Address is 172.16.1.1/24
        Encapsulation is TUNNEL, loopback not set
        Tunnel source 10.1.12.1 (Serial1/0/0), destination 10.1.23.1
        Tunnel protocol/transport GRE/IP, key disabled
        keepalive disabled
 

        <R3>dis int tun
        Tunnel0/0/0 current state : UP
        Line protocol current state : UP
        Last line protocol up time : 2021-11-30 22:35:46 UTC-08:00
        Description:
        Route Port,The Maximum Transmit Unit is 1500
        Internet Address is 172.16.1.2/24
        Encapsulation is TUNNEL, loopback not set
        Tunnel source 10.1.23.1 (Serial1/0/0), destination 10.1.12.1
        Tunnel protocol/transport GRE/IP, key disabled
        keepalive disabled

        可以观察到,当前隧道接口的物理层状态为正常启动状态,链路层状态为正常运行状态,隧道封装协议为GRE协议。。。

        在R1和R3上执行 display ip routing-table 命令查看路由表。        

        <R1>dis ip routing-table 
        Route Flags: R - relay, D - download to fib
        ------------------------------------------------------------------------------
        Routing Tables: Public
                 Destinations : 15       Routes : 15       

        Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

                0.0.0.0/0   Static  60   0          RD   10.1.12.2       Serial1/0/0
              10.1.12.0/24  Direct  0    0           D   10.1.12.1       Serial1/0/0
              10.1.12.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              10.1.12.2/32  Direct  0    0           D   10.1.12.2       Serial1/0/0
            10.1.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
              127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
             172.16.1.0/24  Direct  0    0           D   172.16.1.1      Tunnel0/0/0
             172.16.1.1/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           172.16.1.255/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           192.168.10.0/24  Direct  0    0           D   192.168.10.1    GigabitEthernet0/0/0
           192.168.10.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
         192.168.10.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
        255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

        <R3>dis ip routing-table 
        Route Flags: R - relay, D - download to fib
        ------------------------------------------------------------------------------
        Routing Tables: Public
                Destinations : 15       Routes : 15       

        Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

                0.0.0.0/0   Static  60   0          RD   10.1.23.2       Serial1/0/0
              10.1.23.0/24  Direct  0    0           D   10.1.23.1       Serial1/0/0
              10.1.23.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              10.1.23.2/32  Direct  0    0           D   10.1.23.2       Serial1/0/0
            10.1.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
              127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
             172.16.1.0/24  Direct  0    0           D   172.16.1.2      Tunnel0/0/0
             172.16.1.2/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           172.16.1.255/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           192.168.20.0/24  Direct  0    0           D   192.168.20.1    GigabitEthernet0/0/0
           192.168.20.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
         192.168.20.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
        255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        可以观察到,R1和R3的路由表有所配隧道接口的路由条目。即R1和R3间已经形成了类似点到点直连的逻辑链路,但没有接到对方的私网路由信息。

3.配置基于GRE接口的动态路由协议

        经过上面步骤,R1和R3之间的GRE隧道已经建立,测试分部PC与总部服务器之间的连通性。     

        PC>ping 192.168.10.10

        Ping 192.168.10.10: 32 data bytes, Press Ctrl_C to break
        Request timeout!
        Request timeout!
        Request timeout!
        Request timeout!
        Request timeout!

        仍然无法正常通信。原因是目前还没有配置基于GRE隧道接口的路由协议。GRE协议支持组播数据传输,因此可以支持一些动态路由协议的运行,动态路由协议通过GRE协议形成的逻辑隧道在R1和R3间传递路由信息。

        在R1和R3上配置OSPF协议,通告相应的私网网段和Tunnel接口所在的网络。

        [R1]ospf 1
        [R1-ospf-1]area 0
        [R1-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
        [R1-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.255

        [R3]ospf 1
        [R3-ospf-1]area 0
        [R3-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
        [R3-ospf-1-area-0.0.0.0]network 172.16.1.0 0.0.0.255

        在R1和R3上查看OSPF邻居

        <R1>dis ospf peer

             OSPF Process 1 with Router ID 192.168.10.1
                 Neighbors 

         Area 0.0.0.0 interface 172.16.1.1(Tunnel0/0/0)'s neighbors
         Router ID: 10.1.23.1        Address: 172.16.1.2      
           State: Full  Mode:Nbr is  Slave  Priority: 1
           DR: None   BDR: None   MTU: 0    
           Dead timer due in 35  sec 
           Retrans timer interval: 5 
           Neighbor is up for 00:01:57     
           Authentication Sequence: [ 0 ] 

        <R3>dis ospf peer

             OSPF Process 1 with Router ID 10.1.23.1
                 Neighbors 

         Area 0.0.0.0 interface 172.16.1.2(Tunnel0/0/0)'s neighbors
         Router ID: 192.168.10.1     Address: 172.16.1.1      
          State: Full  Mode:Nbr is  Master  Priority: 1
           DR: None   BDR: None   MTU: 0    
           Dead timer due in 30  sec 
           Retrans timer interval: 5 
           Neighbor is up for 00:00:39     
           Authentication Sequence: [ 0 ] 

        可以观察到,此时双发已经通过隧道接口建立了OSPF邻居关系。

        查看R1和R3的路由表。

        <R1>dis ip routing-table 
        Route Flags: R - relay, D - download to fib
        ------------------------------------------------------------------------------
        Routing Tables: Public
                 Destinations : 16       Routes : 16       

        Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

                0.0.0.0/0   Static  60   0          RD   10.1.12.2       Serial1/0/0
              10.1.12.0/24  Direct  0    0           D   10.1.12.1       Serial1/0/0
              10.1.12.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              10.1.12.2/32  Direct  0    0           D   10.1.12.2       Serial1/0/0
            10.1.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
              127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
             172.16.1.0/24  Direct  0    0           D   172.16.1.1      Tunnel0/0/0
             172.16.1.1/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           172.16.1.255/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           192.168.10.0/24  Direct  0    0           D   192.168.10.1    GigabitEthernet0/0/0
           192.168.10.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
         192.168.10.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
           192.168.20.0/24  OSPF    10   1563        D   172.16.1.2      Tunnel0/0/0
        255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

        

        <R3>dis ip routing-table 
        Route Flags: R - relay, D - download to fib
        ------------------------------------------------------------------------------
        Routing Tables: Public
                 Destinations : 16       Routes : 16       

        Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

                0.0.0.0/0   Static  60   0          RD   10.1.23.2       Serial1/0/0
              10.1.23.0/24  Direct  0    0           D   10.1.23.1       Serial1/0/0
              10.1.23.1/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              10.1.23.2/32  Direct  0    0           D   10.1.23.2       Serial1/0/0
            10.1.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
              127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
             172.16.1.0/24  Direct  0    0           D   172.16.1.2      Tunnel0/0/0
             172.16.1.2/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           172.16.1.255/32  Direct  0    0           D   127.0.0.1       Tunnel0/0/0
           192.168.10.0/24  OSPF    10   1563        D   172.16.1.1      Tunnel0/0/0
           192.168.20.0/24  Direct  0    0           D   192.168.20.1    GigabitEthernet0/0/0
           192.168.20.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
         192.168.20.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
        255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

        可以观察到,双方都能接收到各自内部私有网络发送过来的路由更新。

        在分公司PC上测试与总公司server之间的连通性。

        PC>ping 192.168.10.10

        Ping 192.168.10.10: 32 data bytes, Press Ctrl_C to break
        From 192.168.10.10: bytes=32 seq=1 ttl=253 time=15 ms
        From 192.168.10.10: bytes=32 seq=2 ttl=253 time=47 ms
        From 192.168.10.10: bytes=32 seq=3 ttl=253 time=16 ms
        From 192.168.10.10: bytes=32 seq=4 ttl=253 time=31 ms
        From 192.168.10.10: bytes=32 seq=5 ttl=253 time=47 ms

        可以观察到,通信正常。查看路由器R2的路由表。

        <R2>dis ip routing-table 
        Route Flags: R - relay, D - download to fib
        ------------------------------------------------------------------------------
        Routing Tables: Public
                 Destinations : 12       Routes : 12       

        Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

              10.1.12.0/24  Direct  0    0           D   10.1.12.2       Serial1/0/0
              10.1.12.1/32  Direct  0    0           D   10.1.12.1       Serial1/0/0
              10.1.12.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
            10.1.12.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/0
              10.1.23.0/24  Direct  0    0           D   10.1.23.2       Serial1/0/1
              10.1.23.1/32  Direct  0    0           D   10.1.23.1       Serial1/0/1
              10.1.23.2/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
            10.1.23.255/32  Direct  0    0           D   127.0.0.1       Serial1/0/1
              127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
              127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
        255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

        可以看到,R2上没有任何R1和R3各自私网网段的路由信息。说明通过GRE协议建立起来的隧道,能够跨公网传递各个内部私有网络的路由信息,实现了两个私有网络间的跨公网通信。

说明

        对于一个GRE隧道接口是否处于UP状态,仅取决于本端设备物理接口是否正常开启、隧道源、目的地址是否配置以及隧道接口是否配置了IP地址,需要强调的是设备并不会检测对端隧道点地址是否真正可达,而只判断本地路由表中是否存在到达对端隧道端点地址的路由(含默认路由)。为此,GRE引入了Keepalive机制以定期检测对端隧道端点的可达性,避免路由转发黑洞问题。

        

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值