如何快速配置华为S5700交换机?

华为S5700交换机基础配置命令详解涵盖核心操作:进入系统视图(system-view),设置设备名称(sysname),配置管理IP(interface vlanif),开启远程登录(telnet server enable,user-interface vty),设置登录密码,以及端口基础设置(port link-type,port default vlan)。

华为S5700系列交换机是企业级接入和汇聚层交换机的经典之作,广泛应用于各种网络环境,掌握其基础配置命令是网络管理员必备的技能,本文将详细介绍S5700最常用、最关键的配置命令,帮助您快速上手。

重要提示与准备工作:

  1. 访问方式: 通常通过Console线首次连接配置,或通过Telnet/SSH远程管理,确保您有合法的登录权限。
  2. 配置视图: 华为设备采用分层视图结构,常见的视图有:
    • 用户视图: <Huawei> 提示符,执行基本查看、测试命令(如 display, ping)。
    • 系统视图: [Huawei] 提示符,执行全局配置命令(如 sysname, vlan batch),在用户视图下输入 system-view 进入。
    • 接口视图: [Huawei-GigabitEthernet0/0/1] 提示符,执行针对特定接口的配置(如 port link-type, port default vlan),在系统视图下输入 interface interface-type interface-number 进入(interface GigabitEthernet 0/0/1)。
    • VLAN视图: [Huawei-vlan10] 提示符,执行针对特定VLAN的配置(如 description),在系统视图下输入 vlan vlan-id 进入。
  3. 帮助命令: 在任何视图下,输入 可以查看当前视图下可用的命令列表,输入命令的前几个字母后按 Tab 键可以自动补全命令。
  4. 保存配置: 配置完成后务必保存! 在用户视图下执行 save 命令,否则设备重启后配置会丢失。

基础系统配置

  1. 设备命名 (Hostname):

    • 作用: 为交换机设置一个易于识别的名称,方便管理。
    • 命令:
      <Huawei> system-view  // 进入系统视图
      [Huawei] sysname SW-Core-Floor1  // 将设备命名为 SW-Core-Floor1
      [SW-Core-Floor1]  // 提示符已改变
  2. 配置管理IP地址:

    • 作用: 为交换机的管理VLAN接口(通常是VLANIF 1或其他管理VLAN)配置IP地址,以便远程管理(Telnet/SSH/Web/SNMP)。
    • 步骤:
      • 创建VLAN (如果管理VLAN不是1):
        [SW-Core-Floor1] vlan batch 100  // 创建VLAN 100 (作为管理VLAN示例)
      • 进入VLAN接口视图并配置IP:
        [SW-Core-Floor1] interface vlanif 100  // 进入VLANIF 100接口视图
        [SW-Core-Floor1-Vlanif100] ip address 192.168.100.1 24  // 配置IP地址192.168.100.1,子网掩码255.255.255.0 (/24)
        [SW-Core-Floor1-Vlanif100] quit  // 退出到系统视图
      • 将物理接口加入管理VLAN (如果接口需要访问管理IP):
        [SW-Core-Floor1] interface GigabitEthernet 0/0/24  // 进入连接管理终端的接口视图
        [SW-Core-Floor1-GigabitEthernet0/0/24] port link-type access  // 设置接口为Access模式
        [SW-Core-Floor1-GigabitEthernet0/0/24] port default vlan 100  // 将接口加入VLAN 100
        [SW-Core-Floor1-GigabitEthernet0/0/24] quit
  3. 配置默认网关:

    • 作用: 使交换机能够访问其他网段的设备(如网管服务器、互联网)。
    • 命令:
      [SW-Core-Floor1] ip route-static 0.0.0.0 0.0.0.0 192.168.100.254  // 设置默认网关为192.168.100.254
  4. 配置远程登录 (Telnet/SSH – 强烈推荐SSH):

    • 作用: 允许管理员通过网络远程管理交换机。
    • 基本Telnet配置 (安全性较低,仅作示例,生产环境建议SSH):
      [SW-Core-Floor1] user-interface vty 0 4  // 进入VTY 0到4的虚拟终端线路视图
      [SW-Core-Floor1-ui-vty0-4] authentication-mode password  // 设置认证方式为密码认证
      [SW-Core-Floor1-ui-vty0-4] set authentication password cipher Huawei@123  // 设置登录密码为Huawei@123 (cipher表示加密存储)
      [SW-Core-Floor1-ui-vty0-4] protocol inbound telnet  // 允许Telnet协议接入 (或 all)
      [SW-Core-Floor1-ui-vty0-4] quit
    • 配置SSH (更安全): 需要生成RSA密钥对、创建SSH用户、指定服务类型和认证方式,步骤略复杂,建议参考华为官方文档配置。

