«

Cisco_Swich_相關指令

Paladin 发布于 阅读:220 oTher


配置Syslog

Cisco-sw>enable
Cisco-sw#conf t
Cisco-sw(config)#logging host <Syslog服务器IP>

NTP設定

Cisco-sw>enable
Cisco-sw#conf t
Cisco-sw(config)#clock timezone GMT +8
Cisco-sw(config)#ntp server <NTP服务器IP>
Cisco-sw(config)#service timestamps log datetime localtime
Cisco-sw(config)#do wr

設定自動備份

Archive configuration commands:
  default       Set a command to its defaults
  exit          Exit from archive configuration mode
  log           Logging commands
  maximum       maximum number of backup copies
  no            Negate a command or set its defaults
  path          path for backups
  rollback      Rollback parameters
  time-period   Period of time in minutes to automatically archive the running-config
  write-memory  Enable automatic backup generation during write memory
  R#conf t
R(config)#archive
R(config-archive)#path tftp://ip/$h- //$h为当前主机名
R(config-archive)#time-period 10080 //10080周期时间 单位:分钟
R(config-archive)#write-memory //当保存配置进行write操作时,立即备份
设置存档路径和周期
设置存档路径:通过TFTP协议将交换机的配置文件保存到指定的服务器。例如,使用命令archive path tftp://<TFTP服务器IP>/$h-$d.cfg,其中$h代表主机名,$d代表日期。
设置存档周期:存档周期可以通过time-period参数来设定。例如,设定为10080分钟(相当于7天的周期),命令为archive time-period 10080。
查看存档配置文件
通过TFTP服务器查看:由于配置文件被存储在TFTP服务器上,管理员可以直接访问TFTP服务器上的文件路径,检查存档的文件是否存在并查看其内容。
通过思科交换机命令行查看:可以使用命令show archive config all来列出所有的存档配置文件及其相关信息,如存档时间、文件大小等。
记录和监控存档操作
启用日志记录:为了跟踪存档操作的详细情况,可以在思科交换机上启用日志记录功能。通过命令logging enable和notify syslog,可以将存档操作的日志发送到syslog服务器进行集中管理。
查看日志文件:存档操作的相关日志可以通过查看syslog服务器上的日志文件获得。这可以帮助管理员了解存档操作的详细执行情况,包括成功和失败的存档操作。

思科交换机巡检命令思科交换机基本配置命令

switch>enable
- show clock #查看系統時間
- show ntp status #查看网络时间协议(NTP)的同步状态
- show archive #查看自動備份執行記錄
- show interface stats  #查看交换机所有接口当前接口流量
- show running-config  #查看当前设备配置
- show version  #查看IOS版本信息及设备正常运行时间
- show clock  #查看设备时钟信息
- show vtp status  #查看交换机vtp配置模式
- show vtp password  #查看交换机vtp配置口令
- show env all  #查看设备温度,电源和风扇运转参数及是否报警
- show inventory  #调取设备内部板卡出厂模块型号及序列号
- show spanning-tree root  #查看交换机生成树根位置
- show cdp neighbors  #查看邻接cisco设备基本信息
- show cdp neighbors detail  #查看邻接cisco设备详细信息
- show interface status  #查看交换机接口状态是否存在error disable接口disable接口
- show interface summary  #查看交换机所有接口当前接口流量
- show interface |ierrors|FastEthernet|GigabitEthernet  #查看接口是否存在大量input或output errors包错误
- show processes cpu  #查看设备cpu负载
- show processes mem  #查看设备mem负载
- show access-list   #查看访问控制列表配置及匹配数据包数量
- show logging  #查看本机内部日志记录情况
- show ip route  #查看路由表
- show firewall  #检查防火墙的工作模式
- show conn count  #检查防火墙并发数
- show xlate count  #检查防火墙nat工作状态 
- show running-config #查看当前所有配置
- show running-config interfaces #查看指定端口配置
- show interfaces #查看所有端口详细信息
- show interfaces #查看指定端口详细信息
- show interfaces status #查看所有端口简要信息
- show ip interfaces brief #查看3层端口简要信息
- show interfaces status #查看指定端口简要信息
- show etherchannel summary #查看每个聚合组内包含哪些端口
- show etherchannel detail #查看所有聚合组信息及其所含端口的简要状态信息
- show etherchannel port-channel #查看所有聚合组的简要信息及其包含哪些端口
- show interfaces port-channel #查看指定聚合组的端口信息
- show interfaces transceiver detail #查看所有光纤口的详细状态信息
- show interfaces transceiver #查看所有光纤口的简要状态信息

思科交换机基本配置命令

