为了让大家更加清楚,每行代码都有解释。
一、华为交换机基础配置命令
1、创建vlan:
[quidway] vlan 10 //创建vlan 10,并进入vlan10配置视图,如果vlan10存在就直接进入vlan10配置视图
[quidway-vlan10] quit //回到配置视图
[quidway] vlan 100 //创建vlan 100,并进入vlan100配置视图,如果vlan10存在就直接进入vlan100配置视图
[quidway-vlan100] quit //回到配置视图
2、将端口加入到vlan中:
[quidway] interface gigabitethernet2/0/1 (10g光口)
[quidway- gigabitethernet2/0/1] port link-type access //定义端口传输模式
[quidway- gigabitethernet2/0/1] port default vlan 100 //将端口加入vlan100
[quidway- gigabitethernet2/0/1] quit //回到配置视图
[quidway] interface gigabitethernet1/0/0 //进入1号插槽上的第一个千兆网口配置视图中。0代表1号口
[quidway- gigabitethernet1/0/0] port link-type access //定义端口传输模式
[quidway- gigabitethernet2/0/1] port default vlan 10 //将这个端口加入到vlan10中
[quidway- gigabitethernet2/0/1] quit
3、将多个端口加入到vlan中
[quidway]vlan 10
[quidway-vlan10]port gigabitethernet 1/0/0 to 1/0/29 //将0到29号口加入到vlan10中
[quidway-vlan10]quit
4、交换机配置ip地址
[quidway] interface vlanif100 // 进入vlan100接口视图与vlan 100命令进入的地方不同
[quidway-vlanif100] ip address 119.167.200.90 255.255.255.252 // 定义vlan100管理ip三层 交换网关路由
[quidway-vlanif100] quit //返回视图
[quidway] interface vlanif10 // 进入vlan10接口视图与vlan 10命令进入的地方不同
[quidway-vlanif10] ip address 119.167.206.129 255.255.255.128 // 定义vlan10管理ip三层交换网关路由
[quidway-vlanif10] quit
5、配置默认网关:
[quidway]ip route-static 0.0.0.0 0.0.0.0 119.167.200.89 //配置默认网关。
6、 交换机保存设置和重置命令
7、交换机常用的显示命令
用户视图模式下:
8、恢复交换机出厂设置
二、h3c交换机的基本配置
我们先来了解下h3c的配置命令与功能,都是常用的,基本上大部分网络配置都少不了这些命令。
1、基本配置
[h3c] sysname xxx //设置主机名成为xxx这里使用修改特权用户密码
2、用户配置
[h3c]super password h3c //设置用户分级密码
[h3c]undo superpassword //删除用户分级密码
[h3c]localuser bigheap 1234561 //web网管用户设置,1为管理级用户
[h3c]undo localuser bigheap //删除web网管用户
[h3c]user-interface aux 0 //只支持0
[h3c-aux]idle-timeout 250 //设置超时为2分50秒,若为0则表示不超时,默认为5分钟
[h3c-aux]undoidle-timeout //恢复默认值
[h3c]user-interface vty 0 //只支持0和1
[h3c-vty]idle-timeout 250 //设置超时为2分50秒,若为0则表示不超时,默认为5分钟
[h3c-vty]undoidle-timeout //恢复默认值
[h3c-vty]set authentication password123456 //设置telnet密码,必须设置
[h3c-vty]undo set authenticationpassword //取消密码
[h3c]displayusers //显示用户
[h3c]displayuser-interface //用户界面状态
3、vlan配置
[h3c]vlan 2 //创建vlan2
[h3c]undo vlanall //删除除缺省vlan外的所有vlan,缺省vlan不能被删除
[h3c-vlan2]port ethernet 0/4 to ethernet0/7 //将4到7号端口加入到vlan2中,此命令只能用来加access端口,不能用来增加trunk或者hybrid端口
[h3c-vlan2]port-isolate enable //打开vlan内端口隔离特性,不能二层转发,默认不启用该功能
[h3c-ethernet0/4]port-isolate uplink-portvlan 2 //设置4为vlan2的隔离上行端口,用于转发二层数据,只能配置一个上行端口,若为trunk,则建议允许所有vlan通过,隔离不能与汇聚同时配置
[h3c]display vlan all //显示所有vlan的详细信息
[h3c]user-group 20 //创建user-group 20,默认只存在user-group 1
[h3c-usergroup20]port ethernet 0/4 toethernet 0/7 //将4到7号端口加入到vlan20中,初始时都属于user-group 1中
[h3c]display user-group 20 //显示user-group 20的相关信息
四、交换机ip配置
[h3c]vlan 20 //创建vlan
[h3c]management-vlan 20 //管理vlan
[h3c]interface vlan-interface 20 //进入并管理vlan20
[h3c]undo interface vlan-interface 20 //删除管理vlan端口
[h3c-vlan-interface20]ip address192.168.1.2 255.255.255.0 //配置管理vlan接口静态ip地址
[h3c-vlan-interface20]undo ipaddress //删除ip地址
[h3c-vlan-interface20]ip gateway 192.168.1.1 //指定缺省网关(默认无网关地址)
[h3c-vlan-interface20]undo ip gateway
[h3c-vlan-interface20]shutdown //关闭接口
[h3c-vlan-interface20]undo shutdown //开启
[h3c]display ip //显示管理vlan接口ip的相关信息
[h3c]display interface vlan-interface20 //查看管理vlan的接口信息
5、dhcp客户端配置
[h3c-vlan-interface20]ip address dhcp-alloc // 管理vlan接口通过dhcp方式获取ip地址
[h3c-vlan-interface20]undo ip address dhcp-alloc // 取消
[h3c]display dhcp //显示dhcp客户信息
6、端口配置
[h3c]interface ethernet0/3 //进入端口
[h3c-ethernet0/3]shutdown //关闭端口
[h3c-ethernet0/3]speed 100 //速率可为10,100,1000和auto(缺省)
[h3c-ethernet0/3]duplexfull //双工,可为half,full和auto,光口和汇聚后不能配置
[h3c-ethernet0/3]flow-control //开启流控,默认为关闭
[h3c-ethernet0/3]broadcast-suppression 20 //设置抑制广播百分比为20%,可取5,10,20,100,缺省为100,同时组播和未知单播也受此影响
[h3c-ethernet0/3]loopback internal //内环测试
[h3c-ethernet0/3]port link-type trunk //设置链路的类型为trunk
[h3c-ethernet0/3]port trunk pvid vlan 20 //设置20为该trunk的缺省vlan,默认为1(trunk线路两端的pvid必须一致)
[h3c-ethernet0/3]port access vlan 20 //将当前access端口加入指定的vlan
[h3c-ethernet0/3]port trunk permit vlanall //允许所有的vlan通过当前的trunk端口,可多次使用该命令
[h3c-ethernet0/3]mdiauto //设置以太端口为自动监测,normal为直通线,across为交叉线
[h3c]link-aggregation ethernet 0/1 toethernet 0/4 //将1-4口加入汇聚组,1为主端口,两端需要同时配置,设置了端口镜像以及端口隔离的端口无法汇聚
[h3c]undo link-aggregation ethernet 0/1 //删除该汇聚组
[h3c]link-aggregation mode egress //配置端口汇聚模式为根据目的mac地址进行负荷分担,可选为 ingress,egress和both,缺省为both
[h3c]monitor-port ethernet 0/2 //将该端口设置为镜像端口,必须先设置镜像端口,删除时必须先删除被镜像端口,而且它们不能同在一个端口,该端口不能在汇聚组中,设置新镜像端口时,新取代旧,被镜像不变
[h3c]mirroring-port ethernet 0/3 toethernet 0/4 both //将端口3和4设置为被镜像端口,both为同时监控接收和发送的报文,inbound表示仅监控接收的报文,outbound表示仅监控发送的报文
[h3c]display mirror
[h3c]display interface ethernet 0/3
[h3c]display link-aggregation ethernet0/3 //显示端口汇聚信息
[h3c-ethernet0/3]virtual-cable-test //诊断该端口的电路状况
7、qos优先级配置
qos配置步骤:设置端口的优先级,设置交换机信任报文的优先级方式,队列调度,端口限速
[h3c-ethernet0/3]priority 7 //设置端口优先级为7,默认为0
[h3c]priority-trustcos //设置交换机信任报文的优先级方式为cos(802.1p优先级,缺省值),还可以设为dscp方式
[h3c]queue-scheduler hq-wrr 2 4 6 8 //设置队列调度算法为hq-wrr(默认为wrr),权重为2,4,6,8
[h3c-ethernet0/3]line-rate inbound 29 //将端口进口速率限制为2mbps,取1-28时,速率为rate*8*1024/125,即64,128,192…1.792m;
29-127时,速率为(rate-27)*1024,即2m,3m,4m…100m。
[h3c]displayqueue-scheduler //显示队列调度模式及参数
[h3c]displaypriority-trust //显示优先级信任模式
三、锐捷交换机基础命令配置
连接上交换机后,肯定是需要进行命令配置,我们来看下基础命令配置。
1、准备命令
>enable //进入特权模式
#exit //返回上一级操作模式
#end //返回到特权模式
#copy running-config startup-config //保存配置文件
#del flash:config.text //删除配置文件(交换机及1700系列路由器)
#erase startup-config //删除配置文件(2500系列路由器)
#del flash:vlan.dat //删除vlan配置信息(交换机)
#configure terminal //进入全局配置模式
(config)# hostname switcha //配置设备名称为switcha
(config)#banner motd & //配置每日提示信息 &为终止符
(config)#enable secret level 1 0 star //配置远程登陆密码为star
(config)#enable secret level 15 0 star //配置特权密码为star
level 1为普通用户级别,可选为1~15,15为最高权限级别;0表示密码不加密
(config)#enable services web-server //开启交换机web管理功能
services 可选以下:web-server(web管理)、telnet-server(远程登陆)等
2、查看信息
#show running-config //查看当前生效的配置信息
#show interface fastethernet 0/3 //查看f0/3端口信息
#show interface serial 1/2 //查看s1/2端口信息
#show interface //查看所有端口信息
#show ip interface brief //以简洁方式汇总查看所有端口信息
#show ip interface //查看所有端口信息
#show version //查看版本信息
#show mac-address-table //查看交换机当前mac地址表信息
#show running-config //查看当前生效的配置信息
#show vlan //查看所有vlan信息
#show vlan id 10 //查看某一vlan (如vlan10)的信息
#show interface fastethernet 0/1 //查看某一端口模式(如f 0/1)
#show aggregateport 1 summary //查看聚合端口ag1的信息
#show spanning-tree //查看生成树配置信息
#show spanning-tree interface fastethernet 0/1 //查看该端口的生成树状态
#show port-security //查看交换机的端口安全配置信息
#show port-security address //查看地址安全绑定配置信息
#show ip access-lists listname //查看名为listname的列表的配置信息
3、端口的基本配置
(config)#interface fastethernet 0/3 //进入f0/3的端口配置模式
(config)#interface range fa 0/1-2,0/5,0/7-9 //进入f0/1、f0/2、f0/5、f0/7、f0/8、f0/9的端口配置模式
(config-if)#speed 10 //配置端口速率为10m,可选10,100,auto
(config-if)#duplex full //配置端口为全双工模式,可选full(全双工),half(半双式),auto(自适应)
(config-if)#no shutdown //开启该端口
(config-if)#switchport access vlan 10 //将该端口划入vlan10中,用于vlan
(config-if)#switchport mode trunk //将该端口设为trunk模式,可选模式为access , trunk
(config-if)#port-group 1 //将该端口划入聚合端口ag1中,用于聚合端口
4、聚合端口的创建
(config)# interface aggregateport 1 //创建聚合接口ag1
(config-if)# switchport mode trunk //配置并保证ag1为 trunk 模式
(config)#int f0/23-24
(config-if-range)#port-group 1 //将端口(端口组)划入聚合端口ag1中
5、生成树
配置多生成树协议:
switch(config)#spanning-tree //开启生成树协议
switch(config)#spanning-tree mst configuration //建立多生成树协议
switch(config-mst)#name ruijie //命名为ruijie
switch(config-mst)#revision 1 //设定校订本为1
switch(config-mst)#instance 0 vlan 10,20 //建立实例0
switch(config-mst)#instance 1 vlan 30,40 //建立实例1
switch(config)#spanning-tree mst 0 priority 4096 //设置优先级为4096
switch(config)#spanning-tree mst 1 priority 8192 //设置优先级为8192
switch(config)#interface vlan 10
switch(config-if)#vrrp 1 ip 192.168.10.1 //此为vlan 10的ip地址
switch(config)#interface vlan 20
switch(config-if)#vrrp 1 ip 192.168.20.1 //此为vlan 20的ip地址
switch(config)#interface vlan 30
switch(config-if)#vrrp 2 ip 192.168.30.1 //此为vlan 30的ip地址(另一三层交换机)
switch(config)#interface vlan 40
switch(config-if)#vrrp 2 ip 192.168.40.1 //此为vlan 40的ip地址(另一三层交换机)
6、vlan的基本配置
(config)#vlan 10 //创建vlan10
(config-vlan)#name vlanname // 命名vlan为vlanname
(config-if)#switchport access vlan 10 //将该端口划入vlan10中
某端口的接口配置模式下进行
(config)#interface vlan 10 //进入vlan 10的虚拟端口配置模式
(config-if)# ip address 192.168.1.1 255.255.255.0 //为vlan10的虚拟端口配置ip及掩码,二层交换机只能配置一个ip,此ip是作为管理ip使用,例如,使用telnet的方式登录的ip地址
(config-if)# no shutdown //启用该端口
7、端口安全
(config)# interface fastethernet 0/1 //进入一个端口
(config-if)# switchport port-security //开启该端口的安全功能
a、配置最大连接数限制
(config-if)# switchport port-secruity maxmum 1 //配置端口的最大连接数为1,最大连接数为128
(config-if)# switchport port-secruity violation shutdown
//配置安全违例的处理方式为shutdown,可选为protect (当安全地址数满后,将未知名地址丢弃)、restrict(当违例时,发送一个trap通知)、shutdown(当违例时将端口关闭,并发送trap通知,可在全局模式下用errdisable recovery来恢复)
b、ip和mac地址绑定
(config-if)#switchport port-security mac-address xxxx.xxxx.xxxx ip-address 172.16.1.1
//接口配置模式下配置mac地址xxxx.xxxx.xxxx和ip172.16.1.1进行绑定(mac地址注意用小写)
8、三层路由功能(针对三层交换机)
(config)# ip routing //开启三层交换机的路由功能
(config)# interface fastethernet 0/1
(config-if)# no switchport //开启端口的三层路由功能(这样就可以为某一端口配置ip)
(config-if)# ip address 192.168.1.1 255.255.255.0
(config-if)# no shutdown
9、三层交换机路由协议
(config)# ip route 172.16.1.0 255.255.255.0 172.16.2.1 //配置静态路由
注:172.16.1.0 255.255.255.0 //为目标网络的网络号及子网掩码
172.16.2.1 为下一跳的地址,也可用接口表示,如ip route 172.16.1.0 255.255.255.0 serial 1/2(172.16.2.0所接的端口)
(config)# router rip //开启rip协议进程
(config-router)# network 172.16.1.0 //申明本设备的直连网段信息
(config-router)# version 2 //开启rip v2,可选为version 1(ripv1)、version 2(ripv2)
(config-router)# no auto-summary //关闭路由信息的自动汇总功能(只有在ripv2支持)
(config)# router ospf //开启ospf路由协议进程(针对1762,无需使用进程id)
(config)# router ospf 1 //开启ospf路由协议进程(针对2501,需要加ospf进程id)
(config-router)# network 192.168.1.0 0.0.0.255 area 0
//申明直连网段信息,并分配区域号(area0为骨干区域)
可以明显看出,三家命令大同小异,其实华为与h3c更加类似。
