华为交换机学习
参考资料:
https://blog.csdn.net/hnjb5873/article/details/88773904
https://blog.csdn.net/weixin_43815140/article/details/104803603
一、基础配置命令
1、用户模式
登陆设备后,直接进入用户模式,尖括号表示用户模式
,在这个模式下只能执行少量查看配置的命令;
<Huawei>
2、视图模式
用户模式下,输入system-view或者sys进入视图模式,方括号表示视图模式
,可执行设备全局配置的命令;
<Huawei>system-view
Enter system view, return user view with Ctrl+Z.
[Huawei]
3、交换机改名
[Huawei]sysname switch01 #改交换机名字
[switch01]
Oct 16 2020 16:02:51-08:00 switch01 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011
.5.25.191.3.1 configurations have been changed. The current change number is 4,
the change loop count is 0, and the maximum number of records is 4095.
Oct 16 2020 16:02:51-08:00 switch01 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011
.5.25.191.3.1 configurations have been changed. The current change number is 4,
the change loop count is 0, and the maximum number of records is 4095.
这个提示信息,比较烦人。每次更改了什么配置都会显示出来,影响调试。可以使用下面的命令关闭掉
undo terminal monitor
4、进入接口
[switch01]int g0/0/1
[switch01-GigabitEthernet0/0/1]
5、退出此端口
q
二、创建vlan并将端口加入vlan
1、创建vlan
创建单个vlan
[HUAWEI]vlan 10 #创建vlan10,创建后会自动进入vlan10
[HUAWEI-vlan2]q
批量创建vlan
[HUAWEI]vlan batch 3 to 10 #批量建立vlan,3-10
Info: This operation may take a few seconds. Please wait for a moment...done.
[HUAWEI] #批量建立vlan后不会进入vlan
2、更改端口的链接类型
由于华为交换机的端口出厂时默认都是hybrid类型
或auto类型
的,所以无法立即加入vlan,需要更改端口的link-type
后,才可以加入vlan。单个端口更改方式如下:
[HUAWEI]int g0/0/1
[HUAWEI-GigabitEthernet0/0/1]port link-type access
为何要选择access类型??
因为我们是终端PC与交换机相连,要求PC只能只能和上级交换机通信,所以必须只属于1个vlan
以太网端口的链路类型有三种:
- Access 类型:端口只能属于1 个VLAN,一般用于交换机与终端用户之间的连接;
- Trunk 类型:端口可以属于多个VLAN,可以接收和发送多个VLAN 的报文,一般用于交换机 之间的连接;
- Hybrid 类型:端口可以属于多个VLAN,可以接收和发送多个VLAN 的报文,可以用于交换 机之间连接,也可以用于连接用户的计算机。Hybrid 端口可以允许多个VLAN 的报文发送时不携带标签,而Trunk 端口只允许缺省VLAN 的报文,发送时不携带标签。
trunk
端口用于交换机相连,pvid必须一致。access
类型只能属于1 个vlan- 规模较大的企业局域网,不建议使用vlan1,所以trunk端口不允许vlan1通过
3、端口加入vlan
[HUAWEI-GigabitEthernet0/0/1] port default vlan 10 #端口1加入vlan10
以上的操作是单个操作,如果配置端口比较多就很麻烦,下面我们来批量操作。
4、端口的批量操作——端口组
原理就是创建一个端口组,把要更改的端口加入到端口组中,然后统一更改类型加入vlan。也可以理解为群组端口,统一配置类型加入vlan.
批量更改,先更改端口类型,再统一加入某个vlan,如下:
port-group pokes #pokes是端口组名
[swh-port-group-pokes]group-member GigabitEthernet 0/0/1 to GigabitEthernet 0/0/2
port link-type access 设置为access模式
port default vlan 3 加入vlan3[swh]vlan 10 #创建vlan10
[swh-vlan10]q
[swh]port-group pokes #pokes是端口组名
[swh-port-group-pokes]group-member GigabitEthernet 0/0/1 to GigabitEthernet 0/0/2 #把1、2两个端口加入到端口组中
[swh-port-group-pokes]port link-type access #更改组的端口类型
[swh-GigabitEthernet0/0/1]port link-type access #自动生成行
[swh-GigabitEthernet0/0/2]port link-type access #自动生成行
[swh-port-group-pokes]port default vlan 10 #端口组加入vlan10
[swh-GigabitEthernet0/0/1]port default vlan 10 #自动生成行
[swh-GigabitEthernet0/0/2]port default vlan 10 #自动生成行
5、vlan的查看
全局查看vlan信息
[swh]dis vlan #查看vlan信息
The total number of vlans is : 2
--------------------------------------------------------------------------------
U: Up; D: Down; TG: Tagged; UT: Untagged;
MP: Vlan-mapping; ST: Vlan-stacking;
#: ProtocolTransparent-vlan; *: Management-vlan;
--------------------------------------------------------------------------------VID Type Ports
--------------------------------------------------------------------------------
1 common UT:GE0/0/3(U) GE0/0/4(U) GE0/0/5(D) GE0/0/6(D) GE0/0/7(D) GE0/0/8(D) GE0/0/9(D) GE0/0/10(D) GE0/0/11(D) GE0/0/12(D) GE0/0/13(D) GE0/0/14(D) GE0/0/15(D) GE0/0/16(D) GE0/0/17(D) GE0/0/18(D) GE0/0/19(D) GE0/0/20(D) GE0/0/21(D) GE0/0/22(D) GE0/0/23(D) GE0/0/24(D) 10 common UT:GE0/0/1(U) GE0/0/2(U) VID Status Property MAC-LRN Statistics Description
--------------------------------------------------------------------------------1 enable default enable disable VLAN 0001
10 enable default enable disable VLAN 0010
查看端口与vlan对应关系
[swh]display port vlan
Port Link Type PVID Trunk VLAN List
-------------------------------------------------------------------------------
GigabitEthernet0/0/1 access 10 -
GigabitEthernet0/0/2 access 10 -
GigabitEthernet0/0/3 hybrid 1 -
GigabitEthernet0/0/4 hybrid 1 -
GigabitEthernet0/0/5 hybrid 1 -
GigabitEthernet0/0/6 hybrid 1 -
GigabitEthernet0/0/7 hybrid 1 -
GigabitEthernet0/0/8 hybrid 1 -
GigabitEthernet0/0/9 hybrid 1 -
GigabitEthernet0/0/10 hybrid 1 -
GigabitEthernet0/0/11 hybrid 1 -
GigabitEthernet0/0/12 hybrid 1 -
GigabitEthernet0/0/13 hybrid 1 -
GigabitEthernet0/0/14 hybrid 1 -
GigabitEthernet0/0/15 hybrid 1 -
GigabitEthernet0/0/16 hybrid 1 -
GigabitEthernet0/0/17 hybrid 1 -
GigabitEthernet0/0/18 hybrid 1 -
GigabitEthernet0/0/19 hybrid 1 -
GigabitEthernet0/0/20 hybrid 1 -
GigabitEthernet0/0/21 hybrid 1 -
GigabitEthernet0/0/22 hybrid 1 -
GigabitEthernet0/0/23 hybrid 1 -
GigabitEthernet0/0/24 hybrid 1 -
6、允许所有vlan通过
[switch01-port-group-link-type]port trunk allow-pass
三、首次登入交换机或路由器
第一次上电和恢复出厂是一样的,我们先说一下恢复出厂设置。
1、恢复出厂设置
注意Y和N的选项,不要输错。
<S1>reset saved-configuration
Warning: The action will delete the saved configuration in the device.
The configuration will be erased to reconfigure. Continue? [Y/N]:y<S1>reboot
Info: The system is now comparing the configuration, please wait.
Warning: The configuration has been modified, and it will be saved to the next startup saved-configuration file . Continue? [Y/N]:nInfo: If want to reboot with saving diagnostic information, input 'N' and then execute 'reboot save diagnostic-information'.
System will reboot! Continue?[Y/N]:y
2、设置新密码
新交换机第一次上电,或恢复出厂设置后,要求设置新密码
出厂自带的用户名是admin,密码是admin@huawei.com
Login authenticationUsername:admin
Password:
Warning: The default password poses security risks.
The password needs to be changed. Change now? [Y/N]: y
Please enter old password:
Please enter new password: --------------输入密码时没有任何显示
Please confirm new password:
The password has been changed successfully.
3、首次保存配置
第一次保存设置时,需输入文件名,只需按回车
<HUAWEI>save
The current configuration will be written to the device.
Are you sure to continue?[Y/N]y
Info: Please input the file name ( *.cfg, *.zip ) [vrpcfg.zip]:
May 28 2019 10:57:52 HUAWEI %%01CFM/4/SAVE(s)[1]:The user chose Y when deciding whether to save the configuration to the device.
flash:/vrpcfg.zip exists, overwrite?[Y/N]:y
May 28 2019 10:57:54 HUAWEI %%01CFM/4/OVERWRITE_FILE(s)[2]:When deciding whether to overwrite the configuration file vrpcfg.zip, the user chose Y.
Now saving the current configuration to the slot 0......
Save the configuration successfully.
4、设置日期和时间
<HUAWEI>clock datetime 10:46:30 2019-05-28
设置console口的连接方式,可设置为无,仅密码,用户名密码等方式
[HUAWEI]user-interface console 0
[HUAWEI-ui-console0]authentication-mode ?aaa AAA authentication, and this authentication mode is recommendednone Login without checkingpassword Authentication through the password of a user terminal interface[HUAWEI-ui-console0]set authentication password[HUAWEI-ui-console0]set authentication password cipher administrator
5、开启必要的服务和功能
开启telnet服务,stp功能,http服务
[HUAWEI]telnet server enable #开启telnet服务
[HUAWEI]stp mode rstp #设置stp模式为rstp
[HUAWEI]stp enable #开启stp功能
[HUAWEI]http server enable #开启http服务(默认就是开启的)
6、设置vty,telnet登录
[HUAWEI]user-interface maximum-vty 15 #vty界面最大值15authentication-mode password #认证模式设置为仅需密码,也可设置为aaa模式user privilege level 15 #用户权限级别15(非常重要)set authentication password cipher $1a$IZ,o~LZ$Z.$GHlQ-zn9-Gn<*8(yp-@F#6wmH;M\%L#($\PXNa.:$---此处是密码,输入时是明文,根据需要设置history-command max-size 256 #命令行最大历史记录idle-timeout 6 0 #用户超时时间6分0秒screen-length 100 #屏幕长度100行protocol inbound telnet #允许telnet协议进入(非常重要)
7、设置一个用户用于网页登录
[HUAWEI]aaa
[HUAWEI-aaa]dis local-user----------------------------------------------------------------------------User-name State AuthMask AdminLevel ----------------------------------------------------------------------------admin A MH 15 ----------------------------------------------------------------------------Total 1 user(s)
[HUAWEI-aaa]undo local-user admin
Error: Have user(s) online, can not be deleted.
[HUAWEI-aaa]quit
由于第一次登录时,console口要求用户名密码登录,所以无法删除本地用户admin,此时可退到<>视图,保存设置,退出交换机,再重新登录。由于我们已经将console口的认证方式改为仅需密码,所以可以再次进入aaa,删除用户admin。删除后,再建立admin,权限,服务类型等,均可由我们自己控制。
[HUAWEI]aaa
[HUAWEI-aaa]undo local-user admin
[HUAWEI-aaa]local-user admin password irreversible-cipher administrator idle-timeout 6 0 #administrator为密码,根据需要设置
Info: Add a new user.
[HUAWEI-aaa]local-user admin service-type http
[HUAWEI-aaa]local-user admin privilege level 15
Warning: This operation may affect online users, are you sure to change the user privilege level ?[Y/N]y
[HUAWEI-aaa]local-user admin ftp-directory flash:
如遇更新版本的交换机软件,telnet服务要求必须是aaa认证(用户名密码认证),可按上面所述再建立一个用户,service-type设置为telnet。
8、关闭交换机自动弹出配置改变告警
输入配置命令后设备会提示如下类似信息:
DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.191.3.1 configurations have been changed. The current change number is 1, the change loop count is 64, and the maximum number of records is 1.
这个是配置改变的告警提示信息,不是错误信息,可以配置如下命令屏蔽此信息:
[HUAWEI]info-center source DS channel console trap level warning state off
四、设置链路聚合
[HUAWEI]interface Eth-Trunk 1
[HUAWEI-Eth-Trunk1]port link-type trunk
Info: This operation may take a few seconds. Please wait for a moment...done.
[HUAWEI-Eth-Trunk1]port trunk pvid vlan 10
[HUAWEI-Eth-Trunk1]port trunk allow-pass vlan 2 to 4000
Info: This operation may take a few seconds. Please wait a moment....done.
[HUAWEI-Eth-Trunk1]undo port trunk allow-pass vlan 1
Info: This operation may take a few seconds. Please wait a moment...done.
[HUAWEI-Eth-Trunk1]dis this
#
interface Eth-Trunk1port link-type trunkport trunk pvid vlan 10undo port trunk allow-pass vlan 1port trunk allow-pass vlan 2 to 4000
#
return
以上命令建立一个聚合端口,并设置了端口的属性
[HUAWEI]interface GigabitEthernet 0/0/25
[HUAWEI-GigabitEthernet0/0/25]eth-trunk 1
Info: This operation may take a few seconds. Please wait a moment...done.
以上命令将G 0/0/25端口加入聚合端口eth-trunk 1,无需更多设置。可将更多的端口加入聚合端口。
五、交换机DHCP
开启DHCP功能,设置地址池,并应用
[HUAWEI]dhcp enableip pool 192.168.2.0 #建立一个地址池,名为192.168.2.0gateway-list 192.168.2.254 #设置网关地址network 192.168.2.0 mask 255.255.255.0 #设置网段excluded-ip-address 192.168.2.251 192.168.2.253 #设置不参与分配的IP地址范围lease day 0 hour 0 minute 30 #设置租期时长dns-list 114.114.114.114 8.8.8.8 #设置dns地址[HUAWEI]interface Vlanif 2 #进入vlanif 2
[HUAWEI-Vlanif2]ip address 192.168.2.254 24 #给vlanif 2 设置IP地址(就是上面地址池的网关地址)
[HUAWEI-Vlanif2]dhcp select global #DHCP选择全局,会自动匹配地址池
六、开启流控制功能,限制某些网段互链
主要是限制访客网与办公网、财务网互访
[HUAWEI]acl number 3001 #添加一个高级ACL,可控制源地址和目的地址
Info: When the ACL that is referenced by SACL is modified, the SACL will be dynamically updated. During the update, these SACL will become invalid temporarily.
[HUAWEI-acl-adv-3001]rule 1000 deny ip source 172.16.0.0 0.0.255.255 destination 192.168.0.0 0.0.255.255
[HUAWEI-acl-adv-3001]rule 1100 deny ip source 172.16.0.0 0.0.255.255 destination 175.40.0.0 0.0.255.255
[HUAWEI-acl-adv-3001]quit
注意源地址和目的地址的反向掩码
[HUAWEI]traffic-filter inbound acl 3001 #在全局层面应用ACL 3000里面的规则