华为交换机配置脚本

-----------------------------------------------------------------------------------
盒式设备istack https://support.huawei.com/enterprise/zh/doc/EDOC1000069491/5e798e3e#ZH-CN_TASK_0177090980 堆叠口需要交叉连接;2台MAD检测  使用接口下 mad detect direct 并且需要在对应端口关闭STP和LLDP

# 配置SwitchA的业务口GigabitEthernet0/0/27、GigabitEthernet0/0/28为物理成员端口,并加入到相应的逻辑堆叠端口。
system-view
sysname SwitchA
interface stack-port 0/1
port interface gigabitethernet 0/0/27 enable
quit
interface stack-port 0/2
port interface gigabitethernet 0/0/28 enable
quit
stack slot 0 priority 200
save

# 配置SwitchB的业务口GigabitEthernet0/0/27、GigabitEthernet0/0/28为物理成员端口,并加入到相应的逻辑堆叠端口。
system-view
sysname SwitchB
interface stack-port 0/1
port interface gigabitethernet 0/0/27 enable
quit
interface stack-port 0/2
port interface gigabitethernet 0/0/28 enable
quit
stack slot 0 renumber 1
save

# 配置SwitchC的业务口GigabitEthernet0/0/27、GigabitEthernet0/0/28为物理成员端口,并加入到相应的逻辑堆叠端口。
system-view
sysname SwitchC
interface stack-port 0/1
port interface gigabitethernet 0/0/27 enable
quit
interface stack-port 0/2
port interface gigabitethernet 0/0/28 enable
quit
stack slot 0 renumber 2
save

为保证堆叠组建成功,建议按照以下顺序进行连线上电(如果用户希望某台交换机为主交换机可以先为其上电。例如,按以下顺序连线上电后,SwitchA为主交换机):
为SwitchA、SwitchB、SwitchC下电;
连接SwitchA与SwitchB之间的堆叠线缆;
先为SwitchA上电,SwitchA启动后,再为SwitchB上电;
检查SwitchA与SwitchB的堆叠组建是否成功,检查方法请参见步骤4;
与上一步类似,连接SwitchC与SwitchB和SwitchA之间的堆叠线缆,再为SwitchC上电;
检查SwitchA、SwitchB、SwitchC的堆叠组建是否成功,检查方法请参见步骤4。
system-view
display stack

# 在堆叠系统创建Eth-Trunk,并将上行物理端口设置为Eth-Trunk成员接口。

[Stack] interface eth-trunk 10
[Stack-Eth-Trunk10] trunkport gigabitethernet 0/0/5
[Stack-Eth-Trunk10] trunkport gigabitethernet 1/0/5
[Stack-Eth-Trunk10] trunkport gigabitethernet 2/0/5
[Stack-Eth-Trunk10] quit

# 在SwitchD上创建Eth-Trunk,并将与Stack相连的端口设置为Eth-Trunk成员接口。

<HUAWEI> system-view
[HUAWEI] sysname SwitchD
[SwitchD] interface eth-trunk 10
[SwitchD-Eth-Trunk10] trunkport gigabitethernet 0/0/1
[SwitchD-Eth-Trunk10] trunkport gigabitethernet 0/0/2
[SwitchD-Eth-Trunk10] trunkport gigabitethernet 0/0/3
[SwitchD-Eth-Trunk10] quit

# 在堆叠系统上,配置跨设备Eth-Trunk的代理方式多主检测功能。

[Stack] interface eth-trunk 10
[Stack-Eth-Trunk10] mad detect mode relay
[Stack-Eth-Trunk10] return

# 在代理设备SwitchD上,配置Eth-Trunk的代理功能。

[SwitchD] interface eth-trunk 10
[SwitchD-Eth-Trunk10] mad relay     
[SwitchD-Eth-Trunk10] return

display mad verbose
-----------------------------------------------------------------------------------

框式设备CSS https://support.huawei.com/enterprise/zh/doc/EDOC1000069491/7c9e33a7 需要先升级系统和补丁
配置集群连接方式、集群ID及集群优先级

# 在SwitchA上配置集群。集群连接方式为业务口集群,集群优先级为100,集群ID采用缺省值1(不需配置)。
system-view
sysname SwitchA
set css mode lpu
set css priority 100

# 在SwitchB上配置集群。集群连接方式为业务口集群,集群ID为2,集群优先级为10。
system-view
sysname SwitchB
set css mode lpu
set css id 2
set css priority 10

