diff --git "a/27 \345\274\240\350\257\255\345\253\243/20250418-\350\267\257\347\224\261\345\231\250\345\212\250\346\200\201\350\267\257\347\224\261\347\232\204\351\205\215\347\275\256.md" "b/27 \345\274\240\350\257\255\345\253\243/20250418-\350\267\257\347\224\261\345\231\250\345\212\250\346\200\201\350\267\257\347\224\261\347\232\204\351\205\215\347\275\256.md" new file mode 100644 index 0000000000000000000000000000000000000000..302d27900630109339a67104c3a0cf578ab02b2d --- /dev/null +++ "b/27 \345\274\240\350\257\255\345\253\243/20250418-\350\267\257\347\224\261\345\231\250\345\212\250\346\200\201\350\267\257\347\224\261\347\232\204\351\205\215\347\275\256.md" @@ -0,0 +1,240 @@ +## 技术原理: + +- 动态路由选择:路由器使用路由选择协议(算法)根据实测或估计的距离、时延和网络拓扑等度量权值,自动计算最佳路径并建立路由表。相比静态路由选择,它配置手段更加便捷,适合应用于中大型且网络拓扑变化频繁的网络环境;但另一方面则会占用更多的路由器CPU资源和网络带宽。 + +- 路由选择协议可分为3大类,只有理解不同路由选择协议的工作方式,才能根据实际情况具体分析,从而最大程度上满足具体的应用需要: + + - 距离矢量:通过判断距离确定当前到达目的网络的最佳路径。如RIP、IGRP等 + + - 链路状态:通过发送本路由器与哪些路由器相邻,及其链路状态(距离、时延等)信息,如OSPF等 + + - 混合型:同时具有距离矢量和链路状态两种协议的特性,如EIGRP等 + +- 路由信息协议(Routing Information Protocls,即 RIP),是应用较早、使用较普遍的IGP内部路由协议,使用于小型同类网络的一种距离矢量协议,有以下两个版本:15跳 + + - RIPv1:属于有类路由协议,不支持VLSM,以广播形式进行路由更新; 255.255.255.0 /8 /16 /24 / 32 /25 19 + + - RIPv2:属于无类路由协议,支持VLSM,以组播形式进行路由更新; + + CIDR是子网掩码往左边移了,VLSM是子网掩码往右边移了 + +- 路由配置模式            Router(config-router)# + +- 核心语法: + + ```bash + Router(config)#route rip // 启用动态路由RIP协议 ,进入RIP配置模式 + Router(config-router)#version 2 // 选用RIP2版本 + # Router(config-router)#network 当前路由直连的网络 // 向别的路由器通[宣告]告自己所连接的网络 + Router(config-router)#network 192.168.10.0 + ``` + + + +## 实验拓扑: + +**入门** + +![image-20250417153531527](https://gitee.com/onesheet/images_backup/raw/master/img/upgit_20250417_1744875335.png) + +```bash +# 分别配置好两个电脑的IP、子网掩码、网关 +# 电脑1 +ip:192.168.10.1 +子网掩码:255.255.255.0 +网关:192.168.10.254 + +# 电脑2 +ip:192.168.20.1 +子网掩码:255.255.255.0 +网关:192.168.20.254 + +# 从左往右,依次给三台路由器改名为RT1,RT2,RT3 +命令为:hostname RT1 + +# 配置RT1的相关配置 +Router> +Router>en +Router#conf t +Enter configuration commands, one per line. End with CNTL/Z. +Router(config)#hostname RT1 // 修改设备主机名称 +RT1(config)#interface g0/1 // 选择要配置的端口 +RT1(config-if)#no shutdown // 启用端口 +RT1(config-if)#ip address 192.168.10.254 255.255.255.0 // 给端口绑定IP +RT1(config-if)#ex // 返回上一级 +RT1(config)#interface g0/0 +RT1(config-if)#ip address 10.10.10.1 255.255.255.0 +RT1(config-if)#no shutdown +RT1(config-if)#ex +RT1(config)#route rip // 启用动态路由的RIP协议 +RT1(config-RT1)#version 2 // 设置为RIPv2版本 +RT1(config-RT1)#network 10.10.10.0 // 对外宣告直连网络一 +RT1(config-RT1)#network 192.168.10.0 // 对外宣告直连网络二 + +# RT2的相关配置 +Router>en +Router#conf t +Enter configuration commands, one per line. End with CNTL/Z. +Router(config)#hostname RT2 +RT2(config)#interface g0/0 +RT2(config-if)#ip address 10.10.10.2 255.255.255.0 +RT2(config-if)#no shutdown +RT2(config-if)#ex +RT2(config)#interface g0/1 +RT2(config-if)#no shutdown +RT2(config-if)#ip address 10.10.20.1 255.255.255.0 +RT2(config-if)#ex +RT2(config)#route rip +RT2(config-router)#version 2 +RT2(config-router)#network 10.10.10.0 +RT2(config-router)#network 10.10.20.0 + +# RT3的相关配置 +Router> +Router>en +Router#conf t +Enter configuration commands, one per line. End with CNTL/Z. +Router(config)#hostname RT3 +RT3(config)#interface g0/0 +RT3(config-if)#no shutdown +RT3(config-if)#ip address 10.10.20.2 255.255.255.0 +RT3(config-if)#ex +RT3(config)#interface g0/1 +RT3(config-if)#no shutdown +RT3(config-if)#ip address 192.168.20.254 255.255.255.0 +RT3(config-if)#ex +RT3(config)#route rip +RT3(config-router)#version 2 +RT3(config-router)#network 10.10.20.0 +RT3(config-router)#network 192.168.20.0 + +# 分别查看RT1,RT2,RT3的路由表 +# RT1 +RT1#show ip route +Codes: L - local, 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, E - EGP + i - IS-IS, 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 + + 10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks +C 10.10.10.0/24 is directly connected, GigabitEthernet0/0 +L 10.10.10.1/32 is directly connected, GigabitEthernet0/0 +R 10.10.20.0/24 [120/1] via 10.10.10.2, 00:00:13, GigabitEthernet0/0 + 192.168.10.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.10.0/24 is directly connected, GigabitEthernet0/1 +L 192.168.10.254/32 is directly connected, GigabitEthernet0/1 +R 192.168.20.0/24 [120/2] via 10.10.10.2, 00:00:13, GigabitEthernet0/0 + +# RT2 +RT2#show ip route +Codes: L - local, 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, E - EGP + i - IS-IS, 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 + + 10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks +C 10.10.10.0/24 is directly connected, GigabitEthernet0/0 +L 10.10.10.2/32 is directly connected, GigabitEthernet0/0 +C 10.10.20.0/24 is directly connected, GigabitEthernet0/1 +L 10.10.20.1/32 is directly connected, GigabitEthernet0/1 +R 192.168.10.0/24 [120/1] via 10.10.10.1, 00:00:18, GigabitEthernet0/0 +R 192.168.20.0/24 [120/1] via 10.10.20.2, 00:00:10, GigabitEthernet0/1 + +# RT3 +RT3#show ip route +Codes: L - local, 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, E - EGP + i - IS-IS, 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 + + 10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks +R 10.10.10.0/24 [120/1] via 10.10.20.1, 00:00:18, GigabitEthernet0/0 +C 10.10.20.0/24 is directly connected, GigabitEthernet0/0 +L 10.10.20.2/32 is directly connected, GigabitEthernet0/0 +R 192.168.10.0/24 [120/2] via 10.10.20.1, 00:00:18, GigabitEthernet0/0 + 192.168.20.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.20.0/24 is directly connected, GigabitEthernet0/1 +L 192.168.20.254/32 is directly connected, GigabitEthernet0/1 + +# 链路测试 +# 192.168.10.1 ping 192.168.20.1 +Packet Tracer PC Command Line 1.0 +C:\>ping 192.168.20.1 + +Pinging 192.168.20.1 with 32 bytes of data: + +Request timed out. +Reply from 192.168.20.1: bytes=32 time<1ms TTL=125 +Reply from 192.168.20.1: bytes=32 time=1ms TTL=125 +Reply from 192.168.20.1: bytes=32 time<1ms TTL=125 + +Ping statistics for 192.168.20.1: + Packets: Sent = 4, Received = 3, Lost = 1 (25% loss), +Approximate round trip times in milli-seconds: + Minimum = 0ms, Maximum = 1ms, Average = 0ms + +# 入门实验完成 +``` + +### 小结: + +- 最终目标是让各个路由器的路由表都有包含各个网络完整的路由表 +- 如果某个路由器设置了RIP,却缺少某个网络,可能是版本没设置为v2,即version 2 +- 如果中途某个路由器的网络发生了修改,或添加,要主动对外宣告 +- 如果中途某个路由器的网络关生了关闭或重启,其它路由器会自动处理 + + + +*扩展* + +![image-20250417112944416](https://gitee.com/onesheet/images_backup/raw/master/img/upgit_20250417_1744860584.png) + + +## 实验步骤: + + + + +```bash +1. 各PC设置和服务器先配置好ip,子网掩码,网关 +2. 配置RT1,将所有用到的端口,配上IP,依次照样配置完RT2,RT3,RT4 +3. 各路由器向外宣告自己所连接的网络 +4. 查看各路由器中的路由表是否完整 +5. 在PC上做链路测试Ping +``` + + + + +## 作业 + + + +![image-20250417113033710](https://gitee.com/onesheet/images_backup/raw/master/img/upgit_20250417_1744860633.png) + +### 步骤提示 + +- 新建Cisco PT 拓扑图 +- 为各PC设置IP及网关地址,其中网关地址分别为路由接口的IP地址 +- 对三层交换机SW1进行相关配置(VLAN、SVI及路由等) +- 接着为RT1和RT2上的以太网接口配置IP地址 +- 在路由器之间的接口上配置IP地址,且IP地址必须在同一子网内 +- 査看路由器上的直连路由 +- 在RT1和RT2上配置RIP动态路由 +- 查看路由器上的动态路由 +- 验证不同局域网PC之间的相互通信