接口配置

  1. 接口基本参数:

    • 描述 (Description):
      [SW-Core-Floor1] interface GigabitEthernet 0/0/1
      [SW-Core-Floor1-GigabitEthernet0/0/1] description To-PC-UserA  // 给接口添加描述信息
    • 启用/禁用接口:
      [SW-Core-Floor1-GigabitEthernet0/0/1] shutdown  // 禁用接口 (默认是开启的)
      [SW-Core-Floor1-GigabitEthernet0/0/1] undo shutdown  // 启用接口
    • 双工模式与速率 (通常Auto即可):
      [SW-Core-Floor1-GigabitEthernet0/0/1] undo negotiation auto  // 关闭自协商 (慎用)
      [SW-Core-Floor1-GigabitEthernet0/0/1] speed 100  // 强制速率100Mbps
      [SW-Core-Floor1-GigabitEthernet0/0/1] duplex full  // 强制全双工
      // 恢复自协商
      [SW-Core-Floor1-GigabitEthernet0/0/1] negotiation auto
  2. 配置接口链路类型 (Access/Trunk/Hybrid):

    • Access接口: 通常用于连接终端设备(PC、打印机、IP电话、AP),只允许一个VLAN的流量通过(PVID)。
      [SW-Core-Floor1] interface GigabitEthernet 0/0/5
      [SW-Core-Floor1-GigabitEthernet0/0/5] port link-type access  // 设置为Access模式
      [SW-Core-Floor1-GigabitEthernet0/0/5] port default vlan 10  // 将该接口加入VLAN 10 (即设置PVID=10)
    • Trunk接口: 通常用于交换机之间的互联,允许多个VLAN的流量通过,需要指定允许通过的VLAN列表和Native VLAN (PVID)。
      [SW-Core-Floor1] interface GigabitEthernet 0/0/24  // 假设连接另一台交换机
      [SW-Core-Floor1-GigabitEthernet0/0/24] port link-type trunk  // 设置为Trunk模式
      [SW-Core-Floor1-GigabitEthernet0/0/24] port trunk allow-pass vlan 10 20 100  // 允许VLAN 10, 20, 100通过
      [SW-Core-Floor1-GigabitEthernet0/0/24] port trunk pvid vlan 1  // 设置Native VLAN (PVID) 为1 (默认值,可根据需要修改)
    • Hybrid接口: 功能更灵活,兼具Access和Trunk特性,可以同时以Tagged和Untagged方式发送多个VLAN的流量,配置略复杂,此处不展开。

VLAN配置

  1. 创建VLAN:

    [SW-Core-Floor1] vlan batch 10 20 30  // 一次性创建VLAN 10, 20, 30
    [SW-Core-Floor1] vlan 100  // 创建单个VLAN 100 (并进入VLAN视图)
    [SW-Core-Floor1-vlan100] description Department-Finance  // (可选) 为VLAN 100添加描述
    [SW-Core-Floor1-vlan100] quit
  2. 将接口加入VLAN (已在接口配置部分说明):

    • 对于Access接口:使用 port default vlan <vlan-id>
    • 对于Trunk接口:使用 port trunk allow-pass vlan <vlan-id-list> 允许VLAN通过。
  3. 配置VLAN接口 (SVI – Switch Virtual Interface):

    • 作用: 为三层交换机上的VLAN提供IP层接口,实现VLAN间路由。
    • 命令:
      [SW-Core-Floor1] interface vlanif 10  // 进入VLANIF 10接口视图
      [SW-Core-Floor1-Vlanif10] ip address 192.168.10.1 24  // 为VLAN 10配置网关IP
      [SW-Core-Floor1-Vlanif10] quit
      // 同样方法配置其他需要路由的VLAN的VLANIF