display css status saved

# 配置SwitchA的业务口XGE1/0/1~XGE1/0/2为集群物理成员端口并加入集群端口1,XGE2/0/1~XGE2/0/2为集群物理成员端口并加入集群端口2。

[SwitchA] interface css-port 1
[SwitchA-css-port1] port interface xgigabitethernet 1/0/1 to xgigabitethernet 1/0/2 enable
[SwitchA-css-port1] quit
[SwitchA] interface css-port 2
[SwitchA-css-port2] port interface xgigabitethernet 2/0/1 to xgigabitethernet 2/0/2 enable
[SwitchA-css-port2] quit

# 配置SwitchB的业务口XGE1/0/1~XGE1/0/2为集群物理成员端口并加入集群端口1,XGE2/0/1~XGE2/0/2为集群物理成员端口并加入集群端口2。

[SwitchB] interface css-port 1
[SwitchB-css-port1] port interface xgigabitethernet 1/0/1 to xgigabitethernet 1/0/2 enable
[SwitchB-css-port1] quit
[SwitchB] interface css-port 2
[SwitchB-css-port2] port interface xgigabitethernet 2/0/1 to xgigabitethernet 2/0/2 enable
[SwitchB-css-port2] quit

display css css-port saved

# 使能SwitchA的集群功能并重新启动SwitchA。

[SwitchA] css enable
Warning: The CSS configuration will take effect only after the system is rebooted. The next CSS mode is LPU. Reboot now? [Y/N]:y

# 使能SwitchB的集群功能并重新启动SwitchB。

[SwitchB] css enable
Warning: The CSS configuration will take effect only after the system is rebooted. The next CSS mode is LPU. Reboot now? [Y/N]:y

