当前位置: 首页 > news >正文

零基础从头教学Linux(Day 17)

三层交换机

一、三层交换机的配置

1.关于如何配置三层交换机,首先我们应该先创建VLAN

Switch>en
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 10
VLAN 10 added:Name: VLAN0010
Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#vlan 30
VLAN 30 added:Name: VLAN0030
Switch(vlan)#exit
APPLY completed.
Exiting....

2.将端口分配进VLAN

Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 30
Switch(config-if)#no shutdown
Switch(config-if)#exit

3.进入VLAN进行地址网关的分配

Switch(config)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to upSwitch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to upSwitch(config-if)#ip address 192.168.20.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 30
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to upSwitch(config-if)#ip address 192.168.30.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit

4.一定要在全局模式下输入

Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#ip routing

此为开启交换机路由器功能的全局模式

5.配置交换机接口模式

Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit

二、三层交换机的原理

三层交换机结合了传统交换机和路由器的功能,能够在数据链路层(第二层)和网络层(第三层)进行高效的数据转发。以下是其核心工作原理:

1.基于硬件的转发

三层交换机使用专用集成电路(ASIC)或现场可编程门阵列(FPGA)实现高速数据转发。与软件路由相比,硬件转发大幅降低延迟,提升吞吐量。

2.一次路由多次交换

首次跨网段通信时,三层交换机会像路由器一样进行路由表查询和ARP解析,建立转发路径。后续相同流量的数据包直接由交换引擎处理,绕过路由模块。

3.VLAN间路由

通过创建虚拟接口(SVI),三层交换机能够在不同VLAN间直接路由,无需外接路由器。每个SVI对应一个VLAN的默认网关。

4.路由表与转发表

维护两种表结构:

  • 路由表:存储网络拓扑信息,通过静态配置或动态路由协议(如OSPF)生成

  • 转发表:记录MAC地址与端口的映射关系,用于二层交换

5.协议支持

同时处理二层协议(如STP)和三层协议(如IP、ICMP),支持ACL、QoS等高级功能。

三层交换机示例

保证全网段通信,网段配置已经给出

主机配置p1-p5

交换机s1

Switch>en
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 10
VLAN 10 added:Name: VLAN0010
Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

交换机s2

Switch>en
Switch#vlan database 
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#vlan 30
VLAN 30 added:Name: VLAN0030
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 30
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

三层交换机ms1

Switch>en
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,as VLAN database mode is being deprecated. Please consult userdocumentation for configuring VTP/VLAN in config mode.Switch(vlan)#vlan 10
VLAN 10 added:Name: VLAN0010
Switch(vlan)#vlan 20
VLAN 20 added:Name: VLAN0020
Switch(vlan)#vlan 30
VLAN 30 added:Name: VLAN0030
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#ip routing
Switch(config)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to upSwitch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to upSwitch(config-if)#ip address 192.168.20.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int vlan 30
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to upSwitch(config-if)#ip address 192.168.30.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/1
Switch(config-if)#switchport mode trunk
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport mode trunkSwitch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to upSwitch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#int f0/3
Switch(config-if)#no switchport
Switch(config-if)#ip address 10.0.0.1 255.255.255.252
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.2
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

路由器r1配置

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip address 10.0.0.2 255.255.255.252
Router(config-if)#no shutdownRouter(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to upRouter(config-if)#exit
Router(config)#int f0/1
Router(config-if)#ip address 1.0.0.1 255.0.0.0
Router(config-if)#no shutdownRouter(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to upRouter(config-if)#exit
Router(config)#ip route 192.168.10.0 255.255.255.0 10.0.0.1
Router(config)#ip route 192.168.20.0 255.255.255.0 10.0.0.1
Router(config)#ip route 192.168.30.0 255.255.255.0 10.0.0.1
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

结果

RIP动态路由

RIP(Routing Information Protocol)是一种基于距离矢量的动态路由协议,适用于小型网络。它使用跳数(hop count)作为度量标准,最大跳数为$15$,超过$16$跳的路由被视为不可达。RIP通过定期广播或组播路由更新(默认每30秒)来实现路由信息的动态交换。下面基于您提供的v1和v2介绍,进一步扩展协议细节、配置步骤和注意事项。

一、RIP版本详细比较

  • RIP v1

    • 仅支持有类地址(Classful Addressing),例如:$192.168.1.0$(默认掩码为$255.255.255.0$)。
    • 自动汇总子网:当路由器发送更新时,会将子网汇总到类边界(如将$192.168.1.0/24$汇总为$192.168.0.0/16$),这可能导致路由不精确或环路。
    • 使用广播更新(目标地址$255.255.255.255$),不支持认证,安全性较低。
    • 最大跳数限制为$15$,适用于小规模网络。
  • RIP v2

    • 支持无类地址(Classless Addressing),允许使用子网掩码(如$192.168.1.0/26$),实现更精细的路由控制。
    • 默认不自动汇总子网(通过no auto-summary命令禁用),路由器发送更新时包含精确的子网信息,减少路由错误。
    • 使用组播更新(目标地址$224.0.0.9$),提高效率;支持MD5认证,增强安全性。
    • 同样有跳数限制$15$,但更适合现代网络环境。

