CISCO SWITCH &ROUTER基本配置命令

CISCO SWITCH &ROUTER基本配置命令


2:特權模式
   enable
show vlan
show version
show interface
show mac-address-table
show running-config
copy running-config startup-config
3:全局配置模式
   config terminal
hostname
enable password
ip default-gateway
4:接口配置模式
   interface 端口
switchport mode trunk

5:line模式
   line console 0


第2章 交換機的基本配置

1.配置主機
hostname
2.查看交換機的配置
show running-config
使能口令
enable password
加密保存的使能口令
enable secret
配置IP地址
interface vlan1
ip address
no shutdown
配置交換機的網關
ip default-gateway ipaddress
查看交換機的MAC地址表
show mac-address-table
使用CDP協議
show cdp
show cdp interface
show cdp neighbors
show cdp neighbors detail
show cdp traffic
保存與刪除交換機配置
copy running-config startup-config

 

第三章:虛擬局域網(VLAN)

VLAN的概述
VLAN是對連接在第2層交換機端口的網絡用戶的邏輯分段。

VLAN的作用:
1。廣播控制
2。安全(副產品)
3。帶寬利用
4。延遲

VLAN的種類
靜態:基於端口的VLAN
動態:基於MAC地址的VLAN

在交換機上配置靜態VLAN

創建VLAN
1。CONFIG TERMINAL
   VLAN 2
   NAME 2

2。特權模式下
   VLAN DATABASE
   VLAN 2 NAME 2

查看VLAN
   SHOW VLAN
刪除VLAN
   NO VLAN 2
驗證:SHOW VLAN BRIEF

在VLAN中添加端口
INTERFACE F0/2
INTERFACE RANGE F0/2 - 5
SWITCHPORT MODE ACCESS
SWITCHPORT ACCESS VLAN 2

VLAN配置實例
在交換機上添加VLAN2,VLAN3,VLAN3,端口範圍分別爲1-4,5-8,9-12

這個實例的作用就是讓不同的VLAN的計算機之間的通信隔開。使達到減少廣播域範圍的作用。

 


一、交換機基本配置
(1) 步驟1 :配置主機名
switch>enable
switch#config t
switch(config)# hostname sw1
(2) 步驟2 :配置密碼
sw1(config)#enable secret cisco
sw1(config)#line vty 0 15
sw1(config-line)#password cisco
sw1(config-line)#login
(3)步驟3 :接口基本配置
sw1(config)#interface f0/1
sw1(config-if)#duplex (full|half|auto)
//duplex用來配置接口的雙工模式:full-全雙工 half-半雙工 auto-自動監測雙工的模式
sw1(config-if)#speed (10|100|1000|auto)
//speed命令用來配置交換機的接口速度 10-10mbps 100-100mbps 1000-1000mbps auto-自動監測接口速度
(4)配置管理地址
交換機允許被telnet ,這時需要在交換機上配置一個ip地址,這個地址是在vlan接口上配置的
sw1(config)#int vlan 1
sw1(config-if)#ip address 172.16.0.1 255.255.0.0
sw1(config-if)#no shutdown
sw1(config)#ip default-gateway 172.16.0.254
//以上是vlan 1接口上配置了管理地址,接在vlan 1 上的計算機可以直接進行telnet 該地址,爲了其他網段的計算機也可以telnet 交換機,我們在交換機上配置了默認網關。
(5) 保存配置
sw1#copy running-config startup-config
二、交換機端口安全

(1)步驟1 :檢查r1的g0/0接口的mac地址
r1(config)#int g0/0
r1(config-if)#no shutdown
r1(config-if)#ip address 172.16.0.101 255.255.0.0
r1#show int g0/0   (查看g0/0接口的mac地址)
(2)步驟2:配置交換機端口安全
sw1(config)#int f0/1
sw1(config-if)#shutdown
sw1(config-if)#switch mode access
//以上命令是把端口改爲訪問模式,即用來接入計算機
sw1(config-if)#switch port-security
//以上命令是打開交換機的端口安全功能
sw1(config-if)#switch port-security maximum 1
//以上命令是隻允許該端口下的mac條目最大數量爲1,即只允許一個設備接入
sw1(config-if)#switch port-security violation (protect|shutdown|restrict)
//命令含義是:protect :當新的計算機接入時,如果該接口的mac條目超過最大數量,則這個新的計算機將無法接入,而原有的計算機不受影響。
shutdown :當新的計算機接入時,如果該接口的mac條目超過最大數量,則該接口將會被關閉,則這個新的計算機和原有的計算機都無法接入,需要管理員使用“no shutdown”命令重新打開。
restrict: 當新的計算機接入時,如果該接口的mac條目超過最大數量,則這個新的計算機可以接入,然而交換機將發送警告信息。
sw1(config-if)#switch port-security mac-address 0019.5535.b828(r1的mac)
//允許r1路由器從f0/1接口接入。
sw1(config-if)#no shutdown
sw1(config)#int vlan 1
sw1(config-if)#no shutdown
sw1(config-if)#ip address 172.16.0.1 255.255.0.0
//以上是配置交換機的管理地址
(3) 步驟3:檢查mac地址表
sw1# show mac-address-table
(4)步驟4 模擬非法接入
r1# ping 172.16.0.1
通!
在r1上修改g0/0的mac地址爲另個地址,模擬式另外一臺設備接入,
r1(config)#int g0/0
r1(config-if)#mac-address 12.12.12
過幾秒後,則在sw1 上出現提示f0/1接口被關閉
sw1#show int f0/1
sw1#show port-secutity
//以上命令是查看端口安全的設置情況

三、交換機的密碼恢復
(1) 拔掉交換機電源,按住交換機前面面板的mode鍵不放,接上電源,
(2) 輸入flash_init命令。
(3) 輸入load helper 命令
(4) 輸入dir flash:
//config.text 就是交換機的啓動配置文件,和路由器的startup-config 類似。
(5) 輸入rename flash:config.text flash:config.old命令
//以上是將啓動配置文件改名,這樣交換機啓動時就讀不到config.text了,從而沒有了密碼。
(6)輸入boot 命令引導系統,這時就不要在按住mode鍵了。
(7)當出現如下提示時,輸入n:
continue with the configuration dialog?{yes/no}:n
(8) 用enable 命令,進入特權模式,並將文件config.old 該回config.text,命令如下。
sw1#rename flash:config.old flash:config.text
(9) 將原配置裝入內存,命令如下:
sw1#copy flash:config.text system:running-config
(10) 修改各個密碼:
sw1#config t
sw1(config)#enable secret cisco
sw1(config)#exit
(11) 將配置寫入nvram
sw1#copy running-config start-config


四、交換機的ios恢復
(1)把計算機的串口和交換機的console口連接好,用超級終端軟件連接上交換機,
(2)交換機開機後,執行以下命令
switch:flash_init
switch:load_helper
(3) 輸入複製指令:
switch:copy xmodem: flash:c2950-i6q412-mz.121-22.ea5a.bin
(4)傳送完畢後執行以下命令:
switch :boot
啓動系統


