欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

简单易懂!快速了解华为交换机的基础操作指南

最编程 2024-02-21 11:59:49
...

华为交换机的基本使用

########################
一、基础

· 进入系统配置模式
    <Huawei> system-view                          #普通用户模式,进入系统视图
    [Huawei]                                                #系统配置模式

· 修改交换机名称
    [Huawei] sysname 新名
    [Huawei] sysname SW                           #将设备命名为SW
    [SW]

· 返回普通模式
    [SW] return
    <SW>

· 查看配置
  - 查看保存的启动配置
    <SW> display saved-configuration
  - 查看当前配置
    <SW> display current-configuration
  - 查看当前所在命令行的配置信息
    <SW> display this
    <SW> system-view
    [SW] display this
    [SW] user-interface console 0
    [SW-ui-console0] display this
    
· 保存配置
    <SW> save
    
· 删除全局配置
    <SW> reset saved-configuration
    
· 修改系统时间
    <SW> display clock                                                         #查看当前时间
    <SW> clock datetime HH:MM:SS YYYY-MM-DD             #设置时间 时:分:秒 年-月-日
    
· 配置设备说明信息
    [SW] header login information "登陆信息"
    [SW] header shell information "shell会话的开始信息"
    
· 用户管理
  1) 配置密码
    ① 配置密码password方式
        
    ② 配置密码aaa方式
      · aaa = authentication(认证) + authorization(授权) + accounting(计费)
      · aaa是网络安全的一种管理机制
      · authentication是本地认证/授权
      · authorization和accounting是由远处radius(远程拨号认证系统)服务或hwtacacs(华为终端访问控制系统)服务器完成认证授权
        [SW] aaa                                                                                  #启用aaa
        [SW-aaa] local-user 用户名@域名 password cipher 密码            #创建新用户并配置密码
        [SW-aaa] local-user 用户名@域名 service-typy ssh                    #指定用户的服务类型,如ssh、telnet、http等
        [SW-aaa] local-user 用户名@域名 privilege level 等级                #设置用户密码与特权等级
            #等级说明:默认1
            # level 0 : 访问级,执行网络诊断等功能的命令(ping/tracert/telnet)
            # level 1 : 监控级,执行系统维护/业务故障诊断的命令(denug/terminal)
            # level 2 : 系统级,执行业务配置的命令(路由网络层命令),向用户提供网络服务
            # level 3 : 管理级,*,运行所有命令(文件系统/FTP/TFTP/XModem/用户管理/级别设置)
            # 某些设备用户等级有0-15,其中15相当于level3

        [SW-aaa] quit                                              #返回上级菜单

例:
<Huawei>sys
[Huawei]aaa
[Huawei-aaa]local-user test@abc.com password cipher PassWord
Info: Add a new user.
[Huawei-aaa]local-user test@abc.com service-type ssh
[Huawei-aaa]local-user test@abc.com privilege level 15

   
  2)配置超级密码
    [SW] super password simple 密码               #简单超级密码
    [SW] super password cipher 密码               #复杂超级密码
    
  2) 配置console密码
    [SW] user-interface console 0                                                  #进入console配置模式
    [SW-ui-console0] authentication-mode password                    #设置认证方式为密码
     Please configure the login password (maximum length 16):    #设置密码
    [SW-ui-console0] set authtication password cipher 密码          #修改密码
    [SW-ui-console0] idle-timeout 分钟数 秒数                              #设置空闲超时时间
    [SW-ui-console0] quit
    
  3) 配置vty的密码允许ssh服务
    [SW] user-interface vty 0 4                                            #虚拟终端,允许4个并发连接
    [SW-ui-vty0-4] authentication-mode aaa                      #设置模式
    [SW-ui-vty0-4] protocol inbound ssh                            #设置用户入境协议
    [SW-ui-vty0-4] quit
    
  4) 创建公钥
    [SW]rsa local-key-pair create                                    #创建本地rsa密钥对
     The key name will be: Host
     % RSA keys defined for Host already exist.
     Confirm to replace them? (y/n)[n]:y                        #是否重建密钥对,有个默认的
     The range of public key size is (512 ~ 2048).
     NOTES: If the key modulus is greater than 512,
            It will take a few minutes.
     Input the bits in the modulus[default = 512]:1024          #设置密钥对长度
     Generating keys...
     ..........................++++++
     .++++++
     .............++++++++
     .++++++++
    [SW] ssh user 用户名 authentication-type password          #配置用户ssh验证类型
    
