交换机基本配置命令
一、模式命令:
- 用户模式:
Switch>
- 特权模式:
Switch>enable
Switch#
- 全局配置模式:
Switch# config terminal
Switch(config)#
- 接口配置模式:
Switch(config)#interface fastethernet0/1
Switch(config-if)#
- Line模式:
Switch(config)#line console 0
Switch(config-line)#
二、特权模式下的命令:
- 查看交换机MAC地址:
Switch#show mac-address-table
- Cisco发现协议(CDP):
Switch#show cdp Switch#show cdp interface fastethernet0/1 Switch#show cdp neighbors Switch#show cdp neighbors detail Switch#show cdp entry
- 保存交换机配置:
Switch#copy running-config startup-config或者Switch#write
- 恢复交换机出厂值:
Switch#erase startup-config Switch#reload
三、全局配置模式下的命令:
- 配置主机名:
Switch(config)#hostname Sw1
Sw1(config)#
- 设置登陆台密码:
Switch(config)#line console 0
Switch(config-line)#password 密码
Switch(config-line)#login
- 使能口令:
Switch(config)#enable Password 密码
- 加密保存的使能口令:
Switch(config)#enable secret 密码
- 配置IP地址:
Switch(config)#interface vlan 1 Switch(config-if)#ip address IP地址 网关 Switch(config-if)#no shutdown
- 配置交换机网关:
Switch(config)#ip default-gateway 网关
四、VLAN配置命令:
- 创建vlan命令:
- 全局配置模式下:
Switch(config)#vlan 2 Switch(config)#name v2 Switch(config)#mtu 数值 Switch(config)#end
- Vlan数据库下:
Switch#vlan database Switch#vlan 2 name v2 Switch#vlan 2 mut 数值 Switch#exit
- 全局配置模式下:
- 删除vlan命令:
- 全局配置模式下:
Switch(config)#no vlan 2 Switch(config)#end
- Vlan数据库下:
Switch#no vlan 2 name v2 Switch#exit
- 全局配置模式下:
- 在vlan中添加端口:
Switch#config terminal Switch(config)#interface f0/1(端口) Switch(config-if)#Switchport mode access Switch(config-if)#switchport access vlan 2 Switch(config-if)#end # 一次将多个端口添加到vlan中: Switch#config terminal Switch(config)#interface range f0/1 - 5(端口) Switch(config-if)#switchport access vlan 2 Switch(config-if)#end 注:switch#show vlan biref(查看vlan信息)
配置vlan trunk:
- 配置接口为trunk命令:
Switch(config)# interface f0/1(端口) Switch(config-if)#Switchport mode trunk
- 配置接口为动态协商模式的命令:
Switch(config)# interface f0/1(端口) Switch(config-if)#switchport mode dynamic desirable/auto
- 从trunk中删除vlan:
Switch(config)# interface f0/1(端口) Switch(config-if)#Switchport trunk allowed vlan remove 2
- 在trunk中添加vlan:
Switch(config)# interface f0/1(端口) Switch(config-if)#Switchport trunk allowed vlan add 2
- 配置接口为trunk命令:
配置系统基本信息命令
执行命令sysname host-name,设置设备名称
<HUAWEI> system-view
[HUAWEI] sysname Switch
[Switch] undo sysname //恢复主机名到缺省情况
[HUAWEI] quit
执行命令clock datetime设置当前时间和日期
<HUAWEI> clock datetime 08:00:00 2018-12-01
执行命令clock timezone,配置设备所在地区及其对应的时区
<HUAWEI> system-view
[HUAWEI] clock timezone Beijing add 08:00:00
执行命令display clock,查看系统当前日期和时钟
[HUAWEI] display clock
2018-12-01 08:02:30+08:00
Saturday
Time Zone(Beijing) : UTC+08:00
执行命令ip address,配置设备管理IP地址,执行命令ip route-static,配置设备缺省网关
- 对于有管理网口的设备,在管理网口下配置管理IP地址
[HUAWEI] interface MEth 0/0/1 [HUAWEI-MEth0/0/1] ip address 10.10.10.2 255.255.255.0 //设备管理IP [HUAWEI-MEth0/0/1] quit [HUAWEI] ip route-static 0.0.0.0 0 10.10.10.1 //设备缺省网关
- 对于没有管理网口的设备,在Vlanif接口下配置管理IP地址
[HUAWEI] vlan 10
[HUAWEI-vlan10] quit
[HUAWEI] interface Vlanif 10
[HUAWEI-Vlanif10] ip address 10.10.10.2 255.255.255.0 //设备管理IP
[HUAWEI-Vlanif10] quit
[HUAWEI] ip route-static 0.0.0.0 0 10.10.10.1 //设备缺省网关
执行命令display ip interface brief,查看接口上IP地址的简要信息。执行命令display ip routing-table,查看IP路由信息
[HUAWEI] display ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
(E): E-Trunk down
The number of interface that is UP in Physical is 2
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 2
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
NULL0 unassigned up up(s)
Vlanif10 10.10.10.2/24 up up
[HUAWEI] display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 5 Routes : 5
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 Static 60 0 RD 10.10.10.1 Vlanif10
10.0.0.0/8 Direct 0 0 D 10.0.0.1 InLoopBack0
10.0.0.1/32 Direct 0 0 D 10.0.0.1 InLoopBack0
10.10.10.0/24 Direct 0 0 D 10.10.10.2 Vlanif10
10.10.10.2/32 Direct 0 0 D 10.0.0.1 Vlanif10
执行命令ssh user,配置SSH用户相关参数;执行命令local-user,配置本地用户相关参数,实现通过SSH协议登录设备。
<HUAWEI> system-view
[HUAWEI] user-interface vty 0 4
[HUAWEI-ui-vty0-4] authentication-mode aaa //配置VTY用户认证方式为AAA认证
[HUAWEI-ui-vty0-4] protocol inbound ssh //VTY用户界面所支持的协议缺省为SSH协议。
[HUAWEI-ui-vty0-4] quit
[HUAWEI] aaa
[HUAWEI-aaa] local-user admin password irreversible-cipher admin@123 //创建与SSH用户同名的本地用户和对应的登录密码
[HUAWEI-aaa] local-user admin service-type ssh terminal //配置本地用户的服务方式
[HUAWEI-aaa] local-user admin privilege level 15 //配置本地用户级别
[HUAWEI-aaa] quit
[HUAWEI] ssh user admin //创建SSH用户
[HUAWEI] ssh user admin authentication-type password //配置SSH用户的认证方式为password
[HUAWEI] ssh user admin service-type stelnet //配置SSH用户的服务方式
[HUAWEI] stelnet server enable //使能设备的STelnet服务器功能
注意:确保SSH用户名称与本地用户名称相同。
本页面只介绍了使用Password认证方式实现通过STelnet协议登录设备。更多配置Telnet或STelnet协议实现远程登录的详细操作参见配置通过Telnet登录设备或配置通过STelnet登录设备。
执行命令display current-configuration,查看设备当前配置。
<HUAWEI> system-view
[HUAWEI] display current-configuration | include ip
ip address 10.10.10.2 255.255.255.0
ip route-static 0.0.0.0 0.0.0.0 10.10.10.1
查询系统信息的命令(常用!)
display current-configuration
,查看系统配置。display interface brief
,查看接口摘要信息。display clock
,查看系统当前日期和时钟。display ip interface brief
,查看接口上IP地址的简要信息。display ip routing-table
,查看系统路由信息。display user-interface
,查看用户界面的物理属性和配置。display local-user
,查看本地用户列表。display ssh user-information
,在SSH服务器端查看SSH用户信息。display ssh server status
,查看SSH服务器的全局配置信息。display ssh server session
,查看与SSH客户端连接的会话信息。display mac-address
,查看交换机MAC、VLAN下的MAC绑定display interface vlanif1
,显示VLANIF1的MAC地址
参考文档:华为交换机命令总结https://www.cnblogs.com/hftian/p/8858343.html
交换机分类
划分方式 | 交换分类 | 特点 |
---|---|---|
交换方式 | 存储转发 | 存储、校验、延时大 |
直通式 | 直接、不校验、速度快 | 碎片过滤 | 64字节、小的丢弃 | 协议层次 | 二层交换 | MAC地址交换 | 三层交换 | IP地址交换 | 多层交换 | 端口号、协议交换 | 交换结构 | 固定式 | 固定数量端口,如24口 | 模块式 | 预留插槽、插入模块扩展 | 配置方式 | 堆叠式 | 堆叠口、4到9层、统一 | 非堆叠 | 级联、不超4层 | 管理类型 | 网管型 | 支持SNMP和MIB网管协议 | 非网管 | 傻瓜交换机、不需配置 | 智能型 | 支持WEB配置和SNMP、MIB | 适用范围 | 接入层 | 用户接入、多接口 | 汇聚层 | 策略控制ACL、VLAN、QoS | 核心层 | 高速转发、冗余、均衡 |
典型的三层交换机、
- 接入层交换机,如S2700。
- 汇聚层交换机,如S3700。
- 核心层交换机,如S5700
交换机相关计算公式
- 包转发率:端口吞吐率,64字节数据包转发能力,单位 pps(包/秒)。计算公式如下:
- 背板带宽:端口处理器和数据总线之间单位时间内传输的最大数据量。单位Gbps(吉比特/秒)。计算公式如下:
配置交换机的远程登录管理Telnet
[Swltchl]telnet server enable ## Telnet默认是关闭的,需要打开
[Switch1]user-interface vty 0 4 ## 开启VTY线路模式
[Switch1-ui-vtyO-4]protocol inbound telnet ## 配置telnet协议
[Switch1-ui-vtyO-4]authentication-mode aaa ## 配置认证方式
[Switch1-ui-vtyO-4]quit
[Switch1]aaa ## simple明文密码
[Switch1-aaa]local-user admin password cipher Hello@123 ##配置用户名和密码,用户名不区分大小写,密码区分大小写
[Switchi-aaa]local-useradmin privilege level 15 ## 将管理员的账号权限设置为巧
[Swltchl-aaa]quit
[Switchl]quit
<Switch1>save ## 在用户视图下保存配置
配置交换机端口隔离、速率、双工
## 配置接口GEI/0/1和GEI/0/2的端口隔离功能,实现两个接囗之间的二层数据隔离,三层数据互通
<Switchl>system-view
[Switch1]port-isolate mode
[Switch1]Interface gigabitethernet 1/0/1
[Switch1-GigabitEthemet1/0/1]port-isolate enable group 1
[Switch1-GigabitEthernet1/0/1]quit
[Switch1]Interface gigabitethernet1/0/2
[Switch1-GigabitEthemet1/0/2]port-isolate enable group 1
[SwitchI-GigabitEthernet1/0/2]quit
## 配置以太网接口GEO/0/1在自协商模式下协商速率为100Mb/s
<Switchl>system-view
[Switch1]interface gigabitethernet 0/0/1
[Switchl-GigabitEthernet0/0/1]negotiation auto
[Switch1-GigabitEthemet0/0/1]auto speed 100
#配置以太网电接口GEO/0/1在自协商模式下双工模式为全双工模式
<Switchl>system-view
[Switchl]interfaceygabitethernet0/0/1
[Switch1-GigabitEthemet0/0/1]negotiation auto