cisco命令大全
1.switch配置命令
(1)模式轉換命令
用戶模式----特權模式,使用命令"enable"
特權模式----全局配置模式,使用命令"config t"
全局配置模式----接口模式,使用命令"interface+接口類型+接口號"
全局配置模式----線控模式,使用命令"line+接口類型+接口號"
注:
用戶模式:查看初始化的信息.
特權模式:查看所有信息、調試、保存配置信息
全局模式:配置所有信息、針對整個路由器或交換機的所有接口
接口模式:針對某一個接口的配置
線控模式:對路由器進行控制的接口配置
(2)配置命令
show running config 顯示所有的配置
show versin 顯示版本號和寄存器值
shut down 關閉接口
no shutdown 打開接口
ip add +ip地址 配置IP地址
secondary+IP地址 爲接口配置第二個IP地址
show interface+接口類型+接口號 查看接口管理性
show controllers interface 查看接口是否有DCE電纜
show history 查看歷史記錄
show terminal 查看終端記錄大小
hostname+主機名 配置路由器或交換機的標識
config memory 修改保存在NVRAM中的啓動配置
exec timeout 0 0 設置控制檯會話超時爲0
service password-encryptin 手工加密所有密碼
enable password +密碼 配置明文密碼
ena sec +密碼 配置密文密碼
line vty 0 4/15 進入telnet接口
password +密碼 配置telnet密碼
line aux 0 進入AUX接口
password +密碼 配置密碼
line con 0 進入CON接口
password +密碼 配置密碼
bandwidth+數字 配置帶寬
no ip address 刪除已配置的IP地址
show startup config 查看NVRAM中的配置信息
copy run-config atartup config 保存信息到NVRAM
write 保存信息到NVRAM
erase startup-config 清除NVRAM中的配置信息
show ip interface brief 查看接口的謫要信息
banner motd # +信息 + # 配置路由器或交換機的描素信息
description+信息 配置接口聽描素信息
vlan database 進入VLAN數據庫模式
vlan +vlan號+ 名稱 創建VLAN
switchport access vlan +vlan號 爲VLAN爲配接口
interface vlan +vlan號 進入VLAN接口模式
ip add +ip地址 爲VLAN配置管理IP地址
vtp+service/tracsparent/client 配置SW的VTP工作模式
vtp +domain+域名 配置SW的VTP域名
vtp +password +密碼 配置SW的密碼
switchport mode trunk 啓用中繼
no vlan +vlan號 刪除VLAN
show spamming-tree vlan +vlan號 查看VLA怕生成樹議
2.路由器配置命令
ip route+非直連網段+子網掩碼+下一跳地址 配置靜態/默認路由
show ip route 查看路由表
router rip 激活RIP協議
network +直連網段 發佈直連網段
interface lookback 0 激活邏輯接口
passive-interface +接口類型+接口號 配置接口爲被動模式
debug ip +協議 動態查看路由更新信息
undebug all 關閉所有DEBUG信息
router eigrp +as號 激活EIGRP路由協議
network +網段+子網掩碼 發佈直連網段
show ip eigrp neighbors 查看鄰居表
show ip eigrp topology 查看拓撲表
show ip eigrp traffic 查看發送包數量
router ospf +process-ID 激活OSPF協議
network+直連網段+area+區域號 發佈直連網段
show ip ospf 顯示OSPF的進程號和ROUTER-ID
encapsulation+封裝格式 更改封裝格式
no ip admain-lookup 關閉路由器的域名查找
ip routing 在三層交換機上啓用路由功能
show user 查看SW的在線用戶
clear line +線路號 清除線路
3.三層交換機配置命令
配置一組二層端口
configure terminal 進入配置狀態
nterface range {port-range} 進入組配置狀態
配置三層端口
configure terminal 進入配置狀態
interface {{fastethernet | gigabitethernet} interface-id} | {vlan vlan-id} | {port-channel port-channel-number} 進入端口配置狀態
no switchport 把物理端口變成三層口
ip address ip_address subnet_mask 配置IP地址和掩碼
no shutdown 激活端口
例:
Switch(config)# interface gigabitethernet0/2
Switch(config-if)# no switchport
Switch(config-if)# ip address 192.20.135.21 255.255.255.0
Switch(config-if)# no shutdown
配置VLAN
configure terminal 進入配置狀態
vlan vlan-id 輸入一個VLAN號, 然後進入vlan配態,可以輸入一個新的VLAN號或舊的來進行修改。
name vlan-name 可選)輸入一個VLAN名,如果沒有配置VLAN名,缺省的名字是VLAN號前面用0填滿的4位數,如VLAN0004是VLAN4的缺省名字
mtu mtu-size (可選) 改變MTU大小

Switch# configure terminal
Switch(config)# vlan 20
Switch(config-vlan)# name test20
Switch(config-vlan)# end

Switch# vlan database
Switch(vlan)# vlan 20 name test20
Switch(vlan)# exit
將端口分配給一個VLAN
configure terminal 進入配置狀態
interface interface-id 進入要分配的端口
switchport mode access 定義二層口
switchport access vlan vlan-id 把端口分配給某一VLAN

Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# interface fastethernet0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 2
Switch(config-if)# end
Switch#

--------------------------------------------------------------------------------

fishwfk
2006-09-15, 16:10
配置VLAN trunk
configure terminal 進入配置狀態
interface interface-Id 進入端口配置狀態
switchport trunk encapsulation {isl | dot1q | negotiate}配置trunk封裝ISL 或 802.1Q 或自動協商
switchport mode {dynamic {auto | desirable} | trunk} 配置二層trunk模式。
dynamic auto—自動協商是否成爲trunk
dynamic desirable—把端口設置爲trunk如果對方端口是trunk, desirable, 配置Native VLAN(802.1q)
或自動模式,trunk—設置端口爲強制的trunk方式,而不理會對方端口是否爲trunk
switchport access vlan vlan-id 可選) 指定一個缺省VLAN, 如果此端口不再是trunk
switchport trunk native vlan vlan-id 指定802.1Q native VLAN號
例:
Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# interface fastethernet0/4
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk encapsulation dot1q
Switch(config-if)# end
定義TRUNK允許的VLAN
configure terminal子 進入配置狀態
interface interface-id 進入端口配置
switchport mode trunk 配置二層口爲trunk
switchport trunk allowed vlan {add | all | except | remove} vlan-list可選) 配置trunk允許的VLAN.使用add, all, except, remove關健字
no switchport trunk allowed vlan 允許所有VLAN通過

