日期:2015-08-03  浏览次数:3125 次

CCNA命令注解大全

交换机基本设置:
switch>enable                                       ;进入特权模式
switch#config terminal                              ;进入全局配置模式

switch(config)#hostname <hostname>                  ;设置交换机的主机名
switch(config)#no ip http server                    ;关闭非加密的HTTP访问
switch(config)#no ip domain lookup                  ;禁用域名解析
switch(config)#enable secret xxx                    ;设置特权加密口令
switch(config)#line console 0                       ;进入控制台口
switch(config)#line vty 0 4                         ;进入虚拟终端
switch(config-line)#exec-timeout 30 0               ;超时为30秒
switch(config-line)#login                           ;允许登录
switch(config-line)#password xxx                    ;设置登录口令
switch#dir flash:                                   ;查看闪存
switch(config)#logging 10.0.0.100                   ;设置日志服务器
switch(config)#ip name-server 61.177.7.1            ;dns服务器
switch(config-if)#description Connect R2 fa0/0      ;注释:连接R2的fa0/0

交换机设置IP地址:
switch(config)#interface vlan 1                     ;进入vlan 1
switch(config-if)#ip address <IP> <mask>            ;设置IP地址
switch(config)#ip default-gateway <IP>              ;设置默认网关

交换机ssh设置:
switch(config)#ip domain-name R7.com
switch(config)#aaa new-model
switch(config)#username kele password making
switch(config)#crypto key generate rsa general-keys modulus 2048
switch(config)#line vty 0 4
switch(config-line)#transport input ssh

交换机时间设置:
switch#clock set 16:50:00 28 jul 2006               ;设置时间
switch(config)#clock timezone GTM 8                 ;设置时区

交换机ntp设置:
switch(config)#ntp source Vlan10                    ;强制在NTP包中使用特定的源地址
switch1(config)#ntp authenticate                    ;启用NTP身份验证
switch1(config)#ntp authentication-key 8 md5 making ;验证码为making
switch1(config)#ntp trusted-key 8                   ;确认路由器的特定身份验证键值
switch1(config)#ntp master                          ;设定NTP服务器
switch1(config)#ntp peer 10.1.1.2 key 8             ;系统时钟与其对等体的时钟同步

switch2(config)#ntp authenticate
switch2(config)#ntp authentication-key 8 md5 making
switch2(config)#ntp truster-key 8
switch2(config)#ntp server 10.1.1.1 key 8

NTP示例:
RouterA#clock set xx:xx:xx:xx
RouterA(config)# int s0
RouterA(config-if)#ip add 172.23.1.1 255.255.255.0
RouterA# ntp master 1
RouterB#ntp server 172.23.1.1
RouterB(config-if) ip add 172.16.1.2 255.255.255.0
RouterC#ntp peer 172.16.1.2


交换机VLAN设置:
switch#vlan database                                   ;进入VLAN设置
switch(vlan)#vlan 2                                    ;建VLAN 2
switch(vlan)#no vlan 2                                 ;删vlan 2
switch(config)#vlan 5                                  ;建VLAN 5
switch(config)#no vlan 5                               ;删vlan 5
switch(config-if)#switchport access vlan 2             ;当前端口加入vlan 2
switch(config-if)#switchport mode trunk                ;设置为干道端口
switch(config-if)#switchport trunk allowed vlan 1,2    ;设置允许的vlan
switch(config-if)#switchport trunk encap {dot1q | isl} ;设置vlan中继类型
######## nativ Vlan 用来传输未被标记的帧,默认为vlan 1 ########
        Pvlan
Router(config)#vlan 100                                ;配置主vlan100
Router(config-vlan)#private-vlan primary
Router(config-vlan)#exit
Router(config)#vlan 200                                ;配置辅vlan200 为团体vlan
Router(config-vlan)#private-vlan community
Router(config-vlan)#exit  
Router(config)#vlan 300                                ;配置辅vlan300 为隔离vlan
Router(config-vlan)#private-vlan isolated
Router(config-vlan)#exit  
Router(config)#vlan 100
Router(config-vlan)#private-vlan association 200,300   ;将2层辅vlan关联到主vlan
Router(config-vlan)#private-vlan association {add | remove} vlan-id  
Router(config)#interface vlan 100                      ;将辅vlan映射到主vlan来允许流量
Router(config-if)#private-vlan mapping 200,300
Router(config-if)#private-vlan mapping {add | remove} vlan-id   
Router(config)#interfacet fastethernet 0/1             ;配置端口为主机端口或混杂端口
Router(config-if)#switchport mode private-vlan {host | promiscuous}
Router(config-if)#switchport private-vlan host-association 100 200  ;如果端口设置为主机端口则在端口上映射pvlan
1.一个“Primary VLAN”当中至少有1个“Secondary VLAN”,没有上限。
2.一个“Primary VLAN”当中只能有1个“Isolated VLAN”,可以有多个“Community VLAN”。
3.不同“Primary VLAN”之间的任何端口都不能互相通信(这里所将的“互相通信”是指二层连通性)。
4.“Isolated端口”只能与“混杂端口”通信,除此之外不能与任何其他端口通信。
5.“Community端口”可以和“混杂端口”通信,也可和同一“Community VLAN”当中的其它端口通信,除此之外不能和其他端口通信。

VTP
switch#vlan database
switch(vlan)#vtp server domain v2-mode password……
switch(config)#vtp server                           ;设置vtp模式
switch(config)#vtp client                           ;设置vtp模式
switch(config)#vtp v2-mode                          ;设置vtp版本
switch(config)#vtp domain <name>                    ;设置vtp域名
switch(config)#vtp password <word>                  ;设置vtp密码
switch(config)#vtp pruning                          ;启用管理域中修剪流量

spanning-tree
    backbonefast                                    ;间接失效时加快收敛
    portfast                                        ;直接失效时加快收敛
    uplinkfast                                      ;终端接口快速接入

Etherchannel(以太信道)
3550(config)#int fa0/0
3550(config-if)#switchport                          ;配置第2层Etherchannel
3550(config-if)#channel-group 1 mode desirable      ;创建Etherchannel 1
3550(config-if)#int fa0/1
3550(config-if)#switchport
3550(config-if)#channel-group 1 mode on             ;加入Etherchannel 1
3550(config-if)#interface port-channel 1            ;进入Etherchannel 1
3550(config-if)#switchport mode trunk               ;设置Etherchannel 1为trunk
3550(config)#no interface port-channel 1            ;删除Etherchannel
############### 4500 6500 3层 ###############
6500(config)#int fa0/0                              
6500(config-if)#no switchport                       ;配置第3层Etherchannel
6500(config-if)#channel-group 1 mode desirable      ;创建Etherchannel 2
6500(config-if)#int fa0/1
6500(config-if)#no switchport
6500(config-if)#channel-group 1 mode on             ;加入Etherchannel 2
6500(config-if)#interface port-channel 1            ;进入Etherchannel 2
6500(config-if)#ip address 10.0.0.1 255.255.255.0   ;设置Etherchannel 2的ip地址
switch#show etherchannel 1 summary                  ;查看Etherchannel 1信息

CDP(cisco发现协议)
switch(config)#no cdp run                           ;全局禁用CDP
switch(config)#int fa 0/0                           ;单独禁用端口CDP
switch(config-if)#no cdp enable
switch#show cdp neighbors                           ;查看邻接的cisco设备

端口安全
Switch(config)# interface gigabitethernet1/0
Switch(config-if)# switchport mode access
Switch(config-if)# switchport port-security
Switch(config-if)# switchport port-security mac-address 0000.02000.0004
Switch(config-if)# switchport port-security maximum 1
Switch(config-if)# switchport port-security violation restrict
    出现安全违规时protect(保护)restrict(限制)shutdown(关闭)
Switch(config-if)# switchport port-security mac-address sticky
    用粘性学习,将动态MAC转换为静态MAC,用此可不指定MAC
switch(config)#mac-address-table static 0000.0000.0001 vlan 1 drop
    在vlan1中丢弃mac为0000.0000.0001的流量
6500(config)#system mtu 1552                        ;设定小巨人帧
6500(config-if)#mtu 9198                            ;设定巨型帧
3750(config-if)#udld port aggressive                ;在交换机互联端口配置积极UDLD

VLAN间路由选择
Router(config)#int fa0/2                            ;启用路由端口
Router(config-if)#no switchport
Router(config-if)#ip add 10.0.0.1 255.255.255.0     ;为不同vlan端口配置ip
Router(config-if)#int fa0/3
Router(config-if)#no switchport                 
Router(config-if)#ip add 10.0.1.1 255.255.255.0  
3750(config)#ip routing                             ;设置交换机虚拟接口
3750(config)#router rip
3750(config-router)#network 10.0.0.0
3750(config-router)#int vlan 1
3750(config-if)#ip add 10.0.0.1 255.255.255.0
3750(config-if)#no shut
3750(config-if)#int vlan 2
3750(config-if)#ip add 10.0.1.1 255.255.255.0
3750(config-if)#no shut
R1(config)#int fa0/0                                ;单臂路由
R1(config-if)#no shutdown
R1(config-if)#int fa0/0.10
R1(config-subif)#encapsulation dot1Q 10             ;设置vlan 10
R1(config-subif)#ip add 10.0.1.1 255.255.255.0
R1(config-subif)#int fa0/0.20
R1(config-subif)#encapsulation dot1Q 20             ;设置vlan 20
R1(config-subif)#ip add 10.0.2.1 255.255.255.0
R1(config-subif)#int fa0/0.30
R1(config-subif)#encapsulation dot1Q 30             ;设置vlan 30
R1(config-subif)#ip add 10.0.3.1 255.255.255.0

IP广播转发
3750(config)#int vlan 1
3750(config-if)#no ip directed-broadcast            ;防止定向广播转换问物理广播
3750(config-if)#ip helper-address 10.0.1.1          ;定向广播地址(如DHCP)
3750(config-if)#no ip forward-protocol udp tftp     ;不转发tftp的udp广播

热备路由选择协议(HSRP)-----每个vlan或子网都要配置
Router1(config)#int vlan 1
Router1(config-if)#ip address 172.22.1.3 255.255.255.0
Router1(config-if)#standby 1 ip 172.22.1.1          ;设定虚拟ip,vlan网关
Router1(config-if)#standby 1 priority 120           ;设定优先级
Router1(config-if)#no ip redirects                  ;禁用ICMP重定向
Router1(config-if)#standby 1 preempt                ;设定优先权

虚拟路由冗余协议(VRRP)------一组路由器虚拟成一个
Router(config)#int vlan 2
Router(config-if)#ip address 10.0.1.1{2|3} 255.255.255.0
Router(config-if)#vrrp 1 ip 10.0.1.1                ;虚拟网关ip
Router(config-if)#vrrp 1 priority 90                ;优先级
    果虚拟ip和接口的ip相同则优先级为255


######################################################################
路由器显示命令:
router#show run                                     ;显示配置信息
router#show interface                               ;显示接口信息
router#show ip route                                ;显示路由信息
router#show cdp nei                                 ;显示邻居信息
router#reload                                     ;重新起动

路由器口令设置:
router>enable                                       ;进入特权模式
router#config terminal                              ;进入全局配置模式
router(config)#hostname <hostname>                  ;设置交换机的主机名
router(config)#enable secret xxx                    ;设置特权加密口令
router(config)#ip classless                         ;实现无类路由
router(config)#ip subnet-zero                       ;可用0子网
router(config)#line console 0                       ;进入控制台口
router(config-line)#line vty 0 4                    ;进入虚拟终端
router(config-line)#logging synchronous             ;日志消息不影响cli
router(config-line)#exec-timeout 30 0               ;登陆超时时间
router(config-line)#login                           ;要求口令验证
router(config-line)#password xx                     ;设置登录口令xx
RIPv1;IGRP;BGP3                                   ;有类路由

路由器配置:
router(config)#int s0/0                             ;进入Serail接口
router(config-if)#no shutdown                       ;激活当前接口
router(config-if)#clock rate 64000                  ;设置DCE同步时钟
router(config-if)#bandwidth 56                      ;带宽设置56K
router(config-if)#ip address <ip> <netmask>         ;设置IP地址
router(config-if)#ip address <ip> <netmask> second  ;设置第二个IP
router(config-if)#int f0/0.1                        ;进入子接口
router(config-subif.1)#ip address <ip> <netmask>    ;设置子接口IP
router(config-subif.1)#encapsulation dot1q <n>      ;绑定vlan中继协议
router(config)#config-register 0x2142               ;跳过配置文件
router(config)#config-register 0x2102               ;正常使用配置文件

路由器文件操作:
router#copy running-config tftp                     ;保存配置到tftp
router#copy tftp flash:                             ;下传文件到flash
router#copy tftp startup-config                     ;下载配置文件

ROM状态:
Ctrl+Break                                          ;进入ROM监控状态
rommon>confreg 0x2142                               ;跳过配置文件
rommon>confreg 0x2102                               ;恢复配置文件
rommon>reset                                        ;重新引导
rommon>copy xmodem:<sname> flash:<dname>            ;从console传输文件
rommon>IP_ADDRESS=10.65.1.2                         ;设置路由器IP
rommon>IP_SUBNET_MASK=255.255.0.0                   ;设置路由器掩码
rommon>TFTP_SERVER=10.65.1.1                        ;指定TFTP服务器IP
rommon>TFTP_FILE=c2600.bin                          ;指定下载的文件
rommon>tftpdnld                                     ;从tftp下载
rommon>dir flash:                                   ;查看闪存内容
rommon>boot                                         ;引导IOS

无编号IP------借用其他接口的ip在点到点的广域网链路上
Router(config)#int s1/0
Router(config-if)#ip unnumbered vlan 1              ;s1/0借用vlan 1的ip

DHCP服务器配置
Router(config)#service dhcp
Router(config)#ip dhcp pool network1                ;定义一个地址池network1     
Router(dhcp-config)#network 172.25.1.0 255.255.255.0
Router(dhcp-config)#default-router 172.25.1.1
Router(dhcp-config)#dns-server 172.25.1.1 10.1.2.3
Router(dhcp-config)#netbios-name-server 172.25.1.1
Router(config)#ip dhcp excluded-address 172.25.1.1 172.25.1.50
excluded-address保留地址1到50

静态路由:
ip route <目标网段ip> <subnet-mask> <转发地址>      ;命令格式
router(config)#ip route 1.0.0.0 255.0.0.0 1.1.1.2   ;静态路由举例
router(config)#ip route 1.0.0.0 255.0.0.0 e0        ;从e0口出去
router(config)#ip route 0.0.0.0 0.0.0.0 1.1.1.2     ;默认路由举例

浮动静态路由
R(config)#ip route 1.0.0.0 255.0.0.0 1.1.1.2 121    ;121为管理距离

                      管理距离
直接接口        0                  IS-IS           115
静态路由        1                  RIP             120
EIGRP归纳路由   5                  EGP             140
外部BGP         20                 外部EIGRP       170
内部EIGRP       90                 内部BGP         200
IGRP            100                未知            255
OSPF            110

路由器的NAT配置
Router(config-if)#ip nat inside               ;当前接口指定为内部接口
Router(config-if)#ip nat outside              ;当前接口指定为外部接口
Router(config)#ip nat inside source static <私有IP> <公网IP>
Router(config)#ip nat inside source static tcp 10.65.1.3 80 60.1.1.1 80 extendable
    定义一个静态端口转发
Router(config)#ip nat pool p1 58.211.0.5 58.211.0.10 netmask 255.255.255.0
    定义一个NAT池p1包含公网地址5-10
Router(config)#access-list 1 permit 10.0.0.0 0.0.0.255
Router(config)#ip nat inside source list 1 pool p1
    用access-list定义哪些本地主机使用这个地址池
Router(config)#ip nat inside source list p1 int fa0/0 overload
    用fa0/0接口地址为p1进行NAT,overload为PAT(基于端口的NAT)
Router#show ip nat translation

TCP负载分担(NAT)
Router(config)#ip nat pool webserver 10.0.0.1 10.0.0.2 netmask 255.255.255.0
    --tpye rotary 转换时在地址池中循环
Router(config)#access-list 1 permit host 58.211.0.5
Router(config)#ip nat inside destination list 1 pool webserver
Router(config-if)#ip nat inside 或 outside

VPN(虚拟专用网)site---site
WUXI(config)#crypto isakmp policy 1
WUXI(config-isakmp)#hash md5或sha
WUXI(config-isakmp)#authentication pre-share
WUXI(config-isakmp)#group 1或2
WUXI(config-isakmp)#encryption 3des
    创建IKE策略并设定
WUXI(config)#crypto isakmp key 6 making address 218.5.76.1
    配置预共享密钥及对等体IP(加密)
WUXI(config)#crypto ipsec transform-set kele esp-des esp-md5-hmac
WUXI(cfg-crypto-trans)#mode transport
    定义IPSec转换集kele为传输模式
WUXI(config)#access-list 100 permit ip 10.0.1.0 0.0.0.255 any
WUXI(config)#crypto map mymap1 1 ipsec-isakmp
    配置IPSec密码映射mymap1序号为1
WUXI(config-crypto-map)#set peer 218.5.76.1
WUXI(config-crypto-map)#set transform-set kele
    指定转换集为kele
WUXI(config-crypto-map)#match address 100
    指定转换地址为ACL 100中定义的地址
WUXI(config-crypto-map)#exit
WUXI(config)#int fa 0/0
WUXI(config-if)#crypto map mymap1
    在指定接口应用密码映射mymap1
WUXI#shwo crypto isakmp sa
WUXI#shwo crypto ipsec sa
WUXI#shwo crypto map


动态路由:
    RIPv2
router(config)#ip routing                           ;启动路由转发
router(config)#router rip                           ;启动RIP路由协议
router(config-router)#version 2                     ;启用版本2
router(config-router)#network <netid>               ;设置发布路由
router(config-router)#no auto-summary               ;关闭自动路由汇总
router(config)#int fa 0/0
router(config-if)#ip rip send version 1             ;指定端口接收发送版本
router(config-if)#ip rip receive version 2
router(config)#key chain kele                       ;密钥链名称
router(config-keychain)#key 1
router(config-keychain-key)#key-string making
router(config-keychain-key)#int fa0/0               ;定义接口使用密钥链
router(config-if)#ip rip authentication key-chain kele
router(config-if)#ip rip authentication mode md5
router#show ip protocols                            ;查看
router#show ip route
router#show ip rip database
    EIGRP
router(config)#router eigrp 1                       ;启动eigrp自治(AS)号1
router(config-router)#network <netid>
router(config-router)#eigrp log-neighbor-changes    ;记录邻居的变化
router(config)#router eigrp 1                       ;手工配置汇总路由
router(config-router)#no auto-summary
router(config-router)#int fa 0/0
router(config-if)#ip summary-address eigrp 1 218.5.0.0 255.255.0.0
    OSPF
router(config)#router ospf 1                        ;AS号1区域号0
router(config-router)#network 58.211.0.0 0.0.0.255 area 0
router(config)#int loopback 0                       ;配置路由ID
router(config-if)#ip add 10.0.0.1 255.255.255.255
router(config)#router ospf 1                        ;启用认证功能
router(config-router)#area 0 authentication message-digest
router(config-router)#int fa0/0                     ;方式1消息摘要
router(config-if)#ip ospf message-digest-key 1 md5 0 making
router(config-if)#int fa1/0                         ;方式2口令
router(config-if)#ip ospf authentication-key making

路由优化
router(config)#router ospf 1(rip)                 ;定义被动接口
router(config-router)#passive-interface fa 0/0      ;只接收更新不发送
router(config)#router rip
router(config-router)#network 58.211.0.0
router(config-router)#distribute-list 1 int(out)  ;路由过滤
router(config)#access-list 1 permit 58.211.0.0 0.0.0.255
router(config)#access-list 1 deny any

策略路由
router(config)#access-list 1 permit 58.211.0.0 0.0.0.255
router(config)#access-list 2 permit 218.5.76.0 0.0.0.255
    定义ip访问列表
router(config)#route-map ISP1 permit 10
router(config-route-map)#match ip address 1
router(config-route-map)#set interface fa 0/0
    配置路由图ISP1匹配access-list 1并将数据由fa 0/0发往ISP1
router(config)#route-map ISP2 permit 20
router(config-route-map)#match ip address 2
router(config-route-map)#set interface fa 1/0
router(config-route-map)#int fa0/0
router(config-if)#ip policy route-map ISP1
    将路由图应用到一个接口
router(config-if)#int fa1/0
router(config-if)#ip policy route-map ISP2

基本访问控制列表:
标准访问控制列表尽量靠近接收站
扩展访问控制列表尽量靠近发送站
例1:
router(config)#access-list 1 permit host 10.65.1.1
router(config)#access-list 1 deny any
router(config)#line vty 0 4
router(config-line)#access-class 1 in

例2:
router(config)#access-list 4 permit 10.8.1.1
router(config)#access-list 4 deny 10.8.1.0 0.0.0.255
router(config)#access-list 4 permit 10.8.0.0 0.0.255.255
router(config)#access-list 4 deny 10.0.0.0 0.255.255.255
router(config)#access-list 4 permit any
router(config)#int f0/1
router(config-if)#ip access-group 4 in

扩展访问控制列表:
例:
router(config)#access-list 101 deny icmp any host 10.64.0.2 echo
router(config)#access-list 101 deny tcp any 10.64.0.0 0.0.0.255 eq 3389
router(config)#access-list 101 permit ip any any
router(config)#int s0/0
router(config-if)#ip access-group 101 in

命名ACL
router(config)#ip access-list extended kele
router(config-ext-nacl)#deny ip any 10.0.0.1 0.0.0.0 eq 3389

删除访问控制例表:
router(config)#no access-list 102
router(config-if)#no ip access-group 101 in
router(config-ext-nacl)#no deny ip any any