配置多主检测功能(此处选择代理方式进行配置,将SwitchC作为代理设备。命令行格式以V200R003C00及之后的版本为例)
# 在集群系统上配置Eth-Trunk接口的代理方式多主检测功能。
<CSS> system-view
[CSS] interface eth-trunk 20
[CSS-Eth-Trunk20] mad detect mode relay           //V200R002C00版本命令行格式为dual-active detect mode relay
[CSS-Eth-Trunk20] quit
[CSS] quit
# 配置代理设备SwitchC的代理功能。
[SwitchC] interface eth-trunk 20
[SwitchC-Eth-Trunk20] mad relay                    //V200R002C00版本命令行格式为dual-active relay
[SwitchC-Eth-Trunk20] quit
[SwitchC] quit
-----------------------------------------------------------------------------------
#基础配置 配置时间 时区 主机名
<HUAWEI> clock timezone BJ add 08:00:00    //其中BJ为设置的时区名称。08:00:00表示当地时间是在系统默认的UTC时区基础上加8。
<HUAWEI> clock datetime 10:10:00 2014-07-26    //设置当前时间和日期。设置当前时间前,请务必确认所在时区,设置正确的时区偏移时间,以保证本地时间正确。
<HUAWEI> system-view
[HUAWEI] sysname Switch
#产生密钥对
[Switch] rsa local-key-pair create
#打开HTTPS服务
[Switch] http secure-server enable   //缺省情况下,设备的HTTPS IPv4服务功能已开启,HTTPS IPv6服务功能为关闭状态
[Switch] http server-source -i Ethernet0/0/0    //缺省情况下,未指定HTTP服务器端的源接口和IPv6源地址。
#创建管理员 指定登录方式和权限
[Switch] aaa
[Switch-aaa] local-user admin123 password irreversible-cipher Huawei@6789    //创建名为admin123的本地用户,设置其登录密码为Huawei@6789。V200R003之前的版本,不支持irreversible-cipher,仅支持cipher关键字。
[Switch-aaa] local-user admin123 privilege level 15    //配置用户级别为15级。
Warning: This operation may affect online users, are you sure to change the user privilege level ?[Y/N]y   
[Switch-aaa] local-user admin123 service-type telnet terminal stelnet https  //配置接入类型为telnet,即:Telnet用户。
[Switch-aaa] quit
#创建管理VLAN
[Switch] vlan 10
[Switch-vlan10] description  MGMT
[Switch-vlan10]  interface vlanif 10    //配置VLANIF10作为管理接口。
[Switch-Vlanif10] ip address 10.1.1.1 24
[Switch-Vlanif10] quit
#管理口接管理PC
[Switch] interface gigabitethernet 0/0/10    //GE0/0/10为使用Web网管登录Switch的PC与Switch相连的物理接口编号,请按照实际现网情况进行选择。
[Switch-GigabitEthernet0/0/10] description  TO_MGMT_PC
[Switch-GigabitEthernet0/0/10] port link-type access    //配置接口类型为access。
[Switch-GigabitEthernet0/0/10] port default vlan 10    //配置接口GE0/0/10加入VLAN 10。
[Switch-GigabitEthernet0/0/10] quit
#设置ACL仅允许管理PC远程访问
[Switch] acl 2008
[Switch-acl-basic-2008] rule permit source 10.1.1.2 0
[Switch-acl-basic-2008] quit
#打开SSH服务
[Switch] stelnet server enable    //使能STelnet服务器功能。
[Switch] ssh server-source -i Vlanif 10    //配置服务器端的源接口为10.1.1.1对应的接口,假设该接口为Vlanif 10。
#指定SSH登录用户
[Switch] ssh user admin123 authentication-type password    //配置SSH用户admin123的认证方式为Password认证。
[Switch] ssh user admin123 service-type stelnet    //配置SSH用户admin123的服务方式为STelnet。
#打开Telnet服务
[Switch] telnet server enable    //使能Telnet功能。
[Switch] telnet server-source -i Vlanif 10    //配置服务器端的源接口为10.1.1.1对应的接口,假设该接口为Vlanif 10。
#设置远程登录端口,认证方式,登录权限,ACL和超时时间
[Switch] user-interface vty 0 4    //进入VTY 0~VTY 4用户界面视图。
[Switch-ui-vty0-4] protocol inbound all    //指定VTY用户界面所支持的协议为Telnet。
[Switch-ui-vty0-4] acl 2008 inbound    //配置只允许满足ACL 2008规则的VTY 0~VTY 14用户登录本设备。
[Switch-ui-vty0-4] user privilege level 15    //配置VTY 0~VTY 4的用户级别为15级。
[Switch-ui-vty0-4] authentication-mode aaa    //配置VTY 0~VTY 4的用户认证方式为AAA认证。
[Switch-ui-vty0-4]
[Switch-ui-vty0-4] quit
#设置console口登录方式为本地用户名密码
[Switch] user-interface console 0
[Switch-ui-console0] authentication-mode aaa    //设置Console用户认证方式为AAA认证。
[Switch-ui-console0] quit
#定义Log服务器 记录时间戳和日志等级
[Switch]info-center enable
Info: Information center is enabled.
[Switch]info-center timestamp log date precision-time millisecond                      !log日志日期格式精确到毫秒
[Switch]info-center timestamp trap date precision-time millisecond                     !trap 日期格式精确到毫秒
[Switch]info-center timestamp debugging date precision-time millisecond                !debug输出时间格式精确到毫秒
[Switch]info-center loghost source Vlanif4
[Switch]info-center loghost 1.1.1.1 facility local2 level debugging local-time  !定义日志服务器IP地址和日志记录等级为debugging
Warning: There is security risk as this operation enables a non secure syslog protocol.
#定义DNS 主要是用于NTP解析域名,如果NTP直接指定URL则不需要配置DNS
[Switch]dns server 114.114.114.114
[Switch]dns server 223.5.5.5
[Switch]dns resolve
[Switch]#
#打开NTP客户端,并指定2个NTP时间服务器,这里如果上面配置了DNS则这里可以使用URL
[Switch]undo ntp disable
[Switch]ntp source-interface Vlanif4
[Switch]ntp unicast-server 202.112.29.82
[Switch]ntp unicast-server 202.120.2.101
#打开LLDP
[Switch]lldp enable
[Switch]lldp management-address bind interface Vlanif4
#配置MSTP 如果是核心交换机则指定为STP根,数据中心情况下建议打开BPDU保护
[Switch]stp mode mstp
[Switch]stp region-configuration
[Switch-mst-region] region-name wangsu
[Switch-mst-region] active region-configuration
[Switch-mst-region] quit
[Switch]stp root primary
[Switch]stp enable
[Switch]stp bpdu-protection
#配置SNMP V2 V3
[Switch]snmp-agent
[Switch]snmp-agent mib-view included iso-view iso
[Switch]snmp-agent community read cipher Admin@huawei mib-view iso-view     !配置snmp v2c只读团体关键字
[Switch]snmp-agent sys-info version v2c v3                              !配置snmp 版本为v2c 和 v3

