天天看點

思科Cisco交換機、路由器設定指令(附詳解)

交換機密碼設定:

switch>enable                                        ;進入特權模式

switch#config terminal                               ;進入全局配置模式

switch(config)#hostname <hostname>                   ;設定交換機的主機名

switch(config)#enable secret xxx                     ;設定特權加密密碼為 xxx

switch(config)#enable password xxx                   ;設定特權非密密碼為 xxx

switch(config)#line console 0                        ;進控制台口(Rs232)初始化

switch(config-line)#line vty 0 4                     ;進入虛拟終端virtual tty

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)#int f0/1                              ;進入端口1

switch(config-if)#switchport access vlan 2           ;目前端口1加入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       ;設定vlan 中繼

switch(config)#vtp domain <name>                     ; 設定發vtp域名

switch(config)#vtp password <word>

switch(config)#vtp mode server

switch(config)#vtp mode client

交換機設定IP位址:

switch(config)#interface vlan 1                      ;進入vlan 1

switch(config-if)#ip address <IP> <mask>             ;添加遠端登入IP

switch(config)#ip default-gateway <IP>               ;添加預設網關 

switch#dir flash:                                    ;檢視記憶體

交換機顯示指令:

switch#write                                         ;寫入儲存 

switch#show vtp

switch#show run                                      ;檢視目前配置資訊

switch#show vlan                                     ;看VLAN

switch#show interface                                ;顯示所有端口資訊 

switch#show int f0/0                                 ;顯示端口0的資訊

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

路由器顯示指令:

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                     ;設定特權加密密碼為 xxx

router(config)#enable password xxx                   ;設定特權非密密碼為 xxx

router(config)#line console 0                        ;進控制台口(Rs232)初始化

router(config-line)#line vty 0 4                     ;進入虛拟終端virtual tty

router(config-line)#login                            ;允許登入

router(config-line)#password xx                      ;設定登入密碼xx

router(config)# (Ctrl+z)                             ; 傳回特權模式

router#exit                                          ;傳回指令

配置IP位址:

router(config)#int s0/0                              ;進行串Serail接口

router(config-if)#no shutdown                        ;起動接口

router(config-if)#clock rate 64000                   ;設定時鐘

router(config-if)#ip address 10.1.1.1 255.255.0.0    ;設定IP位址和子網路遮罩

router(config-if)#ip add 10.1.1.2 255.255.0.0 second;

router(config-if)#int f0/0.1                         ; 進入子接口

router(config-subif.1)#ip address <ip><netmask>      ;

router(config-subif.1)#encapsulation dot1q <n>         ;

router(config)#config-register 0x2142                ;跳過配置檔案

router(config)#config-register 0x2102                ;正常使用配置檔案

router#reload                                        ;重新開機

複制操作:

router#copy running-config startup-config            ;存配置

router#copy running-config tftp                      ;上載

router#copy startup-config tftp

router#copy tftp flash:                              ;特權模式下更新IOS

router#copy tftp startup-config               ;下載下傳配置檔案到nvram

ROM狀态:

Ctrl+Break                                           ;進入ROM監控狀态 

rommon>confreg 0x2142                                ;跳過配置,26 36 45xx

rommon>confreg 0x2102                                ;使用配置,恢複工作狀态

rommon>reset                                    ;重新開機,等效于重開機

rommon>copy xmodem:<sname> flash:<dname>             ;從console更新IOS

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                                      ;ROM監控狀态下更新IOS

rommon>dir flash:                                    ;檢視閃存中的内容

rommon>boot                                          ;引導IOS

靜态路由:

ip route <ip-address> <subnet-mask> <gateway>    例:

router(config)#ip route 10.1.0.0 255.255.0.0 10.2.1.1

router(config)#ip route 0.0.0.0 0.0.0.0 1.1.1.2    

動态路由:

router(config)#ip routing                            ;啟動路由

router(config)#router rip                            ;啟動RIP路由協定。

router(config-router)#network <netid>                ;配置範圍,有的支援all。

router(config-router)#negihbor <ip-address>          ;點對點 幀中繼用。

幀中繼指令:

router(config)# frame-relay switching                ;使能幀中繼交換

router(config-s0)# encapsulation frame-relay         ;使能幀中繼

router(config-s0)# frame-relay intf-type DCE         ;DCE端(需要配虛電路)

router(config-s0)# frame-relay local-dlci 20         ;配置虛電路号

基本通路控制清單:

router(config)#access-list <number> permit|deny <source ip> <wild|any>

router(config)#interface <interface>                 ;default: deny any

router(config-if)#ip access-group <number> in|out    ;default: out

例:

RB(config)#access-list 4 permit 10.8.1.1

RB(config)#access-list 4 deny 10.8.1.0 0.0.0.255

RB(config)#access-list 4 permit 10.8.0.0 0.0.255.255

RB(config)#access-list 4 deny 10.0.0.0 0.255.255.255

RB(config)#access-list 4 permit any              

RB(config)#int f0/0

RB(config-if)#ip access-group 4 in

擴充通路控制清單:

access-list <number> permit|deny icmp <SourceIP wild> <destinationIP

wild>[type]

access-list <number> permit|deny tcp <SourceIP wild> <destinationIP

wild>[port]

例1:

router(config)#access-list 101 deny icmp any 10.64.0.2 0.0.0.0 echo

router(config)#access-list 101 permit ip any any  

router(config)#int s0/0

router(config-if)#ip access-group 101 in

例2:

router(config)#access-list 102 deny tcp any 10.65.0.2 0.0.0.0 eq 80

router(config)#access-list 102 permit ip any any

router(config)#interface s0/1

router(config-if)#ip access-group 102 out

router(config)#no access-list 102

router(config-if)#no ip access-group 101 in

在路由器上設定 SNMP Community Strings

   router(config) # snmp-server community read-community-string ro

   router(config) # snmp-server community write-community-string rw

在交換機上設定 SNMP Community Strings

switch(config) # snmp-server community     read-community-string ro

switch(config) # snmp-server community write-community-string rw

在路由器上配置日志資訊(Syslog Message Logging)

router(config) # logging on

router(config) # logging server-ip-address

router(config) # logging trap severity-level

路由器恢複出廠設定

erase start-config

或write erase

或erase NVROM

本文轉自shenzhoulong  51CTO部落格,原文連結:http://blog.51cto.com/shenzhoulong/285544,如需轉載請自行聯系原作者