· 启用交换机的web服务
    <SW> dir                                              #列出全部文件,注意记录web包的文件名
    <SW> system-view                               #进入系统视图
    [SW] http server load web包名               #导入http服务对应的包
    [SW] http secure-server enable              #启动服务
    

##########################
二、VLAN

· 创建vlan
    [SW] vlan 编号                                            #编号范围1~4094
    [SW] vlan batch 编号1 编号2 编号n              #批量创建分别指定id
    [SW] vlan batch 编号开始 to 编号结束          #批量创建指定范围id
    [SW] vlan 11
    [SW] vlan batch 20 30 40
    [SW] vlan batch 50 to 60
    [SW] vlan batch 100 110 120 to 125
    [SW] display this
    [SW] display vlan                             #查看vlan
    
· 删除vlan
  ① 清理vlan中的端口
    [~SW] display vlan 30                                     #查看vlan信息
    [~SW] interface ge1/0/30                               #进入vlan中的端口
    [~SW-GE1/0/30] undo port link-type              #取消端口连接类型,关闭相关配置
    [~SW-GE1/0/30] quit
  ② 清理vlanif信息
    [~SW] interface Vlanif 30
    [~SW-Vlanif30] display this
    [~SW-Vlanif30] undo ip address
    [~SW-Vlanif30] quit
    [~SW] undo interface Vlanif 30                  #取消vlan端口
    [*SW] commit
  ③ 删除vlan
    [~SW] undo vlan 30                                  #取消vlan
    [*SW] commit                                           #提交
    [~SW] display vlan                                    #显示vlan信息
    
· 设置端口类型
    [SW] interface GigabitEthernet 0/0/1                                  #进入端口
    [SW-GigabitEthernet0/0/1] port link-type access                 #设置端口类型为接入
    [SW-GigabitEthernet0/0/1] port link-type trunk                  #设置端口类型为中继
    [SW-GigabitEthernet0/0/1] display this                               #查看当前配置
    
· 批量管理端口(端口组)
    [SW] port-group 组名                                                                                  #进入端口组
    [SW-port-group-组名] group-member GigabitEthernet0/0/11 to g0/0/15    #设置组成员
    [SW-port-group-组名] 端口操作
    
· 将端口加入vlan
    [SW] interface g0/0/1
    [SW-GigabitEthernet0/0/1] port default vlan 30          #将端口加入vlan30
     报错: 因为接口trunk模式不能加入vlan,要转为access
    [SW-GigabitEthernet0/0/1] port link-type access         #转为access模式
    [SW-GigabitEthernet0/0/1] port default vlan 50          #将端口加入vlan50
    
· vlan中端口模式access转为trunk
    [SW-GigabitEthernet0/0/1] port link-type trunk            #
     Error: Please renew the default configurations.            #报错
    [SW-GigabitEthernet0/0/1] undo port default vlan        #取消端口的vlan,将端口移出vlan
    [SW-GigabitEthernet0/0/1] port link-type trunk            #转换

· 允许通过trunk链接的vlan
    [SW-GigabitEthernet0/0/1] port trunk allow-pass vlan 编号1 编号2     #需要进入trunk所在端口操作,允许全部all

· 给vlan配置ip
    [SW] interface vlanif 30                                                   #进入vlan30
    [SW-Vlanif30] ip address 192.168.4.1 255.255.255.0          #设置ip
    [SW-Vlanif30] display this
    [SW-Vlanif30] display ip interface vlanif 30                      #查看vlan端口信息
    
· 给端口配置ip
    <SW> system-view                                          #进入系统视图
    [SW] inter g1/0/0                                             #进入端口
    [~SW-GE1/0/0] undo portswitch                      #使用路由模式,端口取消交换机端口模式
    [*SW-GE1/0/0] ip address 192.168.4.254 24       #设置端口ip
    [*SW-GE1/0/0] description 端口说明                  #可以为端口添加说明文件
    [*SW-GE1/0/0] undo shutdown                        #启动端口,取消关闭
    [*SW-GE1/0/0] commit                                    #提交修改,*表示有修改未保存
    [~SW-GE1/0/0] display this                              #显示当前区域配置
    [~SW-GE1/0/0] display ip interface brief          #显示ip端口摘要
    