[Switch]snmp-agent protocal source-interface vlan 100                   !必须配置 否则业务不通
Warning: SNMPv1/SNMPv2c is not secure, and SNMPv3 in either authentication or privacy mode is recommended.
[Switch]snmp-agent group v3 managev3group privacy read-view iso-view    !创建只读组managev3group
[Switch]snmp-agent usm-user v3 admin group managev3group            !将用户cncwangsu加入managev3group组
[Switch]snmp-agent usm-user v3 admin authentication-mode md5        !认证模式为md5
Please configure the authentication password (8-255)                                  !输入认证秘钥
Enter Password:
Confirm Password:
Warning: The algorithm is insecure. Using a security algorithm is recommended.
[Switch]snmp-agent usm-user v3 admin privacy-mode des56
Please configure the privacy password (8-255)
Enter Password:
Confirm Password:
Warning: The privacy and authentication passwords are the same, which is insecure. It is recommended that the privacy and authentication passwords be different.
Warning: DES56 is less secure, and it is recommended to use AES128 or higher.
[Switch]#
#配置snmp-agent
[Switch]snmp-agent trap enable
[Switch]undo snmp-agent trap enable feature-name snmp trap-name authenticationfailure
[Switch]snmp-agent trap source Vlanif4
[Switch]snmp-agent target-host trap address udp-domain 1.1.1.1 params securityname Admin@huawei v3 privacy
#配置边缘端口
[Switch]int 10 1/0/7
[Switch-10GE1/0/7] stp edged-port enable
[Switch-10GE1/0/7]int range 10 1/0/10 to 10 1/0/48
[Switch-port-group] stp edged-port enable
exit
ip route-static 0.0.0.0 0.0.0.0 192.168.5.1
#创建聚合口将端口放入聚合口
[S12700E-8] interface Eth-Trunk1
[S12700E-8-Eth-Trunk1] trunkport gigabitethernet 1/1/0/46
[S12700E-8-Eth-Trunk1] trunkport gigabitethernet 2/1/0/46
[S12700E-8-Eth-Trunk1] port link-type access
[S12700E-8-Eth-Trunk1] port default vlan 1202
[S12700E-8-Eth-Trunk1] quit
[S12700E-8] interface Eth-Trunk2
[S12700E-8-Eth-Trunk2] trunkport gigabitethernet 1/1/0/47
[S12700E-8-Eth-Trunk2] trunkport gigabitethernet 2/1/0/47
[S12700E-8-Eth-Trunk2] port link-type access
[S12700E-8-Eth-Trunk2] port default vlan 1203
[S12700E-8-Eth-Trunk2] quit
[Switch-port-group]comm
Committing.
-----------------------------------------------
#系统升级操作;PC作为FTP服务器,需要提前将新的版本系统文件和补丁放到FTP根目录
企业用户:登录http://support.huawei.com/e,在搜索栏中输入交换机型号,单击搜索栏中联想出的路径,进入对应的产品页面,单击“软件”,选择版本,进入“版本及补丁”页签下路径,获取升级需要的版本系统软件(.cc)。
企业用户:登录http://support.huawei.com/e,在搜索栏中输入交换机型号,单击搜索栏中联想出的路径,进入对应的产品页面,单击“软件”,选择版本,进入“VR版本公共补丁”页签下路径,获取升级需要的补丁(.pat)。
<HUAWEI> system-view
[HUAWEI] interface vlanif 1
[HUAWEI-vlanif1] ip address 10.10.1.1 24    //10.10.1.1/24为配置的VLANIF接口IP地址,按照实际现网情况进行选择,确保与PC处于同一网段。
[HUAWEI-vlanif1] quit

<HUAWEI> ftp 10.10.1.2    //10.10.1.2为终端PC的IP地址。
[ftp] get S5720-HI-V200R010C00SPC600.cc    //加载系统软件到交换机中,S5720-HI-V200R010C00SPC600.cc为系统软件的文件名。
[ftp] get S5720-HI-V200R010SPH013.pat    //加载补丁文件到交换机中,S5720-HI-V200R010SPH013.pat为系统补丁的文件名。