默认情况下,Cisco设备启用RIP v1;切换到v2需显式配置。v2的主要优势是解决了v1的局限性,如支持VLSM(可变长度子网掩码)和CIDR(无类域间路由)。

二、完整配置步骤

在Cisco设备上配置RIP时,需进入全局配置模式(configure terminal),然后执行以下命令。配置核心是network语句,指定路由器直连的IP网段(必须与接口IP匹配)。以下是一个扩展示例,包括v1和v2的典型场景。

示例:配置RIP v2(推荐用于无类地址环境)

Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# router rip  ! 启用RIP进程
Switch(config-router)# version 2  ! 切换到v2版本
Switch(config-router)# no auto-summary  ! 禁用自动汇总
Switch(config-router)# network 192.168.1.0  ! 指定直连网段,例如192.168.1.0/24
Switch(config-router)# network 10.0.0.0  ! 添加另一个直连网段,例如10.0.0.0/8
Switch(config-router)# exit
Switch(config)# exit
Switch# write memory  ! 保存配置到NVRAM

示例:配置RIP v1(传统模式)

Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# router rip  ! 启用RIP进程(默认v1)
Switch(config-router)# network 172.16.0.0  ! 指定直连网段,例如172.16.0.0/16
Switch(config-router)# exit
Switch(config)# exit
Switch# write memory

关键配置说明

  • network命令:必须输入路由器自身接口的直连网段(如$192.168.1.0$),RIP仅在这些网段上发送和接收更新。每个网段单独添加。
  • 版本切换:在router rip模式下,version 2将协议升级;省略此命令则使用v1。
  • 禁用汇总:v2中no auto-summary确保不自动汇总子网,避免路由黑洞。
  • 添加认证(v2可选):使用key chainip rip authentication命令实现MD5认证,提高安全性。

三、注意事项和最佳实践

  1. 网络设计

    • RIP适用于跳数少(小于$10$)的网络;大型网络推荐OSPF或EIGRP。
    • 在v2中,确保所有路由器运行相同版本,避免兼容问题。
  2. 性能优化

    • 调整计时器:使用timers basic命令修改更新间隔(默认$30$秒),例如设为$20$秒以加快收敛,但会增加带宽开销。
    • 被动接口:在router rip模式下,用passive-interface命令阻止接口发送更新,减少不必要流量。
  3. 常见问题排查

    • 路由环路:启用split-horizon(默认开启)或poison reverse来预防。
    • 更新丢失:检查network语句是否覆盖所有直连网段;使用show ip rip database查看路由表。
    • 安全风险:v1易受攻击;v2中务必配置认证。
  4. 迁移建议

    • 从v1升级到v2时,逐步部署:先在部分路由器启用v2,测试后全网切换。
    • 监控工具:使用debug ip rip命令实时调试更新信息。

http://www.dtcms.com/a/342751.html

相关文章:

  • 在职老D渗透日记day23:sqli-labs靶场通关(第29关-31关)http参数过滤
  • [软件开发技术栈]从MVVM到MVC
  • 大模型提示词工程背后的原理:深入理解Prompt Learning(提示学习)
  • 【Dify(v1.x) 核心源码深入解析】prompt 模块
  • 单智能体篇:Prompt工程艺术
  • 【运维进阶】Shell 函数的知识与实践
  • CTFSHOW | 其他篇题解(一)web396-web416
  • 学习日志39 python
  • 华为iVS1800接入SVMSPro平台
  • Web3 的发展挑战:技术、监管与生态的多重困境
  • 使用C++11改进工厂方法模式:支持运行时配置的增强实现
  • 【Ansible】将文件部署到受管主机1:文件模块
  • Autoware Universe 感知详解 | 第二节 宏观认识Autoware Universe感知模块整体架构
  • C++中的内存管理(二)
  • 第四章:大模型(LLM)】07.Prompt工程-(6)受限生成和引导生成
  • 机械试验台功能量具平台:铸铁工装平台
  • 阿里云对象存储OSS之间进行数据转移教程
  • 小迪安全v2023学习笔记(六十八讲)—— Java安全原生反序列化SpringBoot攻防
  • iOS沙盒机制
  • 【系统信息相关】datecal命令
  • React + Antd+TS 动态表单容器组件技术解析与实现
  • (栈)Leetcode155最小栈+739每日温度
  • Python爬虫实战:研究puzzle,构建谜题类数据采集分析系统
  • 编程语言与存储过程:业务处理的速度与取舍
  • 3ds Max 渲染动画总模糊?
  • 基于stm32的智能建筑能源管理系统/基于单片机的能源管理系统
  • 【Java SE】认识数组
  • 【Protues仿真】基于AT89C52单片机的舵机和直流电机控制
  • 【新启航】3D 扫描逆向抄数全流程工具与技能:从手持设备到 CAD 建模的 10 项核心配置解析
  • windows10安装playwright