实验拓扑
实验要求
通过学习GRE隧道的原理和配置,从而掌握GRE隧道的特点和使用。
本次实验由三台路由器完成,其中R1和R3上存在环回接口,其IP地址分别为1.1.1.1和3.3.3.3并且R1和,R2和R3之间运行EIGRP路由协议,但是不将环回口加入EIGRP进程中。也就是说在R1上使用1.1.1.1去ping3.3.3.3无法通信。
实验配置
配置好R1,R2以及R3上的相关接口IP地址。并且配置好EIGRP路由协议。使得R1能够学习到10.10.23.0/24的路由,R3能够学习到10.10.12.0/2 的路由。查看R1和R3的路由表,如下:
R1:
R1#configure terminal
R1(config)#interface e0/0
R1(config-if)#ip add 10.10.12.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#int loo0
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#no sh
R1(config)#router eigrp 1
R1(config-router)#no au
R1(config-router)#net 10.10.12.0
R2:
R2#configure terminal
R2(config)#interface e0/1
R2(config-if)#ip add 10.10.12.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int e0/0
R2(config-if)#ip add 10.10.23.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#int loo0
R2(config-if)#ip add 2.2.2.2 255.255.255.0
R2(config-if)#no sh
R2(config)#router eigrp 1
R2(config-router)#no au
R2(config-router)#net 10.10.12.0
R2(config-router)#net 10.10.23.0
R3;
R3#configure terminal
R3(config)#int e0/1
R3(config-if)#ip add 10.10.23.3 255.255.255.0
R3(config-if)#no sh
R3(config-if)#int loo0
R3(config-if)#ip add 3.3.3.3 255.255.255.0
R3(config-if)#no sh
R3(config)#router eigrp 1
R3(config-router)#no au
R3(config-router)#net 10.10.23.0
- 现在,要求R1的1.1.1.1 和 R3的3.3.3.3 通过GRE隧道相互通信。则需要在R1和R3之间配置GRE隧道。
GRE隧道(通过路由封装)协议能够封装多种协议的数据包,因此功能强大,能够将需要的内容封装进入不支持该内容的网络区域传递出去。
并且GRE隧道为单向的,因此一条正确的GRE隧道是需要在起始端点上都需要配置的。
首先在R1上配置到R3d1GRE隧道。
R1:
R1(config)#int tunnel 13
R1(config-if)#
*Mar 1 00:39:23.227: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel13, changed state to up //当隧道的源IP地址的目的IP地址之间能够相互通信的话,那么该隧道便能够up起来
R1(config-if)#tunnel source 10.10.12.1 //隧道IP源地址
R1(config-if)#tunnel mode gre ip //隧道模式为GRE模式
R1(config-if)#ip add 10.10.13.1 255.255.255.0 //为隧道配置为一个IP地址,使得隧道两端逻辑上直连
>同样的在R3上也配置一条GRE隧道指向R1
R3:
R3(config)#int tunnel 13
R3(config-if)#tunnel source 10.10.12.1
R3(config-if)#tunnel destination 10.10.23.3
R3(config-if)#
*Mar 1 00:41:46.247: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel13, changed state to up
R3(config-if)#tunnel mode gre ip
R3(config-if)#ip add 10.10.13.1 255.255.255.0
然后,我们在R1和R3上分别建立去往3.3.3.3和1.1.1.1上的静态路由。
R1(config)#ip route 3.3.3.0 255.255.255.0 tunnel 13
R3(config)#ip route 1.1.1.0 255.255.255.0 tunnel 13
最后验证,在R1上ping3.3.3.3,并且以1.1.1.1为源IP地址。
实验总结
那么总结本实验GRE隧道的实际操作步骤。当R1想要发给3.3.3.3地址数据包时,根据本地静态路由,该数据包将被发往隧道13中,而隧道13为GRE,因此原始的ICMP ping包被封装进入GRE包中,外层还有一层IP包头,其源IP地址为10.10.13.1,目的IP地址为10.10.13.3。这个数据包从R1的e0/0为源起发往R3的e0/1.当R3收到该GRE隧道包后,拆包,获取了内部原始ICMP ping 包,发给环回口3.3.3.3.这样就能够相互ping通了。