配置GRE实现IPv4网络互通

静态路由方式

组网需求

配置步骤

配置网络接口

#############SwitchA##########################

SwitchA(config)# interface eth-0-1

SwitchA(config-if)# no switchport

SwitchA(config-if)# ip address 192.168.1.1/24

SwitchA(config-if)# exit

SwitchA(config)# interface eth-0-23

SwitchA(config-if)# no switchport

SwitchA(config-if)# ip address 10.1.1.1/24

SwitchA(config-if)# exit

SwitchA(config)#

#############SwitchB##########################

SwitchB(config)# interface eth-0-23

SwitchB(config-if)# no switchport

SwitchB(config-if)# ip address 10.1.1.2/24

SwitchB(config-if)# exit

SwitchB(config)# interface eth-0-24

SwitchB(config-if)# no switchport

SwitchB(config-if)# ip address 10.1.2.2/24

SwitchB(config-if)# exit

SwitchB(config)#

#############SwitchC##########################

SwitchC(config)# interface eth-0-24

SwitchC(config-if)# no switchport

SwitchC(config-if)# ip address 10.1.2.3/24

SwitchC(config-if)# exit

SwitchC(config)# interface eth-0-1

SwitchC(config-if)# no switchport

SwitchC(config-if)# ip address 192.168.2.1/24

SwitchC(config-if)# exit

SwitchC(config)#

配置静态路由,使隧道传输网络可达

#############SwitchA##########################

SwitchA(config)# ip route 10.1.2.0/24 10.1.1.2

SwitchA(config)#

#############SwitchC##########################

SwitchC(config)# ip route 10.1.1.0/24 10.1.2.2

SwitchC(config)#

配置GRE Tunnel

#############SwitchA##########################

SwitchA(config)# interface eth-0-23

SwitchA(config-if)# tunnel enable

SwitchA(config-if)# exit

SwitchA(config)# interface tunnel 1

SwitchA(config-if)# tunnel mode gre

SwitchA(config-if)# tunnel source eth-0-23

SwitchA(config-if)# tunnel destination 10.1.2.3

SwitchA(config-if)# keepalive 5 3

SwitchA(config-if)# ip address 192.168.168.1/24

SwitchA(config-if)# exit

#############SwitchC##########################

SwitchC(config)# interface eth-0-24

SwitchC(config-if)# tunnel enable

SwitchC(config-if)# exit

SwitchC(config)# interface tunnel 1

SwitchC(config-if)# tunnel mode gre

SwitchC(config-if)# tunnel source eth-0-24

SwitchC(config-if)# tunnel destination 10.1.1.1

SwitchC(config-if)# keepalive 5 3

SwitchC(config-if)# ip address 192.168.168.2/24

SwitchC(config-if)# exit

配置GRE隧道路由

#############SwitchA##########################

SwitchA(config)# ip route 192.168.2.0/24 tunnel1

#############SwitchC##########################

SwitchC(config)# ip route 192.168.1.0/24 tunnel1

结果验证

查看Tunnel状态

SwitchA# show interface tunnel 1

Interface tunnel1

Interface current state: UP

Hardware is Tunnel

Index 8193 , Metric 1 , Encapsulation TUNNEL

VRF binding: not bound

Internet primary address:

192.168.168.1/24 pointopoint 192.168.168.255

Tunnel protocol/transport GRE/IP, Status Valid

Tunnel source 10.1.1.1(eth-0-23)

Tunnel destination 10.1.2.3

Tunnel DSCP inherit,  Tunnel TTL 254

Tunnel GRE key disable

Tunnel GRE keepalive enable, Send period: 5, Retry times: 3

11882 packets input, 1253396 bytes

17259 packets output, 1734436 bytes

SwitchA#

验证隧道可达

SwitchA# ping -a 192.168.168.1 192.168.168.2

PING 192.168.168.2 (192.168.168.2) from 192.168.168.1 : 56(84) bytes of data.

64 bytes from 192.168.168.2: icmp_seq=1 ttl=64 time=1.87 ms

64 bytes from 192.168.168.2: icmp_seq=2 ttl=64 time=1.61 ms

64 bytes from 192.168.168.2: icmp_seq=3 ttl=64 time=1.59 ms

64 bytes from 192.168.168.2: icmp_seq=4 ttl=64 time=1.52 ms

64 bytes from 192.168.168.2: icmp_seq=5 ttl=64 time=1.65 ms

 

— 192.168.168.2 ping statistics —

5 packets transmitted, 5 received, 0% packet loss, time 4006ms

rtt min/avg/max/mdev = 1.524/1.653/1.872/0.120 ms

SwitchA#

网络互通

此时从PC1 ping PC2能够互通,测试过程略