GRE简单配置命令
实验拓扑:
要求:
R1,R3为私网路由器,R2为运营商公网。即R2上不写任何路由,R1、R3上也不能直接写到R2的路由(缺省)。
R1和R3通过GRE搭建虚拟专线组成内网,要求R1的环回可直接ping通R3环回。
配置IP
R1
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip add 22.1.1.1 24
[R1-GigabitEthernet0/0/0]q
[R1]interface l0
[R1-LoopBack0]ip add 192.168.1.1 24
[R1-LoopBack0]q
[R1]ip route-static 0.0.0.0 0 22.1.1.2
R2
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 22.1.1.2 24
[R2-GigabitEthernet0/0/0]q
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 23.1.1.1 24
[R2-GigabitEthernet0/0/1]q
[R2]int l0
[R2-LoopBack0]ip add 1.1.1.1 24
R3
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 23.1.1.2 24
[R3-GigabitEthernet0/0/0]q
[R3]int l0
[R3-LoopBack0]ip add 192.168.2.1 24
[R3-LoopBack0]q
[R3]ip route-static 0.0.0.0 0 23.1.1.1
配置GRE
R1
[R1]interface Tunnel 0/0/0 创建通道接口
[R1-Tunnel0/0/0]ip add 10.1.1.1 24 配置ip地址
[R1-Tunnel0/0/0]tunnel-protocol gre 定义封装方式为gre
[R1-Tunnel0/0/0]source 22.1.1.1 封装的源ip
[R1-Tunnel0/0/0]destination 23.1.1.2 封装的目标ip
R3
[R3]interface tunnel0/0/0
[R3-Tunnel0/0/0]ip add 10.1.1.2 24
[R3-Tunnel0/0/0]tunnel-protocol gre
[R3-Tunnel0/0/0]source 23.1.1.2
[R3-Tunnel0/0/0]destination 22.1.1.1
测试:
[R1]ping 10.1.1.2
PING 10.1.1.2: 56 data bytes, press CTRL_C to break
Reply from 10.1.1.2: bytes=56 Sequence=1 ttl=255 time=40 ms
Reply from 10.1.1.2: bytes=56 Sequence=2 ttl=255 time=30 ms
Reply from 10.1.1.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 10.1.1.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 10.1.1.2: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 10.1.1.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/30/40 ms
配置静态路由,测试R1和R3之间通过GRE搭建的虚拟专线是否连通。
[R1]ip route-static 192.168.2.0 24 10.1.1.2
[R3]ip route-static 192.168.1.0 24 10.1.1.1
[R3]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=255 time=40 ms
Reply from 192.168.1.1: bytes=56 Sequence=2 ttl=255 time=30 ms
Reply from 192.168.1.1: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 192.168.1.1: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 192.168.1.1: bytes=56 Sequence=5 ttl=255 time=30 ms
--- 192.168.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/32/40 ms
抓包查看
可以看到封装了两个IPv4地址,第一个为公网ip,第二个为搭建的虚拟连接ip。如图: