借助安全端口,可以只允許指定的MAC地址或指定數(shù)量的MAC地址訪問某個(gè)端口,從而避免未經(jīng)授權(quán)的計(jì)算機(jī)接入網(wǎng)絡(luò),或限制某個(gè)端口所連接的計(jì)算機(jī)數(shù)量,從而確保網(wǎng)絡(luò)接入的安全。
當(dāng)配置端口安全時(shí),應(yīng)當(dāng)注意以下問題:
安全端口不能是Trunk端口。
安全端口不能是Switch Port Analyzer (SPAN)的目的端口。
安全端口不能是屬于EtherChannel的端口。
安全端口不能是private-VLAN端口。
1.配置安全端口
Switch# configure terminal
Switch(config)# interface interface_id
Switch(config-if)# switchport mode access第三步:將接口設(shè)置為訪問模式。
Switch(config-if)# switchport port-security 第四步:在接口啟用端口安全。
第五步:(可選)在接口設(shè)置安全MAC地址的最大數(shù)量,以限制該端口所連接的計(jì)算機(jī)數(shù)量。取值范圍為1~3 072,默認(rèn)值是1。Switch(config-if)# switchport port-security maximum value
第六步:(可選)設(shè)置違例發(fā)生后的處理模式。當(dāng)安全違例事件發(fā)生時(shí),將端口置于restrict或shutdown模式。選擇restrict模式時(shí),當(dāng)非法MAC地址或太多MAC連接至該接口時(shí),將丟棄數(shù)據(jù)包,并向網(wǎng)管計(jì)算機(jī)發(fā)送SNMP陷阱通知。選擇shutdown模式時(shí),發(fā)生安全錯(cuò)誤的端口將被置于error-disable狀態(tài),除非網(wǎng)絡(luò)管理員使用no shutdown命令手工激活,否則該端口失效。
Switch(config-if)# switchport port-security violation {restrict | shutdown}
第七步:設(shè)置壞包速率限制。
Switch(config-if)# switchport port-security limit rate invalid-source-mac
第八步:(可選)為該接口指定安全MAC地址。也可以使用該命令指定最大安全MAC 地址數(shù)。如果指定的MAC地址數(shù)量少于安全地址的最大數(shù)量,動(dòng)態(tài)學(xué)習(xí)的MAC地址將被保留。
Switch(config-if)# switchport port-security mac-address mac_address
第九步:在端口啟動(dòng)sticky learning。
Switch(config-if)# switchport port-security mac-address sticky
第十步:返回特權(quán)EXEC模式。
Switch(config-if)# end
第十一步:查看并校驗(yàn)配置。
Switch# show port-security address interface interface_id
Switch# show port-security address
第十二步:保存當(dāng)前配置。
Switch# copy running-config startup-config
【注意】 使用no switchport port-security mac-address mac_address命令,可以從地址表中刪除MAC地址。
2.設(shè)置端口安全老化
當(dāng)為端口指定最大MAC地址數(shù)時(shí),為了保障該端口能夠得以充分利用,可以采用設(shè)置端口安全老化時(shí)間和模式的方式,使系統(tǒng)能夠自動(dòng)刪除長時(shí)間未連接的MAC地址,從而不必手動(dòng)刪除,減少網(wǎng)絡(luò)維護(hù)的工作量。
Switch# configure terminal
Switch(config)# interface interface_id
Switch(config-if)# switchport port-security [ aging time aging_time | type {absolute | inactivity} ]
第三步:為安全端口設(shè)置老化時(shí)間和老化類型。老化時(shí)間的取值范圍為0 ~ 1440分鐘。采用absolute模式時(shí),一旦到達(dá)指
定的老化時(shí)間,那么,即將從安全地址列表中移除。采用inactivity時(shí),即使到達(dá)指定的老化時(shí)間,如果沒有其他數(shù)據(jù)通
信,那么,MAC地址仍然被保留在安全地址列表中。
Switch(config-if)# end
Switch# show port security [interface interface_id] [address] 查看并校驗(yàn)配置。
Switch# copy running-config startup-config