################    
三、网络

· 显示ip端口信息摘要
    [~SW] display ip interface brief
    
· 显示路由信息表
    [~SW] display ip routing-table
    
· 访问控制列表ACL
    [~SW] acl ?
      INTEGER<2000-2999>    基本访问列表(添加到当前使用规则),只能匹配源ip
      INTEGER<23000-23999>  ARP(地址解析协议)访问列表
      INTEGER<3000-3999>    高级访问列表(添加到当前使用规则),可匹配源ip、目标ip、源端口、目标端口等三层和四层的字段
      INTEGER<4000-4999>    指定一个L2的ACL组(添加到当前使用规则)
      INTEGER<5000-5999>    用户定义的访问列表
      ip-pool               指定ip地址池
      ipv6                  IPV6的ACL
      name                  命名acl
      number                指定acl编号
      port-pool             指定端口池
  - 注意事项:
    ① 一个接口的同一个方向,只能调用一个acl
    ② 一个acl中可以有多个rule规则,从上往下依次执行
    ③ 匹配即停止,数据包一旦被某rule匹配,就不再向下匹配
    ④ 用来做数据包访问时,默认隐含放过所有(华为设备)

  - acl的两种作用:
    ① 用来对数据包做访问控制(丢弃或放行)
    ② 结合其他协议,用来匹配范围
    
  - 基本acl
    [SW] acl 编号
    [SW-acl-basic-编号] rule [编号] <deny|permit> source 源ip 反掩码         #设置基本acl规则,不指定编号则以5的倍数插入
    [SW-acl-basic-编号] rule 编号 description "规则描述"                             #设置acl的规则描述
    [SW-acl-basic-编号] display this                                                            #查看当前规则
    [SW-acl-basic-编号] interface GigabitEthernet 端口号                            #进入出/入站端口
    [SW-端口] traffic-filer <outbound|inbound> acl <acl编号|acl名>           #设置接口出/入站方向调用acl
    [SW-端口] display this
    [SW] display acl 编号                                                                            #查看acl规则
    例:
        [SW]acl 2345
        [SW-acl-basic-2345] rule deny source 192.168.4.1 0                  #拒绝源ip通过
        [SW-acl-basic-2345] rule deny source 192.168.5.0 0.0.0.255      #拒绝源ip段通过
        [SW-acl-basic-2345] rule 7 permit source 192.168.5.1 0            #允许源ip通过
        [SW-acl-basic-2345] rule 7 description "allowed host ip"          #规则7的描述
        [SW-acl-basic-2345] display this                                              #查看当前区域配置
            #
            acl number 2345
             rule 5 deny source 192.168.4.1 0                #默认以5的倍数为id插入
             rule 7 permit source 192.168.5.1 0             #指定编号则在指定位置插入规则
             rule 7 description "allowed host ip"
             rule 10 deny source 192.168.5.0 0.0.0.255
            #
        [SW-acl-basic-2345] interface g0/0/1                                       #进入端口
        [SW-GigabitEthernet0/0/1] traffic-filter outbound acl 2345      #出站调用acl
        [SW-GigabitEthernet0/0/1]display this
            #
            interface GigabitEthernet0/0/1
             traffic-filter outbound acl 2345
            #
        [SW-GigabitEthernet0/0/1] display acl 2345                      #查看acl规则
        
  - 高级acl
    [SW] acl 编号
    [SW-acl-adv-编号] rule [编号] <deny|permit|description> <协议> 源 目标
    [SW-acl-adv-编号] int g端口号
    [SW-端口] traffic-filer <outbound|inbound> acl <acl编号|acl名>
    例:
        [SW]acl 3456
        [SW-acl-adv-3456] rule deny icmp source 192.168.10.0 0.0.0.255 destination any
            //拒绝192.168.10.0网段ping任何主机
        [SW-acl-adv-3456] rule deny tcp source 192.168.10.1 0 destination 172.16.0.1 0 destination-port eq 80
            //拒绝192.168.10.1访问172.16.0.1的80端口
        [SW-acl-adv-3456] rule deny tcp source 192.168.10.2 0 destination 172.16.0.2 0 destination-port eq telnet
            //拒绝192.168.10.2访问172.16.0.2的telnet服务
        [SW-acl-adv-3456] display this
            #
            acl number 3456
             rule 5 deny icmp source 192.168.10.0 0.0.0.255
             rule 10 deny tcp source 192.168.10.1 0 destination 172.16.0.1 0 destination-port eq www
             rule 15 deny tcp source 192.168.10.1 0 destination 172.16.0.1 0 destination-port eq telnet
            #
        [SW-acl-adv-3456] inter g0/0/2
        [SW-GigabitEthernet0/0/2] traffic-filter outbound acl 3456
    例:只允许某ip远程进入终端
        [SW] acl number 2999
        [SW-acl-basic-2999] rule permit source 12.3.4.5 0
        [SW-acl-basic-2999] rule deny
        [SW-acl-basic-2999] user-interface vty 0 4
        [SW-ui-vty0-4] acl 2999 inbound
        
  - 使用acl策略
    【acl规则】
    [SW] acl 3001
    [SW-acl-adv-3001] rule deny ip source 192.168.3.0 0.0.0.255 destination 172.31.0.0 0.0.0.255
    [SW-acl-adv-3001] display acl 3001                          #查看acl3001规则
    [SW-acl-adv-3001] quit
     
    【acl分类】
    [SW] traffic classifier tc1                                         #交通 分类 名
    [SW-classifier-tc1] if-match acl 3001                       #假如-匹配 acl 编号
    [SW-classifier-tc1] display traffic classifier user-defined
    [SW-classifier-tc1] quit
     
    【acl行为】默认是permit
    [SW] traffic behavior tb1                                   #交通 行为 名
    [SW-behavior-tb1] deny
    [SW-behavior-tb1] display traffic behavior user-defined
    [SW-behavior-tb1] quit
     
    【acl策略】
    [SW] traffic policy tp1                                                        #交通 策略 名
    [SW-trafficpolicy-tp1] classifier tc1 behavior tb1                 #绑定 分类 策略
    [SW-trafficpolicy-tp1] display traffic policy user-defined
    [SW-trafficpolicy-tp1] quit
     
    【在指定接口应用策略】
    [SW] int GigabitEthernet 0/0/2                                           #进入应用端口
    [SW-GigabitEthernet0/0/2] traffic-policy tp1 inbound        #交通-策略 名 入站方向调用
    [SW-GigabitEthernet0/0/2] quit
    [SW] display traffic-policy applied-record
        
  - 删除acl规则
    -- 删除前必须取消对acl规则的应用
    [SW] display current-configuration                                                  #确认acl规则应用在哪里
    [SW] interface g0/0/2                                                                      #进入应用acl的端口
    [SW-GigabitEthernet0/0/2] display this                                            #查看当前区域配置
    [SW-GigabitEthernet0/0/2] undo traffic-filter outbound acl 3456     #取消端口对acl的调用
    [SW-GigabitEthernet0/0/1] acl 3456                                                #进入acl
    [SW-acl-adv-3456] undo rule 10                                                     #删除acl中的某一条
    [SW-acl-adv-3456] quit
    [SW] undo acl 3456                                                                        #删除acl规则
    

· 华为路由器默认协议优先级
    路由协议或路由种类                   优先级
    Direct(直连)                                0
    OSPF(开放最短路径优先)             10
    IS-IS(中间系统到中间系统协议)     15
    Static(静态)                                60
    RIP(路由信息协议)                      100
    OSPF ASE                                 150
    BGP(边界网关协议)                    255
 

· 配置静态路由

 [*HUAWEI] ip route-static 192.168.100.0  24      192.168.4.254    #指定静态路由
          \\ 关键字         被访问地址端     反掩码    下一跳地址

· 配置动态路由ospf

 [R2] ospf 1
 [R2-ospf-1] area 0
 [R2-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255

· 引入外部路由

 [R3-ospf-1] default-route-advertise always 

· 链路聚合(EtherChannel)