48

ciscoGRE-适合晋级者-IT杂谈-51CTO博客

 6 years ago
source link: http://blog.51cto.com/tudoubowen10/2067183
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ciscoGRE-适合晋级者

ciscoGRE-适合晋级者

1.配置基础网络环境
(1)配置 R1:
r1(config)#int f0/0
r1(config-if)#ip address 10.1.1.1 255.255.255.0
r1(config-if)#no sh

r1(config)#int F0/1
r1(config-if)#ip add 100.1.1.1 255.255.255.0
r1(config-if)#no sh

r1(config)#ip route 0.0.0.0 0.0.0.0 100.1.1.5
说明:配置 R1 的接口地址,并写默认路由指向 Internet(路由器 R5),地址
100.1.1.5。

(2)配置 R2:
r2(config)#int f0/0
r2(config-if)#ip add 10.1.1.2 255.255.255.0
r2(config-if)#no sh

r2(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.1
说明:配置 R2 的接口地址,并写默认路由指向 R1。

(3)配置 R3:
r3(config)#int f0/0
r3(config-if)#ip add 200.1.1.1 255.255.255.0
r3(config-if)#no sh

r3(config)#int f0/1
r3(config-if)#ip address 192.168.1.3 255.255.255.0
r3(config-if)#no sh

r3(config)#ip route 0.0.0.0 0.0.0.0 200.1.1.5
说明:配置 R3 的接口地址,并写默认路由指向 Internet(路由器 R5),地址
200.1.1.5。

(4)配置 R4:
r4(config)#int f0/1
r4(config-if)#ip add 192.168.1.4 255.255.255.0
r4(config-if)#no sh

r4(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.3
说明:配置 R4 的接口地址,并写默认路由指向 R3。

(5)配置 R5:
r5(config)#int f0/1
r5(config-if)#ip add 100.1.1.5 255.255.255.0
r5(config-if)#no sh

r5(config)#int f0/0
r5(config-if)#ip add 200.1.1.5 255.255.255.0
r5(config-if)#no sh

说明:配置 R5 的接口地址,因为 R5 模拟 Internet,R5 只需要有公网路由 100.1.1.0
和 200.1.1.0 即可,所以 R5 不需要写任何路由,也不允许写任何路由。

2.测试基础网络环境
(1)查看 R5 的路由表:
r5#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B – BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static
route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set

100.0.0.0/24 is subnetted, 1 subnets
C 100.1.1.0 is directly connected, FastEthernet0/1
C 200.1.1.0/24 is directly connected, FastEthernet0/0
r5#
说明:因为 R5 为 Internet 路由器,所以 R5 只有公网路由,没有用户的私网路由,
也不应该有用户的私网路由。

(2)测试上海分公司路由器 R1 到北京分公司路由器 R3 的连通性:
r1#ping 200.1.1.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 200.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 44/106/288 ms
r1#
说明:因为双方路由器都接入 Internet,所以使用公网地址 100.1.1.1 和 200.1.1.1
是可以正常通信的。

(3)测试上海分公司 R2 直接使用私有地址 192.168.1.4 到北京分公司 R4 的连
通性:
r2#ping 192.168.1.4

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.4, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
r2#
说明:因为 Internet 中的路由器只有公网路由,没有用户的私有网段,所以上海
分公司 R2 直接使用私有地址 192.168.1.4 与北京分公司 R4 无法通信。

(4)跟踪上海分公司 R2 到北京分公司的路径信息:
r2#traceroute 192.168.1.4

Type escape sequence to abort.
Tracing the route to 192.168.1.4

1 10.1.1.1 104 msec 100 msec 80 msec
2
3

4
r2#
说明:从结果中可以看出,由于 Internet 没有用户的私有网段,所以数据包出了
公司路由器后,到达 Internet 就被丢弃了。

3.在上海分公司与北京分公司之间配置 GRE 隧道
(1)在上海分公司路由器 R1 上配置连接到北京分公司路由器 R3 的 GRE 隧道:
r1(config)#interface tunnel 1
r1(config-if)#ip address 1.1.1.1 255.255.255.0
r1(config-if)#tunnel source 100.1.1.1
r1(config-if)#tunnel destination 200.1.1.1
r1(config-if)#exit
说明:在 R1 上创建 GRE 虚拟链路(隧道)接口,号码为 1,两端号码可不相同;
隧道接口地址为 1.1.1.1/24,隧道的起源为 100.1.1.1,隧道的终点为 200.1.1.1。

(2)查看 R1 当前的隧道接口状态:
r1#show interfaces tunnel 1
Tunnel1 is up, line protocol is up
Hardware is Tunnel
Internet address is 1.1.1.1/24
MTU 1514 bytes, BW 9 Kbit, DLY 500000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation TUNNEL, loopback not set
Keepalive not set
Tunnel source 100.1.1.1, destination 200.1.1.1
Tunnel protocol/transport GRE/IP
Key disabled, sequencing disabled
Checksumming of packets disabled
Tunnel TTL 255
Fast tunneling enabled
Tunnel transmit bandwidth 8000 (kbps)
Tunnel receive bandwidth 8000 (kbps)
Last input never, output never, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/0 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes, 0 no buffer
Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
0 packets output, 0 bytes, 0 underruns
0 output errors, 0 collisions, 0 interface resets
0 output buffer failures, 0 output buffers swapped out
r1#
说明:可以看出,在 R1 创建 GRE 隧道之后,隧道接口状态便已经 up,这是因为
默认情况下,GRE 隧道接口没有 OSI 一层协议做检测,只要本端源地址有效,并且
隧道终点地址有路由可达,那么 GRE 隧道接口就会 up,而无论隧道对端是否已经配
置隧道接口。

(3)在北京分公司路由器 R3 上配置连接到上海分公司路由器 R1 的 GRE 隧道:
r3(config)#interface tunnel 3
r3(config-if)#ip address 1.1.1.2 255.255.255.0
r3(config-if)#tunnel source 200.1.1.1
r3(config-if)#tunnel destination 100.1.1.1
r3(config-if)#exit
说明:在 R3 上创建 GRE 虚拟链路(隧道)接口,号码为 3,两端号码可不相同;
隧道接口地址为 1.1.1.2/24,隧道的起源为 200.1.1.1,隧道的终点为 100.1.1.1。

(4)查看 R3 当前的隧道接口状态:

r3#show interfaces tunnel 3
Tunnel3 is up, line protocol is up
Hardware is Tunnel
Internet address is 1.1.1.2/24
MTU 1514 bytes, BW 9 Kbit, DLY 500000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation TUNNEL, loopback not set
Keepalive not set
Tunnel source 200.1.1.1, destination 100.1.1.1
Tunnel protocol/transport GRE/IP
Key disabled, sequencing disabled
Checksumming of packets disabled
Tunnel TTL 255
Fast tunneling enabled
Tunnel transmit bandwidth 8000 (kbps)
Tunnel receive bandwidth 8000 (kbps)
Last input never, output never, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/0 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes, 0 no buffer
Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
0 packets output, 0 bytes, 0 underruns
0 output errors, 0 collisions, 0 interface resets
0 output buffer failures, 0 output buffers swapped out
r3#
说明:R3 上 GRE 隧道状态也已经 up。

4.测试 GRE 隧道
(1)测试 R1 与 R3 之间的 GRE 隧道连通性:
r1#ping 1.1.1.2

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/96/196 ms
r1#
说明:因为 R1 与 R3 双方 GRE 隧道已经成功建立,并且状态都为 up,所以隧道
连通性正常。

(2)再次测试上海分公司 R2 直接使用私有地址 192.168.1.4 到北京分公司 R4
的连通性:
r2#ping 192.168.1.4

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.4, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
r2#
说明:上海分公司的路由器 R1 在收到去往 192.168.1.4 后,因为默认路由从真实
接口 F0/1 出去,结果数据包被发到 Internet 中的路由器 R5,由于 Internet 路由器 R5
只有公网路由,没有用户的私有网段,所以上海分公司 R2 直接使用私有地址
192.168.1.4 与北京分公司 R4 无法通信,如下是 R1 路由表:

r1#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static
route
o - ODR, P - periodic downloaded static route

Gateway of last resort is 100.1.1.5 to network 0.0.0.0

1.0.0.0/24 is subnetted, 1 subnets
C 1.1.1.0 is directly connected, Tunnel1
100.0.0.0/24 is subnetted, 1 subnets
C 100.1.1.0 is directly connected, FastEthernet0/1
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/0
S* 0.0.0.0/0 [1/0] via 100.1.1.5
r1#

要解决此问题,必须让流量从 GRE 隧道中传输。

(3)在创建 GRE 隧道的路由器双方将去往对方私有网段的数据包引入 GRE 隧
道中传输:

R1:
r1(config)#ip route 192.168.1.0 255.255.255.0 tunnel 1

R3:
r3(config)#ip route 10.1.1.0 255.255.255.0 tunnel 3

(4)再次测试上海分公司 R2 直接使用私有地址 192.168.1.4 到北京分公司 R4
的连通性:

r2#ping 192.168.1.4

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 24/80/240 ms
r2#
说明:上海分公司的路由器 R1 在收到去往 192.168.1.4 后,因为路由 192.168.1.0
已经指向 GRE 隧道,对方同样也已经回指向 GRE 隧道,所以上海分公司 R2 直接使
用私有地址 192.168.1.4 与北京分公司 R4 通信正常。

(5)再次跟踪上海分公司 R2 到北京分公司的路径信息:
r2#traceroute 192.168.1.4

Type escape sequence to abort.
Tracing the route to 192.168.1.4

1 10.1.1.1 108 msec 52 msec 16 msec
2 1.1.1.2 112 msec 48 msec 12 msec
3 192.168.1.4 132 msec * 96 msec

r2#
说明:可以看见,上海与北京分公司私有网段之间的流量已经在隧道中传输,所
以通信正常。

补充:理解×××的原理,就好比你和别人联机打游戏一样,你们都要用运营商网络,但是你要联机的玩家是需要你们自己定义一个房间他输入正确的房间密码才可以进房间和你对话,基本原理就是这样(房间密码适用于IPsec)。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK