網絡設備管理-cisco交換機

#####1、交換機基本配置

以太網交換機工作在OSI參考模型的數據鏈路層,主要功能是提供網絡數據包優化和轉發

交換機的連接方式有級聯和堆疊

終端訪問安全配置:

配置交換機ip,交換機所有端口默認屬於vlan 1
interface vlan 1
ip address 192.168.1.4 255.255.255.0
no sh

配置控制檯訪問口令
conf t
line console 0
exec-timeout 180
password CCNA
login

配置telnet
line vty 0 4    #從全局配置模式切換爲vty線路0到4的線路配置模式
exec-timeout seconds	#設置超時連接的時間。取值範圍0~35791,建議採用180
password CCNA
login     		#開啓登錄口令驗證
也可以使用本地的用戶數據進行登錄驗證,這時就不用設置password
login local

配置SSH
conf t
Switch(config)#hostname sw1						#生成密鑰對時不能使用交換機默認的設備名,否則會報錯
Switch(config)#ip domain-name <domain-name> 		#根據SSH的認證機制,必需要給本機配置一個域名才能生成密鑰對進行加密
Switch(config)#crypto key generate rsa				#生成RSA密鑰對
Switch(config)#ip ssh version <1|2>				#選擇要使用的ssh版本(默認使用版本1),並非所有的設備都支持SSH版本2,並且密匙長度至少需要768bits的模長才能使用版本2。
Switch(config)#ip ssh authentication-retries <0-5>			#修改認證次數( 默認爲認證時需要輸入三次密碼)
Switch(config)#ip ssh time-out <1-120>			#修改認證超時時間(默認爲120s)
Switch#show ip ssh							#查看SSH協議狀態(特權模式)
Switch#show ssh								#查看ssh連接(特權模式下)
sw1(config)#username zwish privilege 10 password zwish		#配置本地數據庫,用於SSH認證
sw1(config)#line vty 0 4
sw1(config0line)#transport input ssh
sw1(config0line)#login local							#配置vty登錄使用SSH協議,並使用本地數據庫認證
#pt裏的客戶端pc登錄:ssh -l username target

二層交換機基本配置

交換機的單個物理端口默認只有第二層交換功能,交換機接口可分爲Access Port和Trunk Port;

端口爲Access Port時,端口只能屬於一個vlan,Access Port只傳輸屬於這個vlan的幀

端口爲Trunk Port時,端口傳輸多個vlan的幀,缺省情況下Trunk Port將傳輸所有vlan的幀,可通過設置vlan許可列表來限制傳輸哪些vlan的幀

interface if-id
或指定一個範圍的接口
interface range f0/1-5
speed {10|100|1000|auto}		#設置接口的速率
duplex {auto|ful|half}			#設置接口的雙工模式
flowcontrol {auto|ful|ff}		#設置接口的流控模式

#單交換機的VLAN配置(基於端口)
Switch#conf t
Switch(config)#vlan vlan-id
Switch(config-vlan)#name vlan-name
Switch(config)#interface if-id
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan vlan-id
Switch(config)#end
Switch#show vlan brief
Switch#show interfaces if-id switchport

#跨交換機
interface if-id
switchport mode trunk
switchport trunk native vlan vlan-id

#定義trunk口的許可vlan列表
switchport trunk allowed vlan {all|[add|remove|except]} vlan-list
例:switchport trunk allowed vlan remove 2


#VTP
Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#hostname SW1
SW1(config)#vtp domain zwish.com
Changing VTP domain name from NULL to zwish.com
SW1(config)#vtp mode server
Device mode already VTP SERVER.
SW1(config)#vtp password zwish
Setting device VLAN database password to zwish
SW2#show vtp status
SW1(config)#interface f0/1
SW1(config-if)#switchport mode trunk

Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#hostname SW2
SW2(config)#interface f0/1
SW2(config-if)#switchport mode trunk
SW2(config-if)#exit
SW2(config)#vtp domain zwish.com
Domain name already set to zwish.com.
SW2(config)#vtp mode client
Setting device to VTP CLIENT mode.
SW2(config)#vtp password zwish
Setting device VLAN database password to zwish
SW2#show vtp status
然後在SW1,即server上新建vlan,會發現SW2也會建立相應的vlan
這裏本來在SW1上還有個vtp修剪功能,可以使SW2不建立SW1上的某個vlan,但實驗的交換機好像沒有這個功能
命令是:switchport Trunk pruning vlan remove vlan-id
2、生成樹協議和端口聚合實例

在這裏插入圖片描述

這裏生成樹協議選擇rstp,先給sw01、sw02、sw03配置一下rstp

sw01(config)#spanning-tree mode rapid-pvst 
sw02(config)#spanning-tree mode rapid-pvst 
sw03(config)#spanning-tree mode rapid-pvst 

鏈路聚合

#sw01
interface port-channel 1
interface range f0/1-2
switchport mode trunk
channel-group 1 mode on

interface port-channel 3
interface range f0/3-4
switchport mode trunk
channel-group 3 mode on

vlan 10
name zw1
interface f0/10
switchport mode access
switchport access vlan 10


#sw02
interface port-channel 1
interface range f0/1-2
switchport mode trunk
channel-group 1 mode on

interface port-channel 2
interface range f0/5-6
switchport mode trunk
channel-group 2 mode on

vlan 20
name zw2
interface f0/20
switchport mode access
switchport access vlan 20


##sw03
interface port-channel 3
interface range f0/3-4
switchport mode trunk
channel-group 3 mode on

interface port-channel 2
interface range f0/5-6
switchport mode trunk
channel-group 2 mode on

vlan 20
name zw2
interface f0/20
switchport mode access
switchport access vlan 20

##查看配置
show spanning-tree
show vlan
show etherchannel summary

#下面的語句添加到對應的交換機
no spanning-tree vlan 10
no spanning-tree vlan 20
3、綜合實驗

在這裏插入圖片描述

1.配置三臺交換機的主機名、特權模式密碼,啓用Telnet訪問,密碼統一爲ccna。
2.三臺交換機以雙鏈路互聯,需要在啓用 RSTP避免環路的同時,提供鏈路的冗餘備份功能。

3.兩兩交換機之間的冗餘鏈路上實現端口聚合,並且在聚合端口上設置 Trunk,流量平衡基於源MAC地址。
4.在交換機SW1、交換機SW2、交換機SW3上開啓安全端口,進行MAC地址動態綁定(發送廣播幀),安全策略是restrict。
5.在交換機SW1劃分VLAN 2(1-4)、VLAN3(5-8),交換機SW2劃分VLAN4(1-4)、VLAN5(5-8),交換機SW3劃分VLAN6(1-4)、VLAN7(5-8)。

這裏應先配置dhcp,給所有pc分配了ip之後,再劃分vlan

相關命令

#生成樹
spanning-tree
#端口聚合
interface port-channel 3
interface range f0/3-4
switchport mode trunk
channel-group 3 mode on

#安全端口(設置mac地址爲動態綁定)
Switch#config terminal
Switch(config)#interface range f0/1-20 //進入需要配置的端口
Switch(config-if)#switchport mode Access //設置爲交換模式
Switch(config-if)#switchport port-security //打開端口安全模式
Switch(config-if)#switchport port-security violation {protect | restrict | shutdown } 
Switch(config-if)#switchport port-security mac-address sticky


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