<HUAWEI> dir flash:    //执行dir命令查看加载文件大小和PC的文件是否相同。如果不相同,删除该文件重新加载。
Directory of flash:/                                                            
                                                                                
  Idx  Attr     Size(Byte)  Date        Time       FileName                     
    0  -rw-    106,395,444  Jul 22 2017 23:44:18   S5720-HI-V200R010C00SPC600.cc
    1  -rw-          84210  Jun 28 2017 05:16:29   S5720-HI-V200R010SPH013.pat
    2  drw-              -  Jan 01 2017 00:00:44   dhcp                         
    3  drw-              -  Dec 03 2013 09:22:27   user                         
    4  -rw-         13,432  Jan 01 2017 00:00:45   default_ca.cer  

<HUAWEI> startup system-software S5720-HI-V200R010C00SPC600.cc    //设置下次启动的系统软件。
<HUAWEI> startup patch S5720-HI-V200R010SPH013.pat    //设置下次启动的补丁。

如果为双主控的框式设备,在用户视图使用以下命令设置备用主控板使用的系统软件和补丁。

copy S5720-HI-V200R010C00SPC600.cc slave#flash:
startup system-software S5720-HI-V200R010C00SPC600.cc slave-board
startup patch S5720-HI-V200R010SPH013.pat slave-board

<HUAWEI> display startup  
 MainBoard:
  Configured startup system software:        flash:/defaultdevicesoft.cc
  Startup system software:                   flash:/defaultdevicesoft.cc
  Next startup system software:              flash:/S5720-HI-V200R010C00SPC600.cc
  Startup saved-configuration file:          flash:/vrpcfg.zip
  Next startup saved-configuration file:     flash:/vrpcfg.zip
  Startup paf file:                          default
  Next startup paf file:                     default
  Startup license file:                      default
  Next startup license file:                 default
  Startup patch package:                     flash:/patch.pat
  Next startup patch package:                flash:/S5720-HI-V200R010SPH013.pat
 
<HUAWEI> reboot fast                                                             
Info: If want to reboot with saving diagnostic information, input 'N' and then e
xecute 'reboot save diagnostic-information'.                                    
System will reboot! Continue?[Y/N]: y  

<HUAWEI> display startup 查看当前运行版本(Configured startup system software)是否为升级的目标版本。
<HUAWEI> display patch-information 查看补丁名(Patch Package Name)和补丁版本(Patch Package Version)是否为需要加载的补丁;查看补丁状态(State)是否正常运行(Running)。
<HUAWEI> check version 查看是否有显示需要升级的软件。如果回显有内容,则可以执行upgrade all命令升级该软件。
<HUAWEI> display device 查看部件是否在位(Online)、注册状态(Register),以及运行状态(Status)。
---------------------------------------------------------------------------------
#COMBO接口选择
<HUAWEI> system-view
[HUAWEI] sysname Switch
[Switch] interface gigabitethernet 1/0/4
[Switch-GigabitEthernet1/0/4] combo-port copper   //缺省情况下,Combo接口工作模式为auto,修改为电口模式。
[Switch-GigabitEthernet1/0/4] quit
#配置三层口
interface GigabitEthernet1/0/1
undo portswitch     
ip address 10.10.1.1 255.255.255.0
undo portswitch batch gigabitethernet 1/0/2 to 1/0/4
---------------------------------------------------------------------------------
#二层端口隔离技术
用如下的思路配置端口隔离:。
    设备缺省端口隔离为二层隔离三层互通,只需要将接口加入到隔离组中,就可以实现隔离组内接口之间二层数据的隔离。
    <HUAWEI> system-view
    [HUAWEI] sysname Switch
    [Switch] vlan 10
    [Switch-vlan10] quit
    [Switch] interface gigabitethernet 1/0/1
    [Switch-GigabitEthernet1/0/1] port link-type access   //配置GE1/0/1的接口类型为access。
    [Switch-GigabitEthernet1/0/1] port default vlan 10   //配置GE1/0/1加入VLAN 10。
    [Switch-GigabitEthernet1/0/1] port-isolate enable   //缺省加入端口隔离组1,且隔离模式为二层隔离三层互通。可以在系统视图下执行port-isolate mode all命令配置隔离模式为二层三层都隔离。
    [Switch-GigabitEthernet1/0/1] quit
    # 配置GE1/0/2的端口隔离功能。
    [Switch] interface gigabitethernet 1/0/2
    [Switch-GigabitEthernet1/0/2] port link-type access   //配置GE1/0/2的接口类型为access。
    [Switch-GigabitEthernet1/0/2] port default vlan 10   //配置GE1/0/2加入VLAN 10。
    [Switch-GigabitEthernet1/0/2] port-isolate enable   //缺省加入端口隔离组1,且隔离模式为二层隔离三层互通。可以在系统视图下执行port-isolate mode all命令配置隔离模式为二层三层都隔离。
    [Switch-GigabitEthernet1/0/2] quit
    # 配置GE1/0/3加入VLAN10。
    [Switch] interface gigabitethernet 1/0/3
    [Switch-GigabitEthernet1/0/3] port link-type access   //配置GE1/0/3的接口类型为access。
    [Switch-GigabitEthernet1/0/3] port default vlan 10   //配置GE1/0/3加入VLAN 10。
    [Switch-GigabitEthernet1/0/3] quit
    验证配置结果
    # PC1和PC2数据报文不能互通。
    # PC1和PC3数据报文可以互通。
    # PC2和PC3数据报文可以互通。
