From 2fd1b8b5ede7a9c49408cbaada4696097f66d083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=98=89=E7=8E=B2?= <14091858+softwork-wjl@user.noreply.gitee.com> Date: Mon, 21 Apr 2025 20:42:53 +0800 Subject: [PATCH] 20250421 --- ...46\200\201\350\267\257\347\224\261OSPF.md" | 450 ++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 "30 \345\220\264\345\230\211\347\216\262/20250421 \345\212\250\346\200\201\350\267\257\347\224\261OSPF.md" diff --git "a/30 \345\220\264\345\230\211\347\216\262/20250421 \345\212\250\346\200\201\350\267\257\347\224\261OSPF.md" "b/30 \345\220\264\345\230\211\347\216\262/20250421 \345\212\250\346\200\201\350\267\257\347\224\261OSPF.md" new file mode 100644 index 0000000..ee89ceb --- /dev/null +++ "b/30 \345\220\264\345\230\211\347\216\262/20250421 \345\212\250\346\200\201\350\267\257\347\224\261OSPF.md" @@ -0,0 +1,450 @@ +# 动态OSPF + +拓扑图:![image-20250421201832469](https://gitee.com/softwork-wjl/picture-warehouse/raw/master/img/upgit_20250421_1745237912.png) + +使用动态OSPF: + +准备工作:设置每个PC的IP子网掩码,网关 + +1. SW1/2/3: + +```cmd +Switch>en +Switch#conf t +Enter configuration commands, one per line. End with CNTL/Z. +Switch(config)#inter f0/2 +Switch(config-if)#sw ac vlan 10 +% Access VLAN does not exist. Creating vlan 10 +Switch(config-if)#ex +Switch(config)#inter f0/3 +Switch(config-if)#sw ac vlan 20 +% Access VLAN does not exist. Creating vlan 20 +Switch(config-if)#ex +Switch(config)#inter f0/1 +Switch(config-if)#sw mode trunk +``` + +2. RT1: + + ```cmd + + Router>en + Router#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Router(config)#inter f0/0 + Router(config-if)#no shutdown + //设置子接口用于网关 + Router(config-if)#ex + Router(config)#inter f0/0.1 + Router(config-subif)#encapsulation dot1Q 30 + Router(config-subif)#ip address 192.168.30.254 255.255.255.0 + Router(config-subif)#ex + //设置子接口用于网关 + Router(config)#inter f0/0.2 + Router(config-subif)#encapsulation dot1Q 40 + Router(config-subif)#ip address 192.168.40.254 255.255.255.0 + Router(config-subif)#ex + + Router(config)#inter f1/0 + Router(config-if)#no shutdown + Router(config-if)#ip address 20.20.20.1 255.255.255.0 + Router(config-if)#ex + + Router(config)#inter f0/1 + Router(config-if)#no shutdown + Router(config-if)#ip address 10.10.10.2 255.255.255.0 + Router(config-if)#ex + //设置动态OSPF + Router(config)#router OSPF 1 + Router(config-router)#network 10.10.10.0 0.0.0.255 area 0 + Router(config-router)#network 20.20.20.0 0.0.0.255 area 0 + Router(config-router)#network 192.168.30.0 0.0.0.255 area 0 + Router(config-router)#network 192.168.40.0 0.0.0.255 area 0 + Router(config-router)#ex + Router(config)#ex + + Router#show running-config + Building configuration... + + Current configuration : 1107 bytes + ! + version 12.4 + no service timestamps log datetime msec + no service timestamps debug datetime msec + no service password-encryption + ! + hostname Router + ! + ! + ! + ! + ! + ! + ! + ! + no ip cef + no ipv6 cef + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + spanning-tree mode pvst + ! + ! + ! + ! + ! + ! + interface FastEthernet0/0 + no ip address + duplex auto + speed auto + ! + interface FastEthernet0/0.1 + encapsulation dot1Q 30 + ip address 192.168.30.254 255.255.255.0 + ! + interface FastEthernet0/0.2 + encapsulation dot1Q 40 + ip address 192.168.40.254 255.255.255.0 + ! + interface FastEthernet0/1 + ip address 10.10.10.2 255.255.255.0 + duplex auto + speed auto + ! + interface FastEthernet1/0 + ip address 20.20.20.1 255.255.255.0 + duplex auto + speed auto + ! + interface FastEthernet1/1 + no ip address + duplex auto + speed auto + shutdown + ! + interface Vlan1 + no ip address + shutdown + ! + //设置成功 + router ospf 1 + log-adjacency-changes + network 10.10.10.0 0.0.0.255 area 0 + network 20.20.20.0 0.0.0.255 area 0 + network 192.168.30.0 0.0.0.255 area 0 + network 192.168.40.0 0.0.0.255 area 0 + ! + ip classless + ! + ip flow-export version 9 + ! + ! + ! + ! + ! + ! + ! + ! + line con 0 + ! + line aux 0 + ! + line vty 0 4 + login + --More-- + ``` + + 3. RT2: + + ```cmd + + Router>en + Router#conf t + + Router(config)#inter f0/0 + Router(config-if)#no shutdown + //设置子接口用于网关 + Router(config-if)#ex + Router(config)#inter f0/0.1 + Router(config-subif)#encapsulation dot1Q 50 + Router(config-subif)#ip address 192.168.50.254 255.255.255.0 + Router(config-subif)#ex + //设置子接口用于网关 + Router(config)#inter f0/0.2 + Router(config-subif)#encapsulation dot1Q 60 + Router(config-subif)#ip address 192.168.60.254 255.255.255.0 + Router(config-subif)#ex + + Router(config)#inter f0/1 + Router(config-if)#no shutdown + Router(config-if)#ip address 20.20.20.2 255.255.255.0 + Router(config-if)#ex + //设置动态OSPF + Router(config)#router OSPF 1 + Router(config-router)#network 20.20.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 192.168.60.0 0.0.0.255 area 0 + Router(config-router)#ex + Router(config)#ex + + Router#show running-config + Building configuration... + + Current configuration : 899 bytes + ! + version 12.4 + no service timestamps log datetime msec + no service timestamps debug datetime msec + no service password-encryption + ! + hostname Router + ! + ! + ! + ! + ! + ! + ! + ! + ip cef + no ipv6 cef + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + spanning-tree mode pvst + ! + ! + ! + ! + ! + ! + interface FastEthernet0/0 + no ip address + duplex auto + speed auto + ! + interface FastEthernet0/0.1 + encapsulation dot1Q 50 + ip address 192.168.50.254 255.255.255.0 + ! + interface FastEthernet0/0.2 + encapsulation dot1Q 60 + ip address 192.168.60.254 255.255.255.0 + ! + interface FastEthernet0/1 + ip address 20.20.20.2 255.255.255.0 + duplex auto + speed auto + ! + interface Vlan1 + no ip address + shutdown + ! + //设置成功 + router ospf 1 + log-adjacency-changes + network 20.20.20.0 0.0.0.255 area 0 + network 192.168.50.0 0.0.0.255 area 0 + network 192.168.60.0 0.0.0.255 area 0 + ! + ip classless + ! + ip flow-export version 9 + ! + ! + --More-- + ``` + + 4. 三层交换机 + + ```cmd + Switch>en + Switch#conf t + + Switch(config)#ip routing //设置成路由模式 + Switch(config)#vlan 10 + Switch(config-vlan)#ex + Switch(config)#vlan 20 + Switch(config-vlan)#ex + + Switch(config)#inter f0/1 + Switch(config-if)#sw trunk encapsulation dot1q //打开端口的trunk模式必写 + Switch(config-if)#sw mode trunk//打开中继 + Switch(config-if)#ex + + Switch(config)#inter f0/2 //连接RT1 + Switch(config-if)#no switchport //将二层转成三层才可以设置IP + + Switch(config-if)#ip address 10.10.10.1 255.255.255.0 + Switch(config-if)#ex + + Switch(config)#inter vlan 10 + Switch(config-if)#ip address 192.168.10.254 255.255.255.0 + Switch(config-if)#no shutdown + + Switch(config-if)#ex + Switch(config)#inter vlan 20 + Switch(config-if)#ip address 192.168.20.254 255.255.255.0 + Switch(config-if)#no shutdown + Switch(config-if)#ex + + //设置OSPF + Switch(config)#router OSPF 1 + Switch(config-router)#network 10.10.10.0 0.0.0.255 area 0 + Switch(config-router)#network 192.168.10.0 0.0.0.255 area 0 + Switch(config-router)#network 192.168.20.0 0.0.0.255 area 0 + Switch(config-router)#end + + Switch#show running-config + Building configuration... + + Current configuration : 1617 bytes + ! + version 12.2(37)SE1 + no service timestamps log datetime msec + no service timestamps debug datetime msec + no service password-encryption + ! + hostname Switch + ! + ! + ! + ! + ! + ! + ip routing + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + ! + spanning-tree mode pvst + ! + ! + ! + ! + ! + ! + interface FastEthernet0/1 + switchport trunk encapsulation dot1q + switchport mode trunk + ! + interface FastEthernet0/2 + no switchport + ip address 10.10.10.1 255.255.255.0 + duplex auto + speed auto + ! + interface FastEthernet0/3 + ! + interface FastEthernet0/4 + ! + interface FastEthernet0/5 + ! + interface FastEthernet0/6 + ! + interface FastEthernet0/7 + ! + interface FastEthernet0/8 + ! + interface FastEthernet0/9 + ! + interface FastEthernet0/10 + ! + interface FastEthernet0/11 + ! + interface FastEthernet0/12 + ! + interface FastEthernet0/13 + ! + interface FastEthernet0/14 + ! + interface FastEthernet0/15 + ! + interface FastEthernet0/16 + ! + interface FastEthernet0/17 + ! + interface FastEthernet0/18 + ! + interface FastEthernet0/19 + ! + interface FastEthernet0/20 + ! + interface FastEthernet0/21 + ! + interface FastEthernet0/22 + ! + interface FastEthernet0/23 + ! + interface FastEthernet0/24 + ! + interface GigabitEthernet0/1 + ! + interface GigabitEthernet0/2 + ! + interface Vlan1 + no ip address + shutdown + ! + interface Vlan10 + mac-address 00d0.ff47.2b01 + ip address 192.168.10.254 255.255.255.0 + ! + interface Vlan20 + mac-address 00d0.ff47.2b02 + ip address 192.168.20.254 255.255.255.0 + ! + //设置成功 + router ospf 1 + log-adjacency-changes + network 10.10.10.0 0.0.0.255 area 0 + network 192.168.10.0 0.0.0.255 area 0 + network 192.168.20.0 0.0.0.255 area 0 + ! + ip classless + ! + ip flow-export version 9 + ! + ! + ! + ! + ! + ! + ! + ! + --More-- + ``` + + 5. ping链路通 + +​ **![image-20250421202708102](https://gitee.com/softwork-wjl/picture-warehouse/raw/master/img/upgit_20250421_1745238428.png)** \ No newline at end of file -- Gitee