生成树协议 (STP/RSTP/MSTP) 配置

  • 作用: 防止二层环路,提供冗余链路备份,S5700默认启用MSTP。
  • 基本配置 (通常需要全局和接口视图配合):
    [SW-Core-Floor1] stp mode mstp  // 确认模式为MSTP (默认)
    [SW-Core-Floor1] stp region-configuration  // 进入MST域配置视图
    [SW-Core-Floor1-mst-region] region-name MyNetwork  // 配置MST域名
    [SW-Core-Floor1-mst-region] revision-level 1  // 配置修订级别
    [SW-Core-Floor1-mst-region] instance 1 vlan 10 20  // 将VLAN 10, 20映射到实例1
    [SW-Core-Floor1-mst-region] instance 2 vlan 30 100  // 将VLAN 30, 100映射到实例2
    [SW-Core-Floor1-mst-region] active region-configuration  // 激活配置
    [SW-Core-Floor1-mst-region] quit
    [SW-Core-Floor1] stp instance 1 root primary  // 设置本交换机为实例1的根桥
    [SW-Core-Floor1] stp instance 2 root secondary  // 设置本交换机为实例2的备份根桥
    // 在连接终端的Access接口上,通常可以关闭STP以节省资源 (确保该接口不会形成环路)
    [SW-Core-Floor1] interface GigabitEthernet 0/0/5
    [SW-Core-Floor1-GigabitEthernet0/0/5] stp disable  // 在该接口禁用STP
    [SW-Core-Floor1-GigabitEthernet0/0/5] quit

链路聚合 (Eth-Trunk) 配置

  • 作用: 将多个物理接口捆绑成一个逻辑接口,增加带宽、提供冗余。
  • 配置步骤:
    1. 创建Eth-Trunk接口:
      [SW-Core-Floor1] interface Eth-Trunk 1  // 创建Eth-Trunk 1 (并进入Eth-Trunk视图)
      [SW-Core-Floor1-Eth-Trunk1] quit
    2. 配置Eth-Trunk工作模式 (LACP静态/动态):
      [SW-Core-Floor1] interface Eth-Trunk 1
      [SW-Core-Floor1-Eth-Trunk1] mode lacp-static  // 设置为LACP静态模式 (常用)
      // 或 mode lacp-dynamic (动态LACP) / mode manual load-balance (手工负载分担)
      [SW-Core-Floor1-Eth-Trunk1] quit
    3. 将物理接口加入Eth-Trunk:
      [SW-Core-Floor1] interface GigabitEthernet 0/0/23
      [SW-Core-Floor1-GigabitEthernet0/0/23] eth-trunk 1  // 将G0/0/23加入Eth-Trunk 1
      [SW-Core-Floor1-GigabitEthernet0/0/23] quit
      [SW-Core-Floor1] interface GigabitEthernet 0/0/24
      [SW-Core-Floor1-GigabitEthernet0/0/24] eth-trunk 1  // 将G0/0/24加入Eth-Trunk 1
      [SW-Core-Floor1-GigabitEthernet0/0/24] quit
    4. 配置Eth-Trunk接口参数 (如链路类型): 像配置普通物理接口一样配置Eth-Trunk接口(如 port link-type trunk, port trunk allow-pass vlan ...)。