Switch(config)# interface fastethernet0/1
Switch(config-if)# switchport trunk allowed vlan remove 2
Switch(config-if)# end
配置Native VLAN(802.1q)
configure terminal 進入配置狀態
interface interface-id 進入配置成802.1qtrunk的端口
switchport trunk native vlan vlan-Id 配置native VLAN號
no switchport trunk native vlan 端口配置命令回到缺省的狀態
配置基於端口權值的負載均衡

configure terminal 進入Switch 1配置狀態
vtp domain domain-name 配置VTP域
vtp mode server 將Switch 1配置成VTP server.
show vtp status 驗證VTP的配置
show vlan 驗證VLAN
configure terminal 進入配置狀態
interface fastethernet 0/1 進入F0/1端口
switchport trunk encapsulation {isl | dot1q | negotiate}配置trunk封裝
switchport mode trunk 配置成trunk
show interfaces fastethernet0/1 switchport 驗證VLAN配置
按以上步驟對想要負載均衡的接口進行配置
在另一個交換機上進行此配置
show vlan 當trunk已經起來,在switch2上驗證已經學到相的vlan配置
configure terminal 在Switch 1上進入配置狀態
interface fastethernet0/1 進入要配置的端口
spanning-tree vlan 8 port-priority 10 將端口權值10賦與VLAN 8.
spanning-tree vlan 9 port-priority 10 將端口權值10賦與VLAN 9.
spanning-tree vlan 10 port-priority 10 將端口權值10賦與VLAN 10.
interface fastethernet0/2 進入F0/2
spanning-tree vlan 3 port-priority 10 將端口權值10賦與VLAN 3.
spanning-tree vlan 4 port-priority 10 將端口權值10賦與VLAN 4
spanning-tree vlan 5 port-priority 10 將端口權值10賦與VLAN 5
spanning-tree vlan 6 port-priority 10 將端口權值10賦與VLAN 10
end 退出
show running-config 驗證配置
copy running-config startup-config 保存配置

配置STP路徑值的負載均衡
Trunk1走VLAN8-10,Trunk2走VLAN2-4

configure terminal 進入 Switch 1配置狀態
interface fastethernet 0/1 進入F0/1
switchport trunk encapsulation {isl | dot1q | negotiate}配置封裝
switchport mode trunk 配置Trunk,缺省是ISL封裝
exit 退回
在F0/2口上重複2-4步驟
exit 退回
show running-config 驗證配置
show vlan驗證switch1 已經學到Vlan
configure terminal 進入配置狀態
interface fastethernet 0/1 進入F0/1
spanning-tree vlan 2 cost 30 設置Vlan2生成樹路徑值爲30
spanning-tree vlan 3 cost 30 設置Vlan3生成樹路徑值爲30
spanning-tree vlan 4 cost 30 設置Vlan4生成樹路徑值爲30
end 退出
在switch1的F0/2上重複9-11步驟設置VLAN8,9,10生成樹路徑值爲30
end 退出
show running-config 驗證配置
copy running-config startup-config 保存配置

 


switch>                                 ;按Ctrl+Break鍵
switch:reset                            ;或用boot命令
    如果有配置文件進入用戶模式,否則提交對話:

         --- System Configuration Dialog ---

At any point you may enter a question mark '?' for help.
Use ctrl-c to abort configuration dialog at any prompt.
Default settings are in square brackets '[]'.
Continue with configuration dialog? [yes/no]:y

Enter IP address:10.65.1.8
Enter IP netmask:255.255.0.0

Would you like to enter a default gateway address? [yes]:
IP address of default gateway:
Enter host name [Switch]:swa

The enable secret is a one-way cryptographic secret used
instead of the enable password when it exists.
Enter enable secret:aaa

Would you like to configure a Telnet password? [yes]:
Enter Telnet password:a

Would you like to enable as a cluster command switch? [no]:

The following configuration command was created:
......
Press RETURN to get started.
swa>en
password:aaa
swa#


2.路由器的初始化
   路由器初始化與交換機類似,上電時按Ctrl+Break,進入ROM監控狀態

router>                               ;用戶模式,按Ctrl+Break
rommon>reset                          ;進入ROM監控狀態,復位引導
Continue with configuration dialog? [yes/no]:yes

At any point you may enter a question mark '?' for help.
Use ctrl-c to abort configuration dialog at any prompt.
Default settings are in square brackets '[ ]'.

Basic management setup configures only enough connectivity
for management of the system, extended setup will ask you
to configure each interface on the system

