diff --git "a/45 \345\210\230\350\213\217\350\220\214/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272.md" "b/45 \345\210\230\350\213\217\350\220\214/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272.md" new file mode 100644 index 0000000000000000000000000000000000000000..dc884220d50f1566cbeaa2b26f067c3607fd5df7 --- /dev/null +++ "b/45 \345\210\230\350\213\217\350\220\214/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272.md" @@ -0,0 +1,274 @@ +#### 三层交换机 + +1. 启用trunk模式 + + - 先将该端口封装成dot1q + + ```c# + SW1(config-if)#sw trunk encapsulation dot1q //将trunk模式先封装成dot1q协议模式 + ``` + + - 启用为trunk + + ```c# + SW1(config-if)#sw mode trunk //启用为trunk模式 + ``` + +2. 开启路由功能: + + - 作用:可以连接不同的网络 + + ```c# + SW1(config)#ip routing + ``` + +3. 开启端口的三层功能:(这个命令要求先进入对应的端口如:int f 0/1) + + - 作用:是让二层端口变成三层端口,使其可以绑定IP,让不同网段的ip互通 + + ```c# + SW1(config-if)#int fa 0/1 + SW1(config-if)#no switch //开启三层交换机 + SW1(config-if)#ip add 192.168.10.1 255.255.255.0 //配置IP+子网掩码 + ``` + +注: + +- 二层交换机的vlan1地址,只能当作远程管理地址使用 +- 三层交换机的SVI可以分别设置ip,并被远程访问到 + + + +#### 作业: + +![20240510_三层交换机作业](./imgs/20240510_三层交换机作业.png) + +- SW1 + + ```c# + Switch>en + Switch#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Switch(config)#host SW1 + SW1(config)#int fa 0/1 + SW1(config-if)#sw acc vlan 100 + % Access VLAN does not exist. Creating vlan 100 + SW1(config-if)#int fa 0/2 + SW1(config-if)#sw acc vlan 200 + % Access VLAN does not exist. Creating vlan 200 + SW1(config-if)#int vlan 100 + SW1(config-if)#ip add 192.168.1.254 255.255.255.0 + SW1(config-if)#int vlan 200 + SW1(config-if)#ip add 192.168.2.254 255.255.255.0 + SW1(config-if)#int fa0/3 + SW1(config-if)#sw trunk encapsulation dot1q //将trunk模式先封装成dot1q协议模式 + SW1(config-if)#sw mode trunk //启用为trunk模式 + SW1(config)#ip routing + SW1(config)#route rip + SW1(config-router)#v 2 + SW1(config-router)#network 192.168.1.0 + SW1(config-router)#network 192.168.2.0 + SW1(config-if)#int fa 0/3 + SW1(config-if)#no switch //开启三层交换机 + SW1(config-if)#ip add 192.168.10.1 255.255.255.0 + SW1(config)#ip routing //三层交换机启用路由功能 + SW1(config)#router ospf 1 //开放式OSPF路由协议 + SW1(config-router)#net 192.168.1.0 0.0.0.255 area 0 + SW1(config-router)#net 192.168.2.0 0.0.0.255 area 0 + SW1(config-router)#net 192.168.10.0 0.0.0.255 area 0 + ``` + +- SW2 + + ```c# + Switch>en + Switch#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Switch(config)#host SW2 + SW2(config)#int fa 0/1 + SW2(config-if)#sw acc vlan 100 + % Access VLAN does not exist. Creating vlan 100 + SW2(config-if)#int fa 0/2 + SW2(config-if)#sw acc vlan 200 + % Access VLAN does not exist. Creating vlan 200 + SW2(config-if)#int vlan 100 + SW2(config-if)#ip add 192.168.3.254 255.255.255.0 + SW2(config-if)#int vlan 200 + SW2(config-if)#ip add 192.168.4.254 255.255.255.0 + SW2(config-if)#int fa 0/3 + SW2(config-if)#sw trunk encapsulation dot1q //将trunk模式先封装成dot1q协议模式 + SW2(config-if)#sw mode trunk //启用为trunk模式 + SW2(config)#int fa 0/3 + SW2(config-if)#no switch //开启三层交换机 + SW2(config-if)#ip add 192.168.10.2 255.255.255.0 + SW2(config)#int fa 0/4 + SW2(config-if)#no switch //开启三层交换机 + SW2(config-if)#ip add 192.168.20.1 255.255.255.0 + SW2(config)#ip routing //三层交换机启用路由功能 + SW2(config)#router ospf 1 //开放式OSPF路由协议 + SW2(config-router)#network 192.168.3.0 0.0.0.255 area 0 + SW2(config-router)#network 192.168.4.0 0.0.0.255 area 0 + SW2(config-router)#network 192.168.10.0 0.0.0.255 area 0 + SW2(config-router)#network 192.168.20.0 0.0.0.255 area 0 + ``` + +- R1 + + ```c# + Router>en + Router#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Router(config)#host R1 + R1(config)#int fa 0/0 + R1(config-if)#no shut + R1(config-if)#ip add 192.168.20.2 255.255.255.0 + R1(config-if)#int fa 0/1 + R1(config-if)#no shut + R1(config-if)#int fa 0/1.1 //进入路由器0模块1端口第1子接口 + R1(config-subif)#encapsulation dot1Q 100 //封装协议为dot1q允许通过的Vlan为100 + R1(config-subif)#ip add 192.168.5.254 255.255.255.0 + R1(config-subif)#int fa 0/1.2 //进入路由器0模块1端口第2子接口 + R1(config-subif)#encapsulation dot1Q 200 //封装协议为dot1q允许通过的Vlan为200 + R1(config-subif)#ip add 192.168.6.254 255.255.255.0 + R1(config)#router ospf 1 //开放式OSPF路由协议 + R1(config-router)#net 192.168.5.0 0.0.0.255 area 0 + R1(config-router)#net 192.168.6.0 0.0.0.255 area 0 + R1(config-router)#net 192.168.20.0 0.0.0.255 area 0 + ``` + +- SW3 + + ```c# + Switch>en + Switch#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Switch(config)#host SW3 + SW3(config)#int fa 0/1 + SW3(config-if)#sw mode trunk + SW3(config-if)#int fa 0/2 + SW3(config-if)#sw acc vlan 100 + % Access VLAN does not exist. Creating vlan 100 + SW3(config-if)#int fa 0/3 + SW3(config-if)#sw acc vlan 200 + % Access VLAN does not exist. Creating vlan 200 + + ``` + + - 终端显示 + + ![20240510_三层交换机终端显示](./imgs/20240510_三层交换机终端显示.png) + + + +#### OSPF练习题: + +1、按下表完成各设备主机名(hostname)和IP地址等信息配置: + +![20240510_OSPF练习](./imgs/20240510_OSPF练习.png) + +- R1 + + ```c# + Router>en + Router#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Router(config)#host R1 + R1(config)#int fa 0/0 + R1(config-if)#no shut + R1(config-if)#ip add 192.168.21.1 255.255.255.240 + R1(config-if)#int fa 0/1 + R1(config-if)#no shut + R1(config-if)#ip add 192.168.21.17 255.255.255.240 + ``` + + + +- R2 + + ```c# + Router>en + Router#conf t + Enter configuration commands, one per line. End with CNTL/Z. + Router(config)#host R2 + R2(config)#int fa 0/1 + R2(config-if)#no shut + R2(config-if)#ip add 192.168.21.18 255.255.255.240 + ``` + +2、在SW1上创建VLAN 11和VLAN 21,分别命名为ks11和ks21,并将PC2加入VLAN 11,PC3加入VLAN 21; + +```c# +Switch>en +Switch#conf t +Enter configuration commands, one per line. End with CNTL/Z. +Switch(config)#host SW1 +SW1(config)#vlan 11 //创建vlan11 +SW1(config-vlan)#name KS11 //将vlan11重命名为KS11 +SW1(config-vlan)#int fa 0/2 +SW1(config-if)#sw acc vlan 11 +SW1(config-if)#vlan 21 +SW1(config-vlan)#name KS21 //将vlan11重命名为KS21 +SW1(config-vlan)#int fa 0/3 +SW1(config-if)#sw acc vlan 21 +SW1(config-if)#do show vlan b //查看vlan配置信息 +``` + +3、将SW1与R2相连的接口配置为Trunk口; + +```c# +//SW1 +SW1(config-if)#int fa0/1 +SW1(config-if)#sw mode trunk +``` + +4、在R2上配置单臂路由,实现VLAN 11和VLAN 21之间的通信; + +```c# +//配置单臂路由 +R2(config)#int fa 0/0 +R2(config-if)#no shut +R2(config-if)#int fa 0/0.11 +R2(config-subif)#encapsulation dot1Q 11 +R2(config-subif)#ip add 192.168.21.129 255.255.255.240 +R2(config-subif)#int fa 0/0.21 +R2(config-subif)#encapsulation dot1Q 21 +R2(config-subif)#ip add 192.168.21.200 255.255.255.240 +``` + +5、在R1配置远程登录(虚拟接口为0-4接口)的口令为123456(明文); + +```c# +R1>en +R1#conf t +Enter configuration commands, one per line. End with CNTL/Z. +R1(config)#line vty 0 4 //进入远程端口管理视图(虚拟接口为0-4接口) +R1(config-line)#password 123456 //配置远程登录密码 +R1(config-line)#login //打开登录认证功能 +``` + +6、在R1和R2上配置OSPF路由协议(要求通告直连网络子网信息),OSPF进程号为1,区域号为0,实现全网通信; + +```c# +//R1 +R1#conf t +Enter configuration commands, one per line. End with CNTL/Z. +R1(config)#route ospf 1 +R1(config-router)#network 192.168.21.0 0.0.0.15 area 0 +R1(config-router)#network 192.168.21.16 0.0.0.15 area 0 + +//R2 +R2>en +R2#conf t +Enter configuration commands, one per line. End with CNTL/Z. +R2(config)#router ospf 1 +R2(config-router)#do show ip route //查看路由配置信息 +R2(config-router)#network 192.168.21.16 0.0.0.15 area 0 +R2(config-router)#network 192.168.21.128 0.0.0.15 area 0 +R2(config-router)#network 192.168.21.192 0.0.0.15 area 0 +``` + +7、配置各台PC网络,并测试各设备通信情况。 + +- 终端显示 + + ![20240510_OSPF练习终端显示](./imgs/20240510_OSPF练习终端显示.png) \ No newline at end of file diff --git "a/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_OSPF\347\273\203\344\271\240.png" "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_OSPF\347\273\203\344\271\240.png" new file mode 100644 index 0000000000000000000000000000000000000000..9f75f720957265f92f4d01704a55a71932645900 Binary files /dev/null and "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_OSPF\347\273\203\344\271\240.png" differ diff --git "a/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_OSPF\347\273\203\344\271\240\347\273\210\347\253\257\346\230\276\347\244\272.png" "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_OSPF\347\273\203\344\271\240\347\273\210\347\253\257\346\230\276\347\244\272.png" new file mode 100644 index 0000000000000000000000000000000000000000..53062c4accf48fb7736ef5d8193a82a12418dbb0 Binary files /dev/null and "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_OSPF\347\273\203\344\271\240\347\273\210\347\253\257\346\230\276\347\244\272.png" differ diff --git "a/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272\344\275\234\344\270\232.png" "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272\344\275\234\344\270\232.png" new file mode 100644 index 0000000000000000000000000000000000000000..37ea7dd09f7b71bb01d7308d97ffba71ab6acc1c Binary files /dev/null and "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272\344\275\234\344\270\232.png" differ diff --git "a/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272\347\273\210\347\253\257\346\230\276\347\244\272.png" "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272\347\273\210\347\253\257\346\230\276\347\244\272.png" new file mode 100644 index 0000000000000000000000000000000000000000..89be2ded1d8b86a2f9b7ef6c9215b261e9fb89fb Binary files /dev/null and "b/45 \345\210\230\350\213\217\350\220\214/imgs/20240510_\344\270\211\345\261\202\344\272\244\346\215\242\346\234\272\347\273\210\347\253\257\346\230\276\347\244\272.png" differ