访问控制列表 (ACL) 配置

  • 作用: 过滤流量,实现安全策略。
  • 基本ACL (基于源IP):
    [SW-Core-Floor1] acl 2000  // 创建基本ACL 2000 (2000-2999范围)
    [SW-Core-Floor1-acl-basic-2000] rule 5 deny source 192.168.10.100 0  // 拒绝源IP 192.168.10.100 (0表示精确匹配)
    [SW-Core-Floor1-acl-basic-2000] rule 10 permit source any  // 允许其他所有源IP
    [SW-Core-Floor1-acl-basic-2000] quit
  • 高级ACL (基于IP五元组等):
    [SW-Core-Floor1] acl 3000  // 创建高级ACL 3000 (3000-3999范围)
    [SW-Core-Floor1-acl-adv-3000] rule 5 deny tcp source 192.168.20.0 0.0.0.255 destination 10.1.1.1 0 destination-port eq 80  // 拒绝192.168.20.0/24网段访问10.1.1.1的80端口(TCP)
    [SW-Core-Floor1-acl-adv-3000] rule 10 permit ip  // 允许其他所有IP流量
    [SW-Core-Floor1-acl-adv-3000] quit
  • 应用ACL (通常在接口入方向或VLANIF应用):
    [SW-Core-Floor1] interface GigabitEthernet 0/0/10  // 应用在接口入方向
    [SW-Core-Floor1-GigabitEthernet0/0/10] traffic-filter inbound acl 2000  // 在入方向应用ACL 2000
    [SW-Core-Floor1-GigabitEthernet0/0/10] quit
    // 或在VLANIF应用 (用于过滤路由流量)
    [SW-Core-Floor1] interface vlanif 20
    [SW-Core-Floor1-Vlanif20] traffic-filter inbound acl 3000
    [SW-Core-Floor1-Vlanif20] quit

常用查看与维护命令

  • 查看运行配置: display current-configuration (在用户或系统视图)
  • 查看保存的配置: display saved-configuration (在用户视图)
  • 查看接口状态与统计: display interface brief / display interface [interface-type interface-number] (如 display interface GigabitEthernet 0/0/1)
  • 查看VLAN信息: display vlan / display vlan vlan-id
  • 查看MAC地址表: display mac-address
  • 查看ARP表: display arp
  • 查看路由表: display ip routing-table
  • 查看STP状态: display stp brief / display stp [interface interface-type interface-number]
  • 查看Eth-Trunk状态: display eth-trunk [trunk-id]
  • 查看ACL配置与应用: display acl all
  • Ping测试: ping [ip-address] (在用户视图)

原创文章,发布者:酷番叔,转转请注明出处:https://cloud.kd.cn/ask/6805.html

(0)
酷番叔酷番叔
上一篇 2025年7月9日 08:16
下一篇 2025年7月9日 08:27

相关推荐

  • Windows 10命令提示符有7种打开方式?

    通过运行对话框(最快捷)同时按下 Win + R 组合键(Win键为键盘左下角Windows徽标键)在弹出窗口中输入 cmd按回车键或点击“确定”适用场景:日常快速执行命令开始菜单搜索(推荐新手使用)点击任务栏左侧 开始按钮 或按 Win 键直接在搜索框输入 “命令提示符” 或 “cmd”从结果中点击 “命令提……

    2025年7月4日
    1200
  • 如何用wsimport快速生成Java Web服务客户端?

    wsimport 是 Java JDK 自带的命令行工具,用于根据 WSDL(Web Services Description Language)文件生成调用 Web Service 所需的客户端代码(如 Java 类、接口等),它简化了 Java 应用与 SOAP Web Service 的集成过程,以下是详……

    2025年7月8日
    700
  • 为何总有人用错expand命令?

    expand命令并非用于解压文件(如.zip、.rar等压缩包),这是一个常见的概念混淆,其真实功能是将文本文件中的制表符(Tab)转换为空格,属于文本处理工具,与文件压缩/解压无关,expand命令的核心功能详解作用场景:当文本文件使用制表符(\t)缩进时,不同编辑器或系统可能显示不一致,expand将制表符……

    2025年7月7日
    1200
  • Java执行系统命令有多危险?

    两种核心执行方式Runtime.exec() 方法Java最传统的命令执行方式,通过java.lang.Runtime类实现:try { // 执行命令 Process process = Runtime.getRuntime().exec("ls -l /home"); // 读取命令输出……

    2025年7月6日
    1200
  • Windows cmd如何提取文件名?

    方法1:使用 dir /b 命令(基础提取)作用:直接列出当前目录下的文件名(不含路径和元信息),命令示例:dir /b > filenames.txt效果:将当前目录所有文件名保存到 filenames.txt 中,扩展用法:提取特定类型文件: dir /b *.txt > text_files……

    2025年7月8日
    1000

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

400-880-8834

在线咨询: QQ交谈

邮件:HI@E.KD.CN

关注微信