CISCO 2950交換機配置參考
這是本人在近期的網路技術培訓中對於交換機的學習記錄,列舉了CISCO 2950交換機的常用配置命令,並進行了簡要說明。
交換機配置
介面設定
Switch(config-if)#duplex [full|half|auto]//設定介面雙工模式
Switch(config-if)#speed [10|100|auto]//介面速率
介面安全
安全介面
Switch(config-if)#sw port-security
Switch(config-if)#sw port-security maximum 1//
Switch(config-if)#sw port-security mac-address [sticky] H.H.H //
說明:設定了安全介面後,就會只學習連線到該介面的MAC地址。如果指定了最大地址數(maximum),則只學習限定地址數的MAC地址。
Trunk介面和監控介面不能配置為安全介面。
介面保護
Switch(config-if)#sw protected//被保護的埠必須指定一個唯一的VLAN ID,它不會向其它被保護埠傳送任何資料包,但可以向非保護埠轉發資料。如果被保護埠向其它交換機發送資料,需要通過trunk介面。
介面地址繫結
Switch(config)#mac access-list extended mac10 //mac10為定義的訪問列表名
switch(config-ext-macl)#permit
switch(config-if)mac access-group mac10 in //在介面中應用訪問列表
IP地址繫結與此類似,只需要將前面的mac換成IP即可。
預設閘道器
Switch(config)#ip default-gateway 192.168.1.1 //設定預設閘道器
VLAN基本配置
定義VLAN
switch# vlan database
switch (vlan)# vlan 10 //配置vlan號
說明:要配置擴充套件VLAN號(1006-4096),則必須將交換機設定為透明(transparent)模式。標準vlan號為1-1005。
設定管理VLAN
指定介面所在
switch (config-if)sw mode acc //配置介面為訪問模式
switch (config-if)#sw acc vlan 8//將介面加入到vlan 8中
VLAN的IP地址和預設閘道器
switch (config-if)#int vlan8//進入vlan介面配置模式
switch (config-if)#ip addr 192.168.1.7 255.255.255.0//設定vlan的ip地址
Switch(config)#ip default-gateway 192.168.1.1 //預設閘道器
VTP模式
switch (vlan)#vtp domain domainname password pass1 //配置vtp域名,密碼為pass1
switch (vlan)# vtp [server|client]//配置交換機為vtp伺服器/客戶模式
VTP修剪
Switch(config)#VTP prunning//啟用VTP修剪
Switch(config-if)#sw trunk vlan [vlan-list]//在介面上對指定vlan進行修剪
trunk設定
Switch(config)# interface interface mod/port
Switch(config-if)# switchport mode trunk//介面配置為trunk模式
Switch(config-if)# switchport trunk encapsulation {isl | dot1q} //封閉的trunk協議
swtich(config-if)#sw trunk allowed vlan [VlanID]//設定允許通過的VLAN號
Switch(config-if)# switchport trunk allowed vlan remove vlan-list
Switch(config-if)# switchport trunk allowed vlan add vlan-list
switch(config-if)#sw trunk prunning vlan [vlanid|add|remove|except|none]//對指定VLAN進行修剪。
Switch(config-if)#sw trunk native vlan 30 //將vlan30設定為native vlan
Switch(config-if)#sw nonegotiate //該介面上不執行協商協議
Switch#show interfacesF0/1 switchport//檢查介面上的trunk/access狀態
檢視VLAN狀態
Switch#sh vlan
動態VLAN TRUNK
Switch(config-if)#sw mode dynamic desirable //設定介面模式為動態
埠映象
s(config)#monitor session 1 destion interface gi0/1//採用gi0/1為映象埠
Switch(config)#monitor session 1 source intface fa0/1 – 24//將1到24號快速乙太網埠作為被監控物件
生成樹配置
基本配置
Switch(config)#span mode [mst|pvst|rapid pvst]//生成樹型別,預設為pvst。Mst模式不支援對單個vlan進行配置,而pvst則可以。Mst的trunk封裝802.1Q,而pvst的trunk封裝為ISL。
驗證:#sh span sum
Switch(config)#span loopguard default//在所有介面上預設啟用環回保護。阻止根介面或預備介面成為指定介面,阻止根介面和預備介面傳送BPDU。介面上有相應配置,可覆蓋預設預設。驗證:#sh span sum
Switch(config-if)#span port-priority 128 //修改介面的優先順序。驗證:#sh span int f0/7 (假定為7號埠)
Switch(config-if)#span vlan 20 port-priority 128 //介面是trunk模式時,可對不同的VLAN設定不同的優先順序值,覆蓋介面優先順序值。驗證:#sh span int f0/7 或#sh span vlan 20
Switch(config-if)#span link-type [point-to-point|shared] //鏈路型別。全雙工介面被認為是點對點型別,而半雙工介面被認為是共享鏈路型別。
根網橋
switch(config)#spanning-tree vlan 10 root primary|secondary //設定此交換機為vlan10的生成樹的主要(次要)根驗證:#sh span vl 10
switch(config)#spanning-tree vlan10 priority 0//優先順序,4096的倍數,預設為32768。驗證:#span vl 10
switch(config-if)#spanning-tree guard root //根保護驗證:#sh run
生成樹快速收斂配置
Switch(config)#span backbonefast //啟用快速幹線。驗證:#sh span sum
Switch(config)#span uplinkfast //啟用快速上連線路,不能用於根網橋。驗證:#sh span sum
Switch(config)#span portfast default //在所有access介面上預設啟用portfast,這樣介面在啟動時直接進入轉發狀態。在介面上的配置會覆蓋全域性的預設配置。驗證:#sh span sum
類似的命令還有:
Switch(config)#Span portfast bpdufilter default //預設在啟用了portfast介面上進行bpdu過濾,即阻止在該埠傳送和接收BPDU。
Switch(config)#span portfast bpduguard default//預設在啟用了portfast介面上進行bpdu保護。在配置有錯時,將收到bpdu的介面置為error-disable狀態,這樣可以幫助排除錯誤配置,因為不排除故障就無法使用介面。
Switch(config)#span uplinkfast max-update-rate 150 //通知上游交換機鏈路狀態改變的頻率。範圍0-32000,預設150。驗證:#sh spanning-tree summary
Swtich(config)#span vlan 20 hello-time 2//設定hello時間間隔,範圍0-10,預設2,只需要在根網橋上設定。驗證:#sh span vlan 20
Switch(config)#span vlan 20 forward-time 15 //埠狀態轉換前停留時間,範圍4-30,,預設15,只需在根網橋上設定。(埠狀態轉換是指監聽到學習,或學習到轉發)
Swtich(config)span vlan 20 max-age 20 //設定通過指定介面從鄰居收到的BPDU儲存的最大生命週期,超過時埠轉入監聽狀態,範圍6-40,預設20。
負載均衡
負載均衡的基本策略:通過修改port-priority或port cost值,將不同的VLAN流量從不同的trunk上通過。假設有VLAN10,20,30,40,分別通過兩個埠f0/3,f0/4的trunk鏈路。可做如下配置。
1、讓VLAN10,20從f0/3通過
Switch(config)#int f0/3
Switch(config-if)#sw mode trunk
Switch(config-if)#span vlan 10 port-priority 16 //優先順序按16增加,預設為128。
Switch(config-if)#span vlan 20 port-prioprity 16
2、讓vlan 30,40 預設從f0/4通過
Switch(config)#int f0/4
Switch(config-if)#span vlan 30 port-priority 16
Switch(config-if)#span vlan 40 port-prority 16
注:這樣的配置,需要生成樹模式為pvst,在正常情況下,VLAN10,20的流量將從3號埠轉發,而VLAN30,40的流量將從4號埠轉發。當3號埠的鏈路中斷時,VL10,20的流量將自動通過4號埠轉發。當然,若不修改port-priority,而是象上面一樣修改cost值(使cost值比預設的要小),能達到相同的效果。
鏈路聚合
Switch(config)#port-channel load-balancesrt/dst//在多個介面間進行負載均衡
switch(config-if)#Channel-group 1 mode on|active|passive //在介面上啟用以太通道模式/LACP/PAGP
switch(config-if)#channel-protocol LACP|pAgp//設定以太通道使用的協議
switch(config-if)#Switchport mode trunk //設定介面為trunk模式,以便所有(或指定VLAN的)流量都能通過
顯示以太通道配置情況
Switch#sh eth port//可顯示以太通道的介面列表和介面引數
Switch#sh eth port-channel //顯示以通道列表
Swtich#sh eth protocol//顯示以太通道組列表和各以太通道使用的協議。
snmp設定
對交換機進行網路管理,必須給交換機設定一個IP地址。
Switch(config)#int vlan 1//進入VLAN1介面,以便設定管理地址
Switch(config-if)#ip add 192.168.1.1 255.255.255.0 //
Switch(config)#snmp-server community public [ro|rw] //設定共同體名稱public和讀(寫)引數ro(rw) .
Switch(config)#snmp-server host 81.129.1.1 traps public //設定traps的接收主機
交換機上的組播配置
Switch(config)#ip igmp snooping [vlan vlanID] //啟用IGMP snooping 。也可以在介面模式下進行類似設定。
手工新增MAC地址表
Switch(config)#mac-address-table static [HH.HH.HH] vlan [VlanID] interface F0/9 //新增MAC地址HH.HH.HH對應的埠為F0/9.
Switch#show mac-address-table//驗證MAC地址表