Would you like to enter basic management setup? [yes/no]:yes

Configuring global parameters:

Enter host name [router]:ra回車
The enable secret is a password used to protect access to
privileged EXEC and configuration modes. This password,
after entered, becomes encrypted in the configuration.
Enter enable secret:aaa回車
The enable password is used when you do not specify an
enable secret password,with some older software versions,
and some boot images.
Enter enable password:aa回車
The virtual terminal password is used to protect
access to the router over a network interface.
Enter virtual terminal password :a回車

Enter interface name used to connect to the management
network from the above interface summary:FastEthernet0/0回車

Configuring interface FastEthernet0/0:回車
Use the 100 Base-TX (RJ-45) connector? [yes]:回車
Operate in full-duplex mode? [no]:回車
Configure IP on this interface? [yes]:回車
    IP address for this interface [ ]:10.1.1.1回車
    Subnet mask for this interface [ ]:255.0.0.0回車

[0] Go to the IOS command prompt without saving this config.
[1] Return back to the setup without saving this config.
[2] Save this configuration to nvram and exit.
Enter your selection [2]:回車

ra>


3. 用命令行設置交換機和路由器的口令和主機名
   交換機和路由器的口令和主機名的設置基本相同,在提問對話時,
回答n,則進入命令行的狀態。
   先對交換機進行操作,雙擊SwitchA,出現:
switch>en                             ;第一次密碼爲空
switch#conf t                         ;進入全局配置模式
switch(config)#hostname swa           ;設置交換機名
swa(config)#enable secret aaa         ;設置特權加密口令爲 aaa
swa(config)#enable password aax       ;設置特權非密口令爲 aax
swa(config)#line console 0            ;進入控制檯口(Rs232)
swa(config-line)#password aa          ;設置登錄口令aa
swa(config-line)#login                ;登錄要求口令驗證
swa(config-line)#line vty 0 4         ;進入虛擬終端virtual tty
swa(config-line)#password a           ;設置登錄口令a
swa(config-line)#login                ;登錄要求口令驗證
swa(config-line)#exit                 ;返回上一層
swa(config)#exit                      ;返回上一層
swa#sh run                            ;看配置信息
swa#exit                              ;返回命令
swa>en
password:                             ;請問輸入哪個口 (aaa)
   secret是設置加密口令,一般都使用這種口令設置方式,它優先級高,
即沒設置secret口令時,非加密口令纔有效。

    路由器的設置與交換機類似,雙擊RouterA,進入用戶模式,例如:
router>en
router#conf t
router(config)#hostname roa
roa(config)#
......
......
    與交換機相同,不現多述。


4. 清除交換機口令
   清除交換機口令,實際中是在開機時按住交換機上的mode按鈕,在
模擬軟件中按Ctrl+Break,進入ROM方式switch:。
   配置文件是flash:config.text,與nvarm:startup-configuse相同。
switch:flash_init
switch:dir flash:
switch:delete flash:config.text
switch:delete nvram:startup-configure
switch:boot 或
switch:reset
   因爲沒有了配置文件,所以重新引導後會提示對話,要求進行配置。
有些情況下,最好用改名方法,修改口令後現將原配置恢復,再重新設置
口令後存盤。例如:
switch:flash_init
switch:rename flash:config.text config.bak
switch:boot
....
switch>en
switch#copy flash:config.bak running-configure
switch#conf t
switch(config)#en secret aaa
switch(config)#exit
switch#w       或
switch#copy run start
switch#reload


5. 清除路由器口令
   路由器2621的配置文件不讓刪除和改名,需要採用設置寄存器開關的
方法實現。
   實際當中是在上電時,按Ctrl+Break。在軟件模擬中,雙擊RouterA
進入終端模式,再按Ctrl+Break進入rommon>狀態,操作如下:

rommon>                               ;進入ROM監控狀態
rommon>confreg 0x2142                 ;跳過配置文件適用26xx 36xx 45xx
rommon>reset                          ;重新引導,等效於重開機

Continue with configuration dialog? [yes/no]:no
router>en
router#conf t
router(config)#enable secret bbb      ;設置特權加密口令爲 bbb
router(config)#c onfig-register 0x2102 ;正常使用配置文件
router(config)#exit
router#exit
router>
router>en
password:bbb

6. 備份IOS和配置文件
   在實際工作中經常需要備份路由器的IOS和配置文件,以備系統有問題時的
恢復。可以這樣操作:
router#dir nvram:
router#copy flash:c2621.bin tftp:
router#copy startup-config tftp:

router#

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章