---------------------------------------------------------------------------------
#配置MAC地址黑洞
<HUAWEI> system-view
[HUAWEI] sysname Switch
[Switch] vlan 3   //创建VLAN 3
[Switch-vlan3] quit
[Switch] mac-address blackhole xxxx-xxxx-xxx5 vlan 3   //配置MAC地址0005-0005-0005在VLAN 3的广播域内为黑洞MAC地址
---------------------------------------------------------------------------------
#配置端口聚合 静态聚合
vlan batch 10 20
#
interface Eth-Trunk1
 port link-type trunk
 port trunk allow-pass vlan 10 20
 load-balance src-dst-mac
#
interface GigabitEthernet1/0/1
 eth-trunk 1
#
interface GigabitEthernet1/0/2
 eth-trunk 1
#
interface GigabitEthernet1/0/3
 eth-trunk 1
------------------------------------------------------------------------------
#配置端口聚合 动态聚合
vlan batch 10 20
#
lacp priority 100
#
interface Eth-Trunk1
 port link-type trunk
 port trunk allow-pass vlan 10 20
 mode lacp
 max active-linknumber 2
#
interface GigabitEthernet1/0/1
 eth-trunk 1
 lacp priority 100
#
interface GigabitEthernet1/0/2
 eth-trunk 1
 lacp priority 100
#
------------------------------------------------------------------------------
#创建VLAN  ACCESS  TRUNK口
<HUAWEI> system-view
[HUAWEI] sysname SwitchA
[SwitchA] vlan batch 2 3   //批量创建VLAN 2和VLAN 3
[SwitchA] interface gigabitethernet 1/0/1
[SwitchA-GigabitEthernet1/0/1] port link-type access  //和接入设备相连的接口类型必须是access,接口默认类型不是access,需要手动配置为access
[SwitchA-GigabitEthernet1/0/1] port default vlan 2   //将接口GE1/0/1加入VLAN 2
[SwitchA-GigabitEthernet1/0/1] quit
[SwitchA] interface gigabitethernet 1/0/2
[SwitchA-GigabitEthernet1/0/2] port link-type access
[SwitchA-GigabitEthernet1/0/2] port default vlan 3   //将接口GE1/0/2加入VLAN 3
[SwitchA-GigabitEthernet1/0/2] quit

配置SwitchA上与SwitchB连接的接口类型及通过的VLAN。SwitchB的配置与SwitchA类似,不再赘述

[SwitchA] interface gigabitethernet 1/0/3
[SwitchA-GigabitEthernet1/0/3] port link-type trunk   //交换机之间相连接口类型建议使用trunk,接口默认类型不是trunk,需要手动配置为trunk
[SwitchA-GigabitEthernet1/0/3] port trunk allow-pass vlan 2 3    //将接口GE1/0/3加入VLAN 2和VLAN 3
------------------------------------------------------------------------------
#在Switch上配置静态ARP表项
[Switch] arp static 10.164.1.1 00e0-fc01-0001 vid 10 interface gigabitethernet 1/0/1 //为总裁办公室主机配置静态ARP表项
[Switch] arp static 10.164.10.1 00e0-fc02-1234 interface gigabitethernet 1/0/2 //为文件备份服务器配置静态ARP表项
------------------------------------------------------------------------------
#DHCP服务器配置
[Switch] vlan batch 10

