成长值: 64645
|
本帖最后由 小乔 于 2022-3-9 15:40 编辑
思科交换机的基本配置
一、基本配置
switch>enable //进入特权模式
switch#config terminal //进入全局配置模式
switch(config)#hostname //设置交换机的主机名
switch(config)#enable secret xxx //设置进入特权MD5加密口令
switch(config)#enable password xxa //设置进入特权明文加密口令
switch(config)#line console 0 //进入控制台口
switch(config-line)#line vty 0 4 //设置进入虚拟终端的连接数目 0~4 5个
switch(config-line)#login //允许登录
switch(config-line)#password xx //设置登录到普通用户口令xx
switch#exit //返回命令
二、交换机vlan的配置
switch#vlan database //进入VLAN设置
switch(vlan)#vlan 2 //建VLAN 2
switch(vlan)#no vlan 2 //删vlan 2
Switch(config)# interface range fastethernet 0/1-5 //进入同种类型多端口配置
三、端口操作
switch(config)#int f0/1 //进入端口1
switch(config-if)#switchport access vlan 2 // 将端口1当前端口加入vlan 2
switch(config-if)#switchport mode trunk //将f0/1设置为中继干线
switch(config-if)#switchport trunk allowed vlan 1,2 //设置允许通过中继的vlan
switch(config-if)#switchport trunk encap dot1q //设置vlan 中继执行的协议
四、设置vtp
switch(config)#vtp domain //设置发vtp域名
switch(config)#vtp password //设置发vtp密码
switch(config)#vtp mode server //设置发vtp模式
switch(config)#vtp mode client //设置发vtp模式
五、交换机设置IP地址:
switch(config)#interface vlan 1 //进入vlan 1
switch(config-if)#ip address //设置IP地址
switch(config)#ip default-gateway //设置默认网关
switch#dir flash: //查看闪存
六、交换机telnet 远程登录设置:
swich(conf)#enable password cisco 以cisco 为特权模式密码
swich(conf)#interface vlan 1 以vlan 1端口作为远程登录的接口,其他端口亦可
swich(conf-if)#ip address 192.168.1.1 255.255.255.0
swich(conf-if)#no shut
swich(conf-if)#exit
swich(conf)line vty 0 4 设置0-4 个用户可以telnet 远程登陆
swich(conf-line)#login
swich(conf-line)#password 123456
七、交换机ssh远程登录设置:
a.设定一个非默认的hostname
Switch(config)#hostname cisco
b.配置域名:
cisco(config)#ip domain-name test
c.指定加密长度:
cisco(config)#crypto key generate rsa
How many bits in the modulus [512]: 1024
% Generating 1024 bit RSA keys, keys will be non-exportable...[OK]
d.将vty线路下的登录方式改为 ssh
cisco(config)#line vty 0 4
cisco(config-line)#transport in ssh
八 、交换机端口安全
#int interface_id
config-if#switchport mode access
config-if#switchport port-security (启用安全模式)
config-if#switchport port-security maximum value (value=1-3072,指该端口所接计算机台数)
config-if#switchport port-security limit rate invalid-source-mac
config-if#switchport port-security [aging time aging_time |type{absolute|inactivity}] (设置安全端口的老化时间,范围是0-1440min,是可选的)
config-if#switchport port-security mac-address sticky (启用sticky learning)
九、交换机生成树
直接设置根桥:spanning-tree vlan 2 root primary
修改优先级设置根桥:spanning-tree vlan 2 priority 24768(4096的倍数,值越小,优先级越高.默认为32768)
确定路径.选定根端口:
(1)可通过修改端口成本: (在配置模式下)spanning-tree vlan 2 cost ***(100m为19,10m为100,值越小,路径越优先)
(2)可修改端口优先级: (在接口模式下)spanning-tree vlan 2 port-priority ***(0-255,默认为128)
可修改计时器(可选)
(1)修改HELLO时间:spanning-tree vlan 2 hello-time **(1-10s,默认为两秒)
(2)修改转发延迟时间:spanning-tree vlan 2 forward-time ***(4-30s,默认为15s)
(3)修改最大老化时间:spanning-tree vlan 2 max-age ***(6-40,默认是20秒)
配置快速端口:spanning-tree portfast
配置上行端口:spanning-tree uplinkfast
十、链路聚合
全局模式下进入Fa0/23-24端口
Switch(config)#interface range fastEthernet 0/23-24
#创建虚拟通道 channel-group 1 并设置模式为desirable
Switch(config-if-range)#channel-group 1 mode desirable
#描述channel-group 1虚拟通道从SW3连接SW1
Switch(config-if-range)#description SW3-SW1
#强制虚拟通道 channel-group 1使用dot1q封装数据包
Switch(config-if-range)#switchport trunk encapsulation dot1q
#设置为trunk允许多个VLAN通过
Switch(config-if-range)#switchport mode trunk
#激活端口
Switch(config-if-range)#no shutdown
查看命令
Switch#show etherchannel summary
1 Po1(SU) PAgP Fa0/23(P) Fa0/24(P)
2 Po2(SU) PAgP Fa0/21(P) Fa0/22(P)
#查看虚拟通道包含的接口
Switch#show etherchannel port-channel
#查看通道接口状况
Switch#show etherchannel load-balance
十一、交换机显示命令
switch#write //保存配置信息
switch#show vtp //查看vtp配置信息
switch#show run //查看当前配置信息
switch#show vlan //查看vlan配置信息
switch#show interface //查看端口信息
switch#show int f0/0 //查看指定端口信息
十二、交换机的密码恢复
拔下交换机电源线。
用手按着交换机的MODE 键,插上电源线
在switch:后执行flash_ini 命令:switch: flash_ini
查看flash 中的文件: switch: dir flash:
把“config.text”文件改名为“config.old”: switch: rename flash: config.text flash: config.old
执行boot: switch: boot
交换机进入是否进入配置的对话,执行no :
进入特权模式察看flash 里的文件: show flash :
把“config.old”文件改名为“config.text”: switch: rename flash: config.old flash: config.text
把“ config.text ” 拷入系统的“ running-configure ”: copy flash: config.text system :
running-configure
重新设置密码并保存
十三、交换机配置保存
Switch#show running-config //查看交换机配置
Switch#copy running-config startup-config //保存交换机配置
备注,关于保存的方式:
1、在接口配置模式下使用 do wr 或者是 do copy running-config startup-config
2、在全局配置模式下使用不带do的命令(以上两个)wr或者copy running-config startup-config
十四、关于快捷键:
ctrl+b(backward) 光标左移一个字符
ctrl+f(foreward) 光标右移一个字符
ctrl+a(a是?????) 光标移到命令开头
ctrl+e(end) 光标移到命令末端
esc+b (backward) 光标左移一个词
esc+f (foreward) 光标右移一个词
ctrl+z 一次性退出特权模式 Router
来源: 思科路由器基础命令大全【建议收藏备查】 |
|