不同网段之间进行通信,中间有多个路由器的情况下,我们可以通过配置RIP
动态路由来实现数据转发。
实验拓扑
如图所示连接,地址规划如下:
名称 | 接口 | IP地址 |
---|---|---|
R1 | f0/0 | 192.168.10.1/24 |
R1 | f0/1 | 192.168.20.1/30 |
R2 | f0/0 | 192.168.20.2/30 |
R2 | f0/1 | 192.168.30.1/30 |
R3 | f0/0 | 192.168.30.2/30 |
R3 | f0/1 | 192.168.40.1/24 |
PC1 | e0 | 192.168.10.2/24 |
PC2 | e0 | 192.168.40.2/24 |
配置方法
R1(config)#router rip
R1(config-router)#network 192.168.10.0
R1(config-router)#network 192.168.20.0
R1(config-router)#version 2
R1(config-router)#no auto-summary
R1(config-router)#ex
配置过程
配置 IP 地址
- R1
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#int f0/0
R1(config-if)#ip add 192.168.10.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#ex
R1(config)#int f0/1
R1(config-if)#ip add 192.168.20.1 255.255.255.252
R1(config-if)#no sh
R1(config-if)#ex
R1(config)#do show 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
C 192.168.10.0/24 is directly connected, FastEthernet0/0
192.168.20.0/30 is subnetted, 1 subnets
C 192.168.20.0 is directly connected, FastEthernet0/1
- R2
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#int f0/0
R2(config-if)#ip add 192.168.20.2 255.255.255.252
R2(config-if)#no sh
R2(config-if)#ex
R2(config)#int f0/1
R2(config-if)#ip add 192.168.30.1 255.255.255.252
R2(config-if)#no sh
R2(config-if)#ex
R2(config)#do show 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
192.168.30.0/30 is subnetted, 1 subnets
C 192.168.30.0 is directly connected, FastEthernet0/1
192.168.20.0/30 is subnetted, 1 subnets
C 192.168.20.0 is directly connected, FastEthernet0/0
- R3
R3#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#int f0/0
R3(config-if)#ip add 192.168.30.2 255.255.255.252
R3(config-if)#no sh
R3(config-if)#ex
R3(config)#int f0/1
R3(config-if)#ip add 192.168.40.1 255.255.255.0
R3(config-if)#no sh
R3(config-if)#ex
R3(config)#do show 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
192.168.30.0/30 is subnetted, 1 subnets
C 192.168.30.0 is directly connected, FastEthernet0/0
C 192.168.40.0/24 is directly connected, FastEthernet0/1
- PC1
PC1> ip 192.168.10.2 192.168.10.1
Checking for duplicate address...
PC1 : 192.168.10.2 255.255.255.0 gateway 192.168.10.1
- PC2
PC2> ip 192.168.40.2 192.168.40.1
Checking for duplicate address...
PC1 : 192.168.40.2 255.255.255.0 gateway 192.168.40.1
默认不可互通
PC1> ping 192.168.40.2
*192.168.10.1 icmp_seq=1 ttl=255 time=18.978 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.1 icmp_seq=2 ttl=255 time=12.061 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.1 icmp_seq=3 ttl=255 time=6.137 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.1 icmp_seq=4 ttl=255 time=7.963 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.10.1 icmp_seq=5 ttl=255 time=7.970 ms (ICMP type:3, code:1, Destination host unreachable)
PC2> ping 192.168.10.2
*192.168.40.1 icmp_seq=1 ttl=255 time=10.004 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.40.1 icmp_seq=2 ttl=255 time=6.786 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.40.1 icmp_seq=3 ttl=255 time=7.979 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.40.1 icmp_seq=4 ttl=255 time=10.064 ms (ICMP type:3, code:1, Destination host unreachable)
*192.168.40.1 icmp_seq=5 ttl=255 time=10.939 ms (ICMP type:3, code:1, Destination host unreachable)
配置 RIP
- R1
R1(config)#router rip
R1(config-router)#network 192.168.10.0
R1(config-router)#network 192.168.20.0
R1(config-router)#version 2
R1(config-router)#no auto-summary
R1(config-router)#ex
- R2
R2(config)#router rip
R2(config-router)#network 192.168.20.0
R2(config-router)#network 192.168.30.0
R2(config-router)#version 2
R2(config-router)#no auto-summary
R2(config-router)#ex
- R3
R3(config)#router rip
R3(config-router)#network 192.168.30.0
R3(config-router)#network 192.168.40.0
R3(config-router)#version 2
R3(config-router)#no auto-summary
R3(config-router)#ex
查看路由表
- R1
R1(config)#do show 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
192.168.30.0/30 is subnetted, 1 subnets
R 192.168.30.0 [120/1] via 192.168.20.2, 00:00:14, FastEthernet0/1
C 192.168.10.0/24 is directly connected, FastEthernet0/0
R 192.168.40.0/24 [120/2] via 192.168.20.2, 00:00:14, FastEthernet0/1
192.168.20.0/30 is subnetted, 1 subnets
C 192.168.20.0 is directly connected, FastEthernet0/1
- R2
R2(config)#do show 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
192.168.30.0/30 is subnetted, 1 subnets
C 192.168.30.0 is directly connected, FastEthernet0/1
R 192.168.10.0/24 [120/1] via 192.168.20.1, 00:00:07, FastEthernet0/0
R 192.168.40.0/24 [120/1] via 192.168.30.2, 00:00:22, FastEthernet0/1
192.168.20.0/30 is subnetted, 1 subnets
C 192.168.20.0 is directly connected, FastEthernet0/0
- R3
R3(config)#do show 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
192.168.30.0/30 is subnetted, 1 subnets
C 192.168.30.0 is directly connected, FastEthernet0/0
R 192.168.10.0/24 [120/2] via 192.168.30.1, 00:00:01, FastEthernet0/0
C 192.168.40.0/24 is directly connected, FastEthernet0/1
192.168.20.0/30 is subnetted, 1 subnets
R 192.168.20.0 [120/1] via 192.168.30.1, 00:00:01, FastEthernet0/0
验证结果
PC1> ping 192.168.40.2
192.168.40.2 icmp_seq=1 timeout
192.168.40.2 icmp_seq=2 timeout
192.168.40.2 icmp_seq=3 timeout
192.168.40.2 icmp_seq=4 timeout
84 bytes from 192.168.40.2 icmp_seq=5 ttl=61 time=55.813 ms
PC1> ping 192.168.40.2
84 bytes from 192.168.40.2 icmp_seq=1 ttl=61 time=63.822 ms
84 bytes from 192.168.40.2 icmp_seq=2 ttl=61 time=54.815 ms
84 bytes from 192.168.40.2 icmp_seq=3 ttl=61 time=62.803 ms
84 bytes from 192.168.40.2 icmp_seq=4 ttl=61 time=56.948 ms
84 bytes from 192.168.40.2 icmp_seq=5 ttl=61 time=63.943 ms
PC2> ping 192.168.10.2
84 bytes from 192.168.10.2 icmp_seq=1 ttl=61 time=64.749 ms
84 bytes from 192.168.10.2 icmp_seq=2 ttl=61 time=62.858 ms
84 bytes from 192.168.10.2 icmp_seq=3 ttl=61 time=54.841 ms
84 bytes from 192.168.10.2 icmp_seq=4 ttl=61 time=62.966 ms
84 bytes from 192.168.10.2 icmp_seq=5 ttl=61 time=54.853 ms