[Switch] interface gigabitethernet 1/0/1
[Switch-GigabitEthernet1/0/1] port link-type hybrid
[Switch-GigabitEthernet1/0/1] port hybrid pvid vlan 10
[Switch-GigabitEthernet1/0/1] port hybrid untagged vlan 10
[Switch-GigabitEthernet1/0/1] quit

[Switch] interface vlanif 10
[Switch-Vlanif10] ip address 10.1.1.1 25
[Switch-Vlanif10] quit

[Switch] ip pool pool1
[Switch-ip-pool-pool1] network 10.1.1.0 mask 255.255.255.128
[Switch-ip-pool-pool1] dns-list 10.1.2.3
[Switch-ip-pool-pool1] gateway-list 10.1.1.1
[Switch-ip-pool-pool1] lease day 10
[Switch-ip-pool-pool1] quit

[Switch] interface vlanif 10
[Switch-Vlanif10] dhcp select global
[Switch-Vlanif10] quit
#DHCP relay 配置
[SwitchA] dhcp enable  //使能DHCP服务,缺省未使能
[SwitchA] interface vlanif 100
[SwitchA-Vlanif100] ip address 10.10.20.1 24
[SwitchA-Vlanif100] dhcp select relay   //使能DHCP中继功能,缺省未使能
[SwitchA-Vlanif100] dhcp relay server-ip 192.168.20.2  //配置DHCP中继代理的DHCP服务器的IP地址
[SwitchA-Vlanif100] quit
------------------------------------------------------------------------------
#策略路由
[Switch] acl 3000   //主要用于匹配内网两个网段之间互访的数据流,这部分数据流不需要做重定向,如果不配置这一步会导致内网之间互访的流量也被重定向,从而导致内网互访不通。
[Switch-acl-adv-3000] rule permit ip source 192.168.1.0 0.0.0.255 destination 192.168.2.0 0.0.0.255
[Switch-acl-adv-3000] rule permit ip source 192.168.2.0 0.0.0.255 destination 192.168.1.0 0.0.0.255
Switch-acl-adv-3000] quit
[Switch] acl 3001   //匹配内网192.168.1.0/24网段的数据流
[Switch-acl-adv-3001] rule permit ip source 192.168.1.0 0.0.0.255
[Switch-acl-adv-3001] quit
[Switch] acl 3002   //匹配内网192.168.2.0/24网段的数据流
[Switch-acl-adv-3002] rule permit ip source 192.168.2.0 0.0.0.255
[Switch-acl-adv-3002] quit
配置流分类
在Switch上创建流分类c0、c1、c2,匹配规则分别为ACL 3000、ACL 3001和ACL 3002。
[Switch] traffic classifier c0 operator or
[Switch-classifier-c0] if-match acl 3000
[Switch-classifier-c0] quit
[Switch] traffic classifier c1 operator or
[Switch-classifier-c1] if-match acl 3001
[Switch-classifier-c1] quit
[Switch] traffic classifier c2 operator or
[Switch-classifier-c2] if-match acl 3002
[Switch-classifier-c2] quit
配置流行为
# 在Switch上创建流行为b0、b1、b2,对于b0只配置permit的动作,对于b1和b2分别指定重定向到10.1.20.1和10.1.30.1的动作。
[Switch] traffic behavior b0
[Switch-behavior-b0] permit
[Switch-behavior-b0] quit
[Switch] traffic behavior b1
[Switch-behavior-b1] redirect ip-nexthop 10.1.20.1
[Switch-behavior-b1] quit
[Switch] traffic behavior b2
[Switch-behavior-b2] redirect ip-nexthop 10.1.30.1
[Switch-behavior-b2] quit
配置流策略并应用到接口上
# 在Switch上创建流策略p1,将流分类和对应的流行为进行绑定。
[Switch] traffic policy p1
[Switch-trafficpolicy-p1] classifier c0 behavior b0
[Switch-trafficpolicy-p1] classifier c1 behavior b1
[Switch-trafficpolicy-p1] classifier c2 behavior b2
[Switch-trafficpolicy-p1] quit
# 将流策略p1应用到Switch的GE1/0/3的入方向上。
[Switch] interface gigabitethernet 1/0/3
[Switch-GigabitEthernet1/0/3] traffic-policy p1 inbound
[Switch-GigabitEthernet1/0/3] return
------------------------------------------------------------------------------
配置ARP防网关冲突
[Switch] arp anti-attack gateway-duplicate enable  //配置ARP防网关冲突
------------------------------------------------------------------------------
#配置DHCP SNOOPING
[SwitchA] dhcp enable
[SwitchA] dhcp snooping enable ipv4  //使能全局DHCP Snooping功能并配置设备仅处理DHCPv4报文,节约设备的CPU利用率
[SwitchA] interface gigabitethernet 0/0/2
[SwitchA-GigabitEthernet0/0/2] dhcp snooping enable  //使能用户侧接口的DHCP Snooping功能
[SwitchA-GigabitEthernet0/0/2] quit
[SwitchA] interface gigabitethernet 0/0/3
[SwitchA-GigabitEthernet0/0/3] dhcp snooping enable
[SwitchA-GigabitEthernet0/0/3] quit
[SwitchA] interface gigabitethernet 0/0/1
[SwitchA-GigabitEthernet0/0/1] dhcp snooping trusted  //配置为信任接口,使得接入交换机只处理从该接口收到的DHCP服务器响应报文
[SwitchA-GigabitEthernet0/0/1] quit
------------------------------------------------------------------------------
#配置端口安全
[Switch] interface gigabitethernet 1/0/1
[Switch-GigabitEthernet1/0/1] port-security enable   //使能端口安全功能
[Switch-GigabitEthernet1/0/1] port-security mac-address sticky   //使能端口安全后,才可以再使能sticky MAC功能
[Switch-GigabitEthernet1/0/1] port-security max-mac-num 1   //使能端口安全后,接口默认限制数为1,如果确认限制一个用户,可以不用配置
------------------------------------------------------------------------------
#端口镜像 本地M:N
<HUAWEI> system-view
[HUAWEI] sysname Switch
[Switch] observe-port 1 interface-range gigabitethernet 1/0/4 gigabitethernet 1/0/5     //批量配置GE1/0/4~GE1/0/5为本地观察端口
[Switch] interface gigabitethernet 1/0/1
[Switch-GigabitEthernet1/0/1] port-mirroring to observe-port 1 both    //将接口GE1/0/1的出入方向绑定到索引为1的观察端口上
[Switch-GigabitEthernet1/0/1] quit
[Switch] interface gigabitethernet 1/0/2
[Switch-GigabitEthernet1/0/2] port-mirroring to observe-port 1 both     //将接口GE1/0/2的出入方向绑定到索引为1的观察端口上
[Switch-GigabitEthernet1/0/2] quit
[Switch] interface gigabitethernet 1/0/3
[Switch-GigabitEthernet1/0/3] port-mirroring to observe-port 1 both     //将接口GE1/0/3的处入方向绑定到索引为1的观察端口上
[Switch-GigabitEthernet1/0/3] return
#VLAN 镜像
[Switch] observe-port 1 interface gigabitethernet 0/0/4     //配置GE0/0/4为本地观察端口,观察端口索引为1
[Switch] vlan 10
[Switch-vlan10] mirroring to observe-port 1 inbound     //VLAN10内所有接口入方向的报文镜像到索引为1的观察端口上
[Switch-vlan10] return
#远程镜像
<HUAWEI> system-view
[HUAWEI] sysname SwitchB
[SwitchB] vlan 20
[SwitchB-vlan20] mac-address learning disable     //关闭该VLAN的MAC地址学习功能
[SwitchB-vlan20] quit
[SwitchB] interface gigabitethernet 0/0/1
[SwitchB-GigabitEthernet0/0/1] port link-type access     //设置监控设备侧接口链路类型为access,接口缺省链路类型不是access口
[SwitchB-GigabitEthernet0/0/1] port default vlan 20
[SwitchB-GigabitEthernet0/0/1] quit
[SwitchB] interface gigabitethernet 0/0/4
[SwitchB-GigabitEthernet0/0/4] port link-type trunk
[SwitchB-GigabitEthernet0/0/4] port trunk allow-pass vlan 20     //设置网络侧接口链路类型为trunk,接口缺省链路类型不是trunk口
[SwitchB-GigabitEthernet0/0/4] return

[SwitchA] observe-port 1 interface gigabitethernet 0/0/4 vlan 20     //配置GE0/0/4为二层远程观察端口,观察端口索引为1,绑定的VLAN为VLAN20
[SwitchA] vlan 10
[SwitchA-vlan10] mirroring to observe-port 1 inbound     //VLAN10内所有接口入方向的报文镜像到索引为1的观察端口上
[SwitchA-vlan10] return
------------------------------------------------------------------------------

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值