配置思科交換機用到哪些基本命令

  交換機除了能夠連線同種型別的網路之外,還可以在不同型別的網路***如乙太網和快速乙太網***之間起到互連作用。這篇文章主要介紹了Cisco 交換機基本配置命令及學習心得,需要的朋友可以參考下

  具體介紹

  1:配置登入使用者,口令等

  Switch> //使用者直行模式提示符

  Switch>enable //進入特權模式

  Switch# //特權模式***配置密碼後必須輸入密碼才可進入特 權模式***

  Switch#config terminal //進入全域性配置模式

  Switch***config***# //配置模式提示符

  Switch***config***#hostname xxx //設定主機名成為xxx這裡使用CISCO 2960G

  CISCO 2960G***config***#enable password xxx //設定使能口令為明文顯示為xxx

  CISCO 2960G***config***#enable secret xxx //設定使能口令為密文顯示為xxx

  CISCO 2960G***config***#line vty 0 15 //設定虛擬終端線,通過telnet方式 登入允許0-15個使用者同事登入

  CISCO 2960G***config-line***#login //設定遠端telnet遠端登入驗證

  CISCO 2960G***config-line***#password xxx //設定telnet登入密碼

  2:cisco2960 VLan設定

  CISCO 2960G> enable //進入特權模式

  CISCO 2960G#vlan database //進入vlan設定

  CISCO 2960G***vlan***#vlan 2 name xxx //建立vlan 2,並給vlan命名

  CISCO 2960G***vlan***#no vlan 2 v //刪除vlan 2

  CISCO 2960G***vlan***#exit //回到特權模式下

  埠設定命令:

  CISCO 2960G***config***#interface fastethernet0/1 //進入網口1,簡化命令 int f0/1 ,0/1指的是第一個插槽上的第一個網口

  CISCO 2960G***config-if***# //介面檢視模式

  CISCO 2960G***config-if***#shutdown //關閉當前埠

  CISCO 2960G***config-if***#no shutdown //開啟當前埠

  CISCO 2960G***config***#interface gigabyte0/1 //進入匯聚千兆口1,簡化命令 int giga0/1指的是第一個插槽上的第一個匯聚網口

  CISCO 2960G***config-if***#

  CISCO 2960G***config-if***#duplex auto/full/half //設定埠工作模式為 自適應/全雙通/半雙通

  CISCO 2960G***config-if***#switchport mode trunk //設定當前埠模式為匯聚口

  CISCO 2960G***config-if***#switchport mode access //設定當前埠模式為接入模式

  CISCO 2960G***config-if***#switchport trunk allowed vlan 1,2 //設定當前匯聚埠允許vlan1,2通過,vlan修剪,預設為all,全部允許

  CISCO 2960G***config-if***#switchport trunk vlan 2 //設定當前匯聚埠允許vlan 2通過,vlan修剪

  CISCO 2960G***config-if***#switchport access vlan 2 //將當前埠加入到vlan 2中

  CISCO 2960G***config-if***#switchport trunk encap dot1q //設定vlan中繼

  將埠加入vlan

  CISCO 2960G***config***#interface fastethernet0/1

  CISCO 2960G***config-if***#switchport mode access

  CISCO 2960G***config-if***#switchport access vlan 2

  將多個埠加入到VLAN中

  CISCO 2960G***config***#interface range f0/1 - 10

  CISCO 2960G***config-if-range***#switchport mode access

  CISCO 2960G***config-if-range***#switchport access vlan 2

  CISCO 2960G#show vlan brief //用於檢視配置後結果

  CISCO 2960G#show vlan //用於檢視配置後結果

  3:設定VTP cisco專有的vlan終極協議也成為區域網幹道協議,作用是十幾臺交換機在企業網中,配置VLAN工作量大,可以使用VTP協議,把一臺交換機配置成VTP Server, 其餘交換機配置成VTP Client,這樣他們可以自動學習到server 上的VLAN 資訊

  switch***config***#vtp domain xxxx //設定發vtp域名

  switch***config***#vtp password xxxx //設定發vtp密碼

  switch***config***#vtp mode server //設定發vtp模式為 vtp伺服器

  switch***config***#vtp mode client //設定發vtp模式為 vtp客戶端

  4:交換機配置IP地址

  switch***config***#interface vlan 1 //進入vlan 1

  switch***config-if***#ip address 119.167.223.221 255.255.255.128 //設定交換機的管理ip地址

  switch***config***#ip default-gateway 119.167.223.254 //設定交換機的預設閘道器

  switch***config***#end //退出當前模式

  5: 交換機儲存設定命令

  switch#write //儲存配置資訊

  switch#copy running-config startup-config //將當前正在使用中的配置儲存到交換機開機需要載入的配置檔案裡去。

  6:交換機顯示命令

  特權模式下:

  switch#show vtp //顯示vtp配置資訊

  switch#show run //顯示當前配置資訊

  switch#show running-config //顯示當前正在使用的配置資訊

  switch#show startup-config //交換機開機是自動載入的 配置檔案

  switch#show vlan //顯示vlaner配置資訊

  switch#show interfaces //顯示埠配置資訊

  switch#show interfaces fastethernet 0/1 switchport //顯示二層埠狀態,可以用來決定此口是否為二層或三層口

  switch#show int f0/1 //檢視指定埠配置資訊 show interface fastethernet0/1

  switch#show ip interface vlan100 //檢視交換機vlan100的ip配置資訊

  switch#show version //檢視交換機韌體版本資訊

  7:基於埠的mac地址繫結

  switch#config terminal //進入配置檢視模式

  switch***config***#interface fasrethernet 0/1 //進入具體埠檢視模式下

  switch***config-if***#switchport port-secruity //配置埠安全模式

  switch***config-if***#switchport port-secruity mac-address MAC***主機的mac地址*** //配置該埠要繫結的主機的MAC地址

  switch***config-if***#no switchport port-secruity mac-address MAC***主機的mac地址*** //刪除繫結主機的mac地址

  8:配置交換機的snmp功能

  switch***config***#snmp-server community xxx ro //xxx為自定義的共同體名稱,並且團體的許可權為只讀。

  switch***config***#snmp-server trap-source FastEthernet0/3/0 //設定snmp監控的埠,此埠必須要配置IP地址才行

  switch***config***#snmp-server trap-source vlan 100 /把vlan 100介面作為監控埠

  switch***config***#snmp-server host x.x.x.x***ip地址*** xxx***團體名*** //設定管理機x.x.x.x,同時允許該管理機以團體明xxx訪問。

  switch***config***#snmp-server host 119.167.223.221 zy //例子

  switch***config***#snmp-server enable traps //啟用snmp服務

  9:交換機禁ping配置

  switch***config***#access-list 110 deny icmp any any //配置訪問控制列表***Access Control List,ACL***110指的ICMP對應ping。

  switch***config***#access-list 110 permit ip any any //執行所有的IP協議的應用

  switch***config***#int vlan 1

  switch***config-if***#ip access-group 110 in

  switch***config***#int vlan 2

  switch***config-if***#ip access-group 110 in

  switch***config***#int vlan 3

  switch***config-if***#ip access-group 110 in

  switch***config***#int fasrethernet 0/X

  switch***config-if***#ip access-group 110 in //埠X上禁ping

  10:恢復交換機出廠設定

  思科交換機分為兩種系統,分別是IOS和CatOS,下面介紹IOS版本的操作,

  Switch#write erase

  Erasing the nvram filesystem will remove all files! Continue? [confirm]y[OK]

  Erase of nvram: complete

  Swtich# delete ------------老版本需做此操作。

  Delete filename [vlan.dat]?

  Delete ? [confirm]y

  Switch#reload

  另一種方法是啟動的時候按Mode進入引導模式,執行如下命令:

  flash_init

  rename

  boot

  11: 埠匯聚

  console>enable

  console#config

  console***config***#interface gigaethernet 0/1

  console***config-if***#speed 1000

  console***config-if***#duplex full

  console***config***#interface gigaethernet 0/2

  console***config-if***#speed 1000

  console***config-if***#duplex full

  console***config-if***#exit

  console***config***#interface range gigaethernet 0/1-0/2

  console***config-if***#channel-group 1 mode on/auto

  console***config-if***#switchport mode trunk

  console***config-if***#switchport trunk allowed vlan all

  console#show etherchannel summary //檢視埠匯聚狀態。

  另外一臺交換機的對應匯聚埠務必要和這裡兩個匯聚口的設定一樣。

  R1#vlan database

  R1***vlan***#vlan 2

  R1***vlan***#exit

  R1#configure terminal

  R1***config***#int range fastethernet 0/1-4

  R1***config-int-range***# switchport access vlan 2

  R1***config-int-range***# channel-group 1 mode on

  R2#vlan database

  R2***vlan***#vlan 2

  R2***vlan***#exit

  R2#configure terminal

  R2***config***#int range fastethernet 0/1-4

  R2***config-int-range***# switchport access vlan 2

  R2***config-int-range***# channel-group 1 mode on

  同一個vlan裡匯聚,埠使用access狀態,多個VLAN之間匯聚端口才需要trunk狀態。

  相關閱讀:交換機工作原理過程

  交換機工作於OSI參考模型的第二層,即資料鏈路層。交換機內部的CPU會在每個埠成功連線時,通過將MAC地址和埠對應,形成一張MAC表。在今後的通訊中,發往該MAC地址的資料包將僅送往其對應的埠,而不是所有的埠。因此,交換機可用於劃分資料鏈路層廣播,即衝突域;但它不能劃分網路層廣播,即廣播域。

  交換機擁有一條很高頻寬的背部匯流排和內部交換矩陣。交換機的所有的埠都掛接在這條背部總線上,控制電路收到資料包以後,處理埠會查詢記憶體中的地址對照表以確定目的MAC***網絡卡的硬體地址***的NIC***網絡卡***掛接在哪個埠上,通過內部交換矩陣迅速將資料包傳送到目的埠,目的MAC若不存在,廣播到所有的埠,接收埠迴應後交換機會“學習”新的MAC地址,並把它新增入內部MAC地址表中。使用交換機也可以把網路“分段”,通過對照IP地址表,交換機只允許必要的網路流量通過交換機。通過交換機的過濾和轉發,可以有效的減少衝突域,但它不能劃分網路層廣播,即廣播域。