diff --git "a/12 \350\251\271\345\256\207\350\210\252/20250421-\345\212\250\346\200\201\350\267\257\347\224\261\357\274\210OSPF\345\215\217\350\256\256\357\274\211.md" "b/12 \350\251\271\345\256\207\350\210\252/20250421-\345\212\250\346\200\201\350\267\257\347\224\261\357\274\210OSPF\345\215\217\350\256\256\357\274\211.md" new file mode 100644 index 0000000000000000000000000000000000000000..e8068bc1e27aec97975f531c1b0e2da72820be19 --- /dev/null +++ "b/12 \350\251\271\345\256\207\350\210\252/20250421-\345\212\250\346\200\201\350\267\257\347\224\261\357\274\210OSPF\345\215\217\350\256\256\357\274\211.md" @@ -0,0 +1,133 @@ +## 动态路由(OSPF协议) + +### 步骤 + +- 按下图配置路线图 + + ![image-20250417113033710](https://gitee.com/onesheet/images_backup/raw/master/img/upgit_20250417_1744860633.png) + +- 配置多层交换机和交换机 + + ```cmd + # 配置交换机 + Switch(config)#interface f0/2 //选择端口 + Switch(config-if)#switchport access vlan 10 //将端口添加到vlan10中 + Switch(config-vlan)#exit //VLAN添加结束 + Switch(config)#interface f0/3 //选择端口 + Switch(config-if)#switchport access vlan 40 //将端口添加到vlan40中 + Switch(config-vlan)#exit //VLAN添加结束,更改f0/1端口的模式,改为共享模式 + Switch(config)#interface f0/1 //选择端口 + Switch(config-if)#switchport mode trunk //设置端口模式为Trunk + Switch(config-if)#end + + # 配置多层交换机 + Switch(config)#vlan 10 //创建VLAN 10 + Switch(config-vlan)#exit + Switch(config)#vlan 40 //创建VLAN 40 + Switch(config-vlan)#exit + Switch(config)#interface f0/2 //选择端口 + Switch(config-if)#switchport trunk encapsulation dot1q . //(更改端口模式前提)先将该接口的Trunk封装为802.1Q的帧格式 + Switch(config-if)#switchport mode trunk //然后设置端口模式为Trunk + Switch(config-if)#exit + Switch(config)#ip routing //开启路由功能(且不将f0/2端口更改为三层端口) + Switch(config)#interface vlan 10 //进入SVI接口模式 + Switch(config-if)#ip address 192.168.10.254 255.255.255.0 //配置该SVI接口的IP地址,作为所在VLAN主机的网关 + Switch(config-if)#no shutdown //端口打开 + Switch(config-if)#exit + Switch(config)#interface vlan 40 //进入SVI接口模式 + Switch(config-if)#ip address 192.168.40.254 255.255.255.0 //配置该SVI接口的IP地址,作为所在VLAN主机的网关 + Switch(config-if)#no shutdown + + Switch(config)# interface f0/1 //配置与网络B连接的接口 + Switch(config-if)# no switchport // 转换为三层接口 + Switch(config-if)# ip address 10.10.1.1 255.255.255.0 + Switch(config-if)# no shutdown + + Switch(config)# router ospf 1 // 配置OSPF动态路由,启用OSPF协议 + Switch(config-router)# network 192.168.10.0 0.0.0.255 area 0 // 宣告网段 + Switch(config-router)# network 192.168.40.0 0.0.0.255 area 0 + Switch(config-router)# network 10.10.1.0 0.0.0.255 area 0 + ``` + +- 配置路由器RT1(交换机配置已完成) + + ```cmd + Router(config)# interface g0/2.20 // 配置子接口实现VLAN间路由 + Router(config-subif)# encapsulation dot1Q 20 // VLAN20标签 + Router(config-subif)# ip address 192.168.20.254 255.255.255.0 + Router(config-subif)# no shutdown + + Router(config)# interface g0/2.50 + Router(config-subif)# encapsulation dot1Q 50 // VLAN50标签 + Router(config-subif)# ip address 192.168.50.254 255.255.255.0 + Router(config-subif)# no shutdown + + Router(config)# interface g0/0 // 配置与路由器和多层交换机连接的物理接口 + Router(config-if)# ip address 10.10.1.2 255.255.255.0 + Router(config-if)# no shutdown + + Router(config)# interface g0/1 + Router(config-if)# ip address 10.10.2.1 255.255.255.0 + Router(config-if)# no shutdown + + Router(config)# router ospf 1 // 配置OSPF动态路由,启用OSPF协议 + Router(config-router)# network 192.168.20.0 0.0.0.255 area 0 // 宣告网段 + Router(config-router)# network 192.168.50.0 0.0.0.255 area 0 + Router(config-router)# network 10.10.1.0 0.0.0.255 area 0 + Router(config-router)# network 10.10.2.0 0.0.0.255 area 0 + ``` + +- 配置路由器RT2(交换机配置已完成) + + ```cmd + Router(config)# interface f0/1 + Router(config-if)# ip address 192.168.30.254 255.255.255.0 + Router(config-if)# no shutdown + + Router(config)# interface f0/0 // 配置与路由器连接的物理接口 + Router(config-if)# ip address 10.10.2.2 255.255.255.0 + Router(config-if)# no shutdown + + Router(config)# router ospf 1 // 配置OSPF动态路由,启用OSPF协议 + Router(config-router)# network 192.168.30.0 0.0.0.255 area 0 // 宣告网段 + Router(config-router)# network 10.10.2.0 0.0.0.255 area 0 + ``` + + +## (RIP)动态路由与(OSPF)动态路由相通 + +### 步骤 + +- 同上俩网络路线相同,动态路由协议不同,假设`FastEthernet0/1` 连接 RIP 网络,`FastEthernet0/2` 连接 OSPF 网络。 + +- 配置RIP与OSPF相连的路由器 + + ```cmd + # 配置连接 RIP 网络的接口 + Router(config)# interface FastEthernet0/1 + Router(config-if)# ip address 10.0.0.1 255.255.255.0 // 设置RIP 网络地址为 10.0.0.0/24 + Router(config-if)# no shutdown + Router(config-if)# exit + + # 配置连接 OSPF 网络的接口 + Router(config)# interface FastEthernet0/2 + Router(config-if)# ip address 192.168.0.1 255.255.255.0 // 设置OSPF 网络地址为 192.168.0.0/24 + Router(config-if)# no shutdown + Router(config-if)# exit + + # 配置 RIP 协议 + Router(config)# router rip + Router(config-router)# version 2 + Router(config-router)# no auto-summary + Router(config-router)# network 10.0.0.0 // 宣告 RIP 网络 + Router(config-router)# redistribute ospf 1 metric 2 // 将 OSPF 路由重分发到 RIP,设置度量值为 2 + Router(config-router)# exit + + # 配置 OSPF 协议 + Router(config)# router ospf 1 + Router(config-router)# network 192.168.0.0 0.0.0.255 area 0 // 宣告 OSPF 网络 + Router(config-router)# redistribute rip subnets metric 100 // 将 RIP 路由重分发到 OSPF,设置度量值为 100 + Router(config-router)# exit + ``` + + \ No newline at end of file