# 进入特权模式
switch>enable
switch#
# 进入全局配置模式
switch>enable
switch#configure terminal
switch(conf)#
# 交换机命名
switch>enable
switch# configure terminal
switch(conf)# hostname hxsw-001
hxsw-001(conf)#
# 配置使能口令
switch>enable
switch#configure terminal
switch(conf)# hostname hxsw-001
hxsw-001(conf)# enable password cisco
# 创建多个VLAN
switch>enable     #进入特权模式
switch#vlan data  #进入VLAN配置模式
switch(vlan)#vlan 10 name IT   #划分VLAN 10,名称为IT
switch(vlan)#vlan 20 name HR   #划分VLAN20,名称为HR
switch(vlan)#vlan 30 name FIN  #划分VLAN30,名称为FIN
switch(vlan)#vlan 40 name LOG  #划分VLAN40,名称为LOG
switch(vlan)#exit
# 设置VLAN1
switch>enable
switch#configure terminal
switch(conf)#hostname hxsw-001
hxsw-001(conf)# interface vlan 1
hxsw-001(conf-if)#ip address 192.168.1.1 255.255.255.0  #配置交换机端口IP和子网掩码
hxsw-001(conf-if)#no shut
hxsw-001(conf-if)#exit
hxsw-001(conf)#ip default-gateway 192.168.254  #设置网关地址
# 进入交换机某一个端口
switch>enable
switch#configure terminal
switch(conf)#hostname hxsw-001
hxsw-001(conf)#interface fastehernet 0/1
hxsw-001(conf-if)#
# 查看命令
switch>enable
switch#show version     #查看系统中的所有版本信息
show interface vlan 1   #查看交换机有关vlan1的配置信息
show running-configure  #查看交换机当前起作用的配置信息
show interface fastethernet 0/1  #查看交换机1接口具体配置和统计信息
show mac-address-table  #查看MAC地址表
show mac-address-table aging-time  #查看MAC地址表自动老化时间
# 交换机恢复出厂命令
switch>enable
switch#erase startup-configure
switch#reload
# 双工模式设置
switch> enable
switch#configure terminal
switch(conf)#hostname hxsw-001
hxsw-001(conf)# interface fastehernet 0/17
hxsw-001(conf-if)#duplex full/half/auto
#有 full、half、auto三个选项
# cdp相关命令
switch> enable
switch# show cdp   #查看设备的cdp全局配置信息
show cdp interface fastethernet 0/1
show cdp traffic      #查看有关cdp包的统计信息
show cdp nerghbors    #列出与设备相连的cisco设备
# 交换机远程登录设置
switch>enable
switch#configure terminal
switch(conf)#hostname hxsw-001
hxsw-001(conf)#enable password cisco
hxsw-001(conf)#interface fastethernet 0/1
hxsw-001(conf-if)#ip address 192.168.1.1 255.255.255.0
hxsw-001(conf-it)#no shut
hxsw-001(conf-if)#exit
hxsw-001(conf)line vty 0 4  #设置0-4个用户可以telnet远程登录
hxsw-001(conf-line)#password edge  #以edge为远程登录的用户密码

主机设置:

IP  192.168.1.2   #主机的IP必须和交换机端口的地址在同一个网络段
metmask 255.255.255.0
gate-way 192.168.1.1     #网关地址是交换机端口地址

运行:

telent 192.168.1.1
进入telnet远程登录界面
password:edge
hxsw-001>en
password:cisco
hxsw-001#

Port Channel配置命令

#1、 port-group
port-group [port-group-number] [load-balance { src-mac|dst-mac | dst-src-mac | src-ip| dst-ip|dst-src-ip}]
no port-group [port-group-number] [load-balance]
#功能: 新建一个port group,并且设置该组的流量分担方式。如果没有指定流量分担方式则为设置默认的流量分担方式。该命令的no操作为删除该group或者恢复该组流量分担的默认值,敲入load-balance表示恢复默认流量分担,否则为删除该组。
#举例:
#新建一个port group,并且采用默认的流量分担方式
switch(config)port-group 1
#删除一个port group
switch(config)no port-group 1
#2、port-group mode
port-group [port-group-number] mode {active|passive|on}
no port-group [port-group-number]
#功能:将物理端口加入port channel,该命令的no操作为将端口从port channel中去除
#参数:[port-group-number] 为port channel的组号,范围为1~16;
#active(0) 启动端口的lacp协议,并设置为active模式;
#passive(1) 启动端口的lacp协议,并且设置为passive模式;
#on(2) 强制端口加入port channel,不启动lacp协议;
#命令模式:接口配置模式
#eg:在ethernet0/0/1端口模式下,将本端口以active模式加入port-group 1
switch(config-ethernet0/0/1)#port-group 1 mode active
#3、 interface port-channel
interface port-channel [port-channel-number]
#功能:进入汇聚接口配置模式
#命令模式:全局配置模式
#缺省情况:使用指南:进入汇聚端口模式下配置时,如果是对gvrp,spanningtree模块做配置则对汇聚端口生效,如果汇聚端口不存在,也就是说在端口没有汇聚起来时先提示错误信息,记录该用户配置操作,当端口真正汇聚起来以后恢复用户刚才对未形成汇聚端口的配置动作,注意只能恢复一次,如果因为某种原因汇聚组被拆散然后又汇聚起来,用户一开始的配置不能被恢复。如果是对其他模块做配置,比如做shutdown, speed配置,则是对该port-channel对应的port-group中的所有成员端口生效,起到一个群配的作用。
#举例:进入port-channel1 配置模式
switch(config)interface port-channel 1
switch(config-if-port-channel1)
#此时,channel只需要被想象成一个普通的物理端口就行。

一般配置


Switch(config)hostname test01 #修改交换机名称 
Switch(config)enable secret 123456  #修改交換安全機密碼
Switch(config)enable password 123456  #修改交換機密碼
Switch show vlan  #查看所有vlan
Switch show interfaces fa0/1  #查看interfaces fa0/1
Switch show version  #查看軟體版本
#配置telnet远程登录
Switch(config)enable secret 123456  
Switch(config)line vty 0 4  
Switch(config-line)password 654321  
Switch(config-line)login  
Switch show running-config  
line vty 0 4 password 654321 login 
Switch write  
#标注:普通思科交换机一般不带电池保存时间,交换机重启后时钟都会恢复到初始化时间,建议配置NTP服务。
#特权模式下显示交换机时间
Switch show clock 
Switch clock set 17:42:00 22 Mar 2017

交換機