当前位置: 代码迷 >> 综合 >> 思科Cisco——IOS命令配置小技巧
  详细解决方案

思科Cisco——IOS命令配置小技巧

热度:64   发布时间:2024-02-22 08:47:56.0

命令1:range

SW(config)#int range Gi 0/1-3                   //进入1-3接口范围
SW(config-if-range)#switchport mode access      //定义端口为接入端口#####################################
interface GigabitEthernet0/1switchport mode access
!
interface GigabitEthernet0/2                    //可以看到1-3端口全部被定义为接入端口switchport mode access
!
interface GigabitEthernet0/3switchport mode access
#####################################

命令2:macro(宏)

1.创建macro

Switch(config)# macro name hello 
//在配置模式下创建宏,创建的宏的名称是hello,宏名可自定义。

2.编辑宏里的内容

# Put the switch in access mode                 //“#”进行注释
switchport mode access
# Allow port to move to forwarding state quickly
spanning-tree portfast
# BPDUs should not be sent into the network
spanning-tree bpduguard enable
# Restrict the port to one address -- that of desktop
switchport port-security maximum 1
# Put all data traffic in vlan 1
switchport access vlan 1
@                                             //通过@符号结束宏

3.应用宏

Switch(config)# interface gigabitethernet1/0/2
Switch(config-if)# macro apply hello     //采用macro apply应用名字为hello的宏。

命令3:alias(别名)

SW(config)#alias exec 11 show ip int br        
//’exec‘为执行的命令,’11‘为新定义的别名,’show ip int br‘是被定义的命令############################################
SW#11
Interface              IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0     unassigned      YES unset  reset                 down    
GigabitEthernet0/1     unassigned      YES unset  up                    up      
GigabitEthernet0/2     unassigned      YES unset  reset                 down    
GigabitEthernet0/3     unassigned      YES unset  up                    up      
############################################

命令4:default(默认)

SW(config)#default int gi 0/1        //恢复端口的初始配置
Interface GigabitEthernet0/1 set to default configuration

命令5:kron(计划命令)

1.首先创建一个kron policy list

Router(config)# kron policy-list backup      //创建名为backup的计划
Router(config-kron-policy)# cli write        //执行的命令是‘write’
Router(config-kron-policy)# exit

2.创建一个kron occurrence 并调用kron policy,定义路由器何时以及多长时间运行这个策略列表(即一组命令)。

Router(config)# kron occurrence wr at 22:00 Mon recurring
//定义一个名为’wr‘的事件,在每周一晚上22:00运行
Router(config-kron-occurrence)# policy-list backup
//调用之前定义的名为’backup‘的策略

3.验证

Router# show kron schedule    //使用show命令验证Kron Occurrence Schedule
backup inactive, will run again in 2 days 22:03:46 at 22:00 on Mon###############################################
Router# show running-configuration
!
kron occurrence backup at 22:00 Mon recurring
policy-list backup
!
kron policy-list backup
cli write
!
###############################################