MAC地址與交換機端口綁定(交換機端口安全)

我們通常說的MAC地址與交換機端口綁定其實就是交換機端口安全功能。端口安全功能能讓您配置一個端口只允許一臺或者幾臺確定的設備訪問那個交換機;能根據MAC地址確定允許訪問的設備;允許訪問的設備的MAC地址既可以手工配置,也可以從交換機“學到”;當一個未批准的MAC地址試圖訪問端口的時候,交換機會掛起或者禁用該端口等等。
 

sw1#show run int f0/1
Building configuration...

Current configuration : 160 bytes
!
interface FastEthernet0/1
 switchport mode access
 switchport port-security
 switchport port-security violation shutdown
 switchport port-security mac-address 001f.162c.f110 
 spanning-tree portfast
end
sw1#

Found duplicate mac-address 001f.162c.f110
clear mac-address-table dynamic address mac|j
1.端口mac被其他的端口給綁定過了
2.端口上打no switchport portsecurity
3.上聯的端口可能打了switchport portsecurity mac address 1111.1111.1111.111 ,所以導致下聯的設備無法再次綁定此mac-address

 一、首先必須明白兩個概念:

可靠的MAC地址。配置時候有三種類型。

靜態可靠的MAC地址:在交換機接口模式下手動配置,這個配置會被保存在交換機MAC地址表和運行配置文件中,交換機重新啓動後不丟失(當然是在保存配置完成後),具體命令如下:

Switch(config-if)#switchport port-security mac-address Mac地址

動態可靠的MAC地址:這種類型是交換機默認的類型。在這種類型下,交換機會動態學習MAC地址,但是這個配置只會保存在MAC地址表中,不會保存在運行配置文件中,並且交換機重新啓動後,這些MAC地址表中的MAC地址自動會被清除。

黏性可靠的MAC地址:這種類型下,可以手動配置MAC地址和端口的綁定,也可以讓交換機自動學習來綁定,這個配置會被保存在MAC地址中和運行配置文件中,如果保存配置,交換機重起動後不用再自動重新學習MAC地址,雖然黏性的可靠的MAC地址可以手動配置,但是CISCO官方不推薦這樣做。具體命令如下:

Switch(config-if)#switchport port-security mac-address sticky
其實在上面這條命令配置後並且該端口得到MAC地址後,會自動生成一條配置命令
Switch(config-if)#switchport port-security mac-address sticky Mac地址
這也是爲何在這種類型下CISCO不推薦手動配置MAC地址的原因。

二、違反MAC安全採取的措施:
當超過設定MAC地址數量的最大值,或訪問該端口的設備MAC地址不是這個MAC地址表中該端口的MAC地址,或同一個VLAN中一個MAC地址被配置在幾個端口上時,就會引發違反MAC地址安全,這個時候採取的措施有三種:

1.保護模式(protect):丟棄數據包,不發警告。

2.限制模式(restrict):丟棄數據包,發警告,發出SNMP trap,同時被記錄在syslog日誌裏。

3.關閉模式(shutdown):這是交換機默認模式,在這種情況下端口立即變爲err-disable狀態,並且關掉端口燈,發出SNMP trap,同時被記錄在syslog日誌裏,除非管理員手工激活,否則該端口失效。

具體命令如下:

Switch(config-if)#switchport port-security violation {protect | restrict | shutdown }
下面這個表一就是具體的對比
Violation Mode Traffic is forwarded Sends SNMP trap Sends syslog message Displays error
message Shuts down port
protect No No No No No
restrict No Yes Yes No No
shutdown No Yes Yes No Yes
表一

配置端口安全時還要注意以下幾個問題:

端口安全僅僅配置在靜態Access端口;在trunk端口、SPAN端口、快速以太通道、吉比特以太通道端口組或者被動態劃給一個VLAN的端口上不能配置端口安全功能;不能基於每VLAN設置端口安全;交換機不支持黏性可靠的MAC地址老化時間。protect和restrict模式不能同時設置在同一端口上。
下面把上面的知識點連接起來談談實現配置步驟的全部命令。

1.靜態可靠的MAC地址的命令步驟:

Switch#config terminal
 Switch(config)#interface interface-id 進入需要配置的端口
 Switch(config-if)#switchport mode Access 設置爲交換模式
 Switch(config-if)#switchport port-security 打開端口安全模式

Switch(config-if)#switchport port-security violation {protect | restrict | shutdown }
上面這一條命令是可選的,也就是可以不用配置,默認的是shutdown模式,但是在實際配置中推薦用restrict。

Switch(config-if)#switchport port-security maximum value
上面這一條命令也是可選的,也就是可以不用配置,默認的maximum是一個MAC地址,2950和3550交換機的這個最大值是132。

其實上面這幾條命令在靜態、黏性下都是一樣的,
Switch(config-if)#switchport port-security mac-address MAC地址
上面這一條命令就說明是配置爲靜態可靠的MAC地址

2.動態可靠的MAC地址配置,因爲是交換機默認的設置。
3.黏性可靠的MAC地址配置的命令步驟:
Switch#config terminal
  Switch(config)#interface interface-id
  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 maximum value 字串4

上面這幾天命令解釋和前面靜態講到原因一樣,不再說明。

Switch(config-if)#switchport port-security mac-address sticky
上面這一條命令就說明是配置爲黏性可靠的MAC地址。
最後,說說企業中如何快速MAC地址與交換機端口綁定。在實際的運用中常用黏性可靠的MAC地址綁定,現在我們在一臺2950EMI上綁定。

方法1:在CLI方式下配置
2950 (config)#int rang fa0/1 - 48
2950 (config-if-range)#switchport mode Access
2950 (config-if-range)#switchport port-security
2950 (config-if-range)#switchport port-security mac-address violation restrict
2950 (config-if-range)#switchport port-security mac-address sticky
這樣交換機的48個端口都綁定了,注意:在實際運用中要求把連在交換機上的PC機都打開,這樣才能學到MAC地址,並且要在學到MAC地址後保存配置文件,這樣下次就不用再學習MAC地址了,然後用show port-security address查看綁定的端口,確認配置正確。

方法2:在WEB界面下配置,也就是CMS(集羣管理單元)
我們通過在IE瀏覽器中輸入交換機IP地址,就可以進入,然後在port—port security下可以選定交換機端口,在Status和Sticky MAC Address中選Enable或Disabled,Violation Action可以選Shutdown、Restrict、Protect中的一種,Maximum Address Count(1-132)可以填寫這個範圍的數值。
當然還有要求綁定IP地址和MAC地址的,這個就需要三層或以上的交換了,因爲我們知道普通的交換機都是工作在第二層,也就是使數據鏈路層,是不可能綁定IP的。假如企業是星型的網絡,中心交換機是帶三層或以上功能的。我們就可以在上綁定,
Switch(config)#arp Ip地址 Mac地址 arpa
 

實驗十八、交換機端口與MAC 綁定
一、 實驗目的
1、瞭解什麼是交換機的 MAC 綁定功能;
2、熟練掌握 MAC 與端口綁定的靜態、動態方式。
二、 應用環境
1、當網絡中某機器由於中毒進而引發大量的廣播數據包在網絡中洪泛時,網絡管理員的唯一想法就是儘快地找到根源主機並把它從網絡中暫時隔離開。當網絡的佈置很隨意時,任何用戶只要插上網線,在任何位置都能夠上網,這雖然使正常情況下的大多數用戶很滿意,但一旦發生網絡故障,網管人員卻很難快速準確定位根源主機,就更談不上將它隔離了。端口與地址綁定技術使主機必須與某一端口進行綁定,也就是說,特定主機只有在某個特定端口下發出數據幀,才能被交換機接收並傳輸到網絡上,如果這臺主機移動到其他位置,則無法實現正常的連網。這樣做看起來似乎對用戶苛刻了一些,而且對於有大量使用便攜機的員工的園區網並不適用,但基於安全管理的角度考慮,它卻起到了至關重要的作用。
2、爲了安全和便於管理,需要將 MAC 地址與端口進行綁定,即,MAC 地址與端口綁定後,該MAC 地址的數據流只能從綁定端口進入,不能從其他端口進入。該端口可以允許其他MAC 地址的數據流通過。但是如果綁定方式採用動態lock 的方式會使該端口的地址學習功能關閉,因此在取消lock 之前,其他MAC 的主機也不能從這個端口進入。
三、 實驗設備
1、DCS-3926S 交換機1 臺
2、PC 機2 臺
3、Console 線1 根
4、直通網線 2 根
四、 實驗拓撲
五、 實驗要求
1、交換機 IP 地址爲192.168.1.11/24,PC1 的地址爲192.168.1.101/24;PC2 的地址爲
192.168.1.102/24。
2、在交換機上作 MAC 與端口綁定;
3、PC1 在不同的端口上ping 交換機的IP,檢驗理論是否和實驗一致。
4、PC2 在不同的端口上ping 交換機的IP,檢驗理論是否和實驗一致。
六、 實驗步驟
第一步:得到PC1主機的mac地址
Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.
C:\>ipconfig/all
Windows IP Configuration
Host Name . . . . . . . . . . . . : xuxp
Primary Dns Suffix . . . . . . . : digitalchina.com
Node Type . . . . . . . . . . . . : Broadcast
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter 本地連接:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connecti
on
Physical Address. . . . . . . . . : 00-A0-D1-D1-07-FF
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Autoconfiguration IP Address. . . : 169.254.27.232
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
C:\>
我們得到了PC1主機的mac地址爲:00-A0-D1-D1-07-FF。
第二步:交換機全部恢復出廠設置,配置交換機的IP地址
switch(Config)#interface vlan 1
switch(Config-If-Vlan1)#ip address 192.168.1.11 255.255.255.0
switch(Config-If-Vlan1)#no shut
switch(Config-If-Vlan1)#exit
switch(Config)#
第三步:使能端口的MAC地址綁定功能
switch(Config)#interface ethernet 0/0/1
switch(Config-Ethernet0/0/1)#switchport port-security
switch(Config-Ethernet0/0/1)#
第四步:添加端口靜態安全MAC地址,缺省端口最大安全MAC地址數爲1
switch(Config-Ethernet0/0/1)#switchport port-security mac-address
00-a0-d1-d1-07-ff
驗證配置:
switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
---------------------------------------------------------------------------
Ethernet0/0/1 1 1 Protect
---------------------------------------------------------------------------
Max Addresses limit per port :128
Total Addresses in System :1
switch#
switch#show port-security address
Security Mac Address Table
---------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1
---------------------------------------------------------------------------
Total Addresses in System :1
Max Addresses limit in System :128
switch#
第五步:使用ping命令驗證
PC 端口 Ping 結果 原因
PC1 0/0/1 192.168.1.11 通
PC1 0/0/7 192.168.1.11 不通
PC2 0/0/1 192.168.1.11 通
PC2 0/0/7 192.168.1.11 通
第六步:在一個以太口上靜態捆綁多個MAC
Switch(Config-Ethernet0/0/1)#switchport port-security maximum 4
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address
aa-aa-aa-aa-aa-aa
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address
aa-aa-aa-bb-bb-bb
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address
aa-aa-aa-cc-cc-cc
驗證配置:
switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
---------------------------------------------------------------------------
Ethernet0/0/1 4 4 Protect
---------------------------------------------------------------------------
Max Addresses limit per port :128
Total Addresses in System :4
switch#show port-security address
Security Mac Address Table
---------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1
1 aa-aa-aa-aa-aa-aa SecurityConfigured Ethernet0/0/1
1 aa-aa-aa-bb-bb-bb SecurityConfigured Ethernet0/0/1
1 aa-aa-aa-cc-cc-cc SecurityConfigured Ethernet0/0/1
---------------------------------------------------------------------------
Total Addresses in System :4
Max Addresses limit in System :128
switch#
上面使用的都是靜態捆綁MAC的方法,下面介紹動態mac地址綁定的基本方法,首先清空
剛纔做過的捆綁。
第七步:清空端口與MAC綁定
switch(Config)#
switch(Config)#int ethernet 0/0/1
switch(Config-Ethernet0/0/1)#no switchport port-security
switch(Config-Ethernet0/0/1)#exit
switch(Config)#exit
驗證配置:
switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
---------------------------------------------------------------------------
Max Addresses limit per port :128
Total Addresses in System :0
第八步:使能端口的MAC地址綁定功能,動態學習MAC並轉換
switch(Config)#interface ethernet 0/0/1
switch(Config-Ethernet0/0/1)#switchport port-security
switch(Config-Ethernet0/0/1)#switchport port-security lock
switch(Config-Ethernet0/0/1)#switchport port-security convert
switch(Config-Ethernet0/0/1)#exit
驗證配置:
switch#show port-security address
Security Mac Address Table
---------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1
---------------------------------------------------------------------------
Total Addresses in System :1
Max Addresses limit in System :128
switch#
第九步:使用ping命令驗證
PC 端口 Ping 結果 原因
PC1 0/0/1 192.168.1.11 通
PC1 0/0/7 192.168.1.11 不通
PC2 0/0/1 192.168.1.11 不通
PC2 0/0/7 192.168.1.11 通
七、 注意事項和排錯
1、如果出現端口無法配置MAC地址綁定功能的情況,請檢查交換機的端口是否運行了Spanning-tree,802.1x,端口匯聚或者端口已經配置爲Trunk端口。MAC綁定在端口
上與這些配置是互斥的,如果該端口要打開MAC地址綁定功能,就必須首先確認端
口下的上述功能已經被關閉。
2、當動態學習MAC時,無法執行“convert”命令時,請檢查PC機網卡是否和該端口正確連接。
3、端口Lock之後,該端口MAC地址學習功能被關閉,不允許其他的MAC進入該端口。
八、 配置序列

九、 課後練習
1、使用三臺 PC 測試端口與MAC 綁定功能。
2、實現多個端口統一綁定。
十、 相關配置命令詳解
switchport port-security
命令:switchport port-security
no switchport port-security
功能:使能端口MAC 地址綁定功能;本命令的no 操作爲關閉端口MAC 地址綁定功能。
命令模式:端口配置模式
缺省情況:交換機端口不打開MAC 地址綁定功能。
使用指南:MAC 地址綁定功能與802.1x、Spanning Tree、端口匯聚功能存在互斥關係,因此如果要打開端口的MAC 地址綁定功能,就必須關閉端口上的802.1x、Spanning Tree、端口匯聚功能,且打開MAC 地址綁定功能的端口不能是Trunk 口。
舉例:使能端口1 的MAC 地址綁定功能。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security
switchport port-security convert
命令:switchport port-security convert
功能:將端口學習到的動態MAC 地址轉化爲靜態安全MAC 地址。
命令模式:端口配置模式
使用指南:必須在安全端口鎖定之後才能執行端口動態MAC 地址轉化命令。執行此命令之後,端口學習到的動態MAC 地址將轉化爲靜態安全MAC 地址。該命令沒有配置保留。
舉例:將端口1 的MAC 地址轉化爲靜態安全MAC 地址。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security convert
switchport port-security lock
命令:switchport port-security lock
no switchport port-security lock
功能:鎖定端口。端口被鎖定之後,端口的MAC地址學習功能將被關閉;本命令的no操作爲恢復端口的MAC地址學習功能。
命令模式:端口配置模式
缺省情況:端口未鎖定
使用指南:端口必須使能MAC 地址綁定功能之後才能執行端口鎖定命令。執行端口鎖定命令之後,端口將關閉動態MAC 學習功能。
舉例:鎖定端口1。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security lock
switchport port-security timeout
命令:switchport port-security timeout <value>
no switchport port-security timeout
功能:設置端口鎖定的定時器;本命令的no 操作爲恢復缺省值。
參數:<value> 鎖定時器時間間隔,取值範圍爲0~300s。
命令模式:端口配置模式
缺省情況:端口未打開端口鎖定的定時器。
使用指南:端口鎖定定時器功能是一種動態MAC 地址鎖定功能,鎖定定時器超時就執行MAC 地址鎖定操作及將動態MAC 轉換爲安全MAC 地址的操作。端口必須先開啓MAC 地址綁定功能後才能使用此命令。
舉例:設置端口1 的鎖定時器爲30 秒。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)# switchport port-security timeout 30
switchport port-security mac-address
命令:switchport port-security mac-address <mac-address>
no switchport port-security mac-address <mac-address>
功能:添加靜態安全MAC 地址;本命令的no 操作爲刪除靜態安全MAC 地址。
命令模式:端口配置模式
參數:<mac-address>爲添加/刪除的MAC 地址。
使用指南:端口必須使能MAC 地址綁定功能之後才能添加端口靜態安全MAC 地址。
舉例:添加MAC 00-03-0F-FE-2E-D3 到端口1。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address 00-03-0F-FE-2E-D3
clear port-security dynamic
命令:clear port-security dynamic [address <mac-addr> | interface <interface-id> ]
功能:清除指定端口的動態MAC 地址。
命令模式:特權配置模式
參數:<mac-addr>爲MAC 地址;<interface-id>爲指定的端口號。
使用指南:必須在安全端口鎖定之後之後才能執行指定端口的動態MAC 清除操作。如果不指定端口、MAC 地址,則清除所有鎖定的安全端口的動態MAC;如果僅指定端口,不指定MAC 地址,則清除指定端口的所有動態MAC 地址。
舉例:刪除端口1 動態MAC。
Switch#clear port-security dynamic interface Ethernet 0/0/1
switchport port-security maximum
命令:switchport port-security maximum <value>
no switchport port-security maximum
功能:設置端口最大安全MAC 地址數;本命令的no 操作爲恢復最大安全地址數爲1。
命令模式:端口配置模式
參數:<value> 端口靜態安全MAC 地址上限,取值範圍1~128。
缺省情況:端口最大安全MAC 地址數爲1。
使用指南:端口必須使能MAC 地址綁定功能之後才能設置端口安全MAC 地址上限。如果端口靜態安全MAC 地址數大於設置的最大安全MAC 地址數,則設置失敗;必須刪除端口的靜態安全MAC 地址,直到端口靜態安全MAC 地址數不大於設置的最大安全MAC 地址數,設置纔會成功。
舉例:設置端口1 安全MAC 地址上限爲4。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security maximum 4
switchport port-security violation
命令:switchport port-security violation {protect | shutdown}
no switchport port-security violation
功能:設置端口違背模式;本命令的no 操作爲恢復違背模式爲protect。
命令模式:端口配置模式
參數:protect 爲保護模式;shutdown 爲關閉模式。
缺省情況:端口違背模式爲缺省爲protect。
使用指南:端口必須使能MAC 地址綁定功能之後才能設置端口違背模式。如果端口違背模式設置爲protect,那麼當端口安全MAC 地址超過設置的端口安全MAC 上限的時候,端口僅僅關閉動態MAC 地址學習功能;如果端口違背模式設置爲shutdown,那麼當端口安全MAC地址超過設置的端口安全MAC上限的時候,端口將被關閉,用戶可以通過no shutdown命令手工打開該端口。
舉例:設置端口1 的違背模式爲shutdown。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security violation shutdown
show port-security
命令:show port-security
功能:顯示全局安全端口配置情況。
命令模式:特權配置模式
缺省情況:交換機不顯示安全端口配置情況。
使用指南:本命令顯示交換機當前已經配置爲安全端口的端口信息。
舉例:
Switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
-----------------------------------------------------------------
Ethernet0/0/3 1 1 Protect
Ethernet0/0/4 10 1 Protect
Ethernet0/0/5 1 0 Protect
-----------------------------------------------------------------
Total Addresses in System :2
Max Addresses limit in System :128
顯示信息 解釋
Security Port 配置爲安全端口的端口名
MaxSecurityAddr 安全端口設置的最大安全MAC 地址數
CurrentAddr 安全端口當前安全MAC 地址數
Security Action 端口設置的違背模式
Total Addresses in System 系統中當前安全MAC 地址數
Max Addresses limit in System 系統中最大安全MAC 地址數
show port-security interface
命令:show port-security interface <interface-id>
功能:顯示安全端口配置情況。
命令模式:特權配置模式
參數:<interface-id> 指定的顯示端口。
缺省情況:交換機不顯示安全端口配置情況。
使用指南:本命令顯示交換機安全端口的詳細配置信息。
舉例:
Switch#show port-security interface ethernet 0/0/1
Port Security :Enabled
Port status :Security Up
Violation mode :Protect
Maximum MAC Addresses :1
Total MAC Addresses :1
Configured MAC Addresses :1
Lock Timer is ShutDown
Mac-Learning function is : Opened
顯示信息解釋
Port Security : 端口是否使能爲安全端口
Port status : 端口安全狀態
Violation mode : 端口設置的違背模式
Maximum MAC Addresses : 端口設置的安全MAC 地址上限
Total MAC Addresses : 端口當前安全MAC 地址數
Configured MAC Addresses : 端口靜態配置的安全MAC 地址數
Lock Timer 端口是否開啓鎖定的定時器(定時器時間)
Mac-Learning function 端口MAC 地址學習功能是否打開
show port-security address
命令:show port-security address [interface <interface-id>]
功能:顯示端口安全MAC 地址。
命令模式:特權配置模式
參數:<interface-id> 指定的顯示端口。
使用指南:本命令顯示端口安全MAC 地址信息,如果不指定端口則顯示所有端口安全MAC地址。顯示內容舉例如下:
Switch#show port-security address interface ethernet 0/0/1
Security Mac Address Table
------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 0000.0000.1111 SecureConfigured Ethernet0/0/3
------------------------------------------------------------------------
Total Addresses :1
顯示信息 解釋
Vlan 安全MAC 地址的VLAN ID
Mac Address 安全MAC 地址
Type 安全MAC 地址類型
Ports 安全MAC 地址所屬端口
Total Addresses 系統中當前安全MAC 地址數 

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

實驗十八、交換機端口與MAC 綁定
一、 實驗目的
1、瞭解什麼是交換機的 MAC 綁定功能;
2、熟練掌握 MAC 與端口綁定的靜態、動態方式。
二、 應用環境
1、當網絡中某機器由於中毒進而引發大量的廣播數據包在網絡中洪泛時,網絡管理員的唯一想法就是儘快地找到根源主機並把它從網絡中暫時隔離開。當網絡的佈置很隨意時,任何用戶只要插上網線,在任何位置都能夠上網,這雖然使正常情況下的大多數用戶很滿意,但一旦發生網絡故障,網管人員卻很難快速準確定位根源主機,就更談不上將它隔離了。端口與地址綁定技術使主機必須與某一端口進行綁定,也就是說,特定主機只有在某個特定端口下發出數據幀,才能被交換機接收並傳輸到網絡上,如果這臺主機移動到其他位置,則無法實現正常的連網。這樣做看起來似乎對用戶苛刻了一些,而且對於有大量使用便攜機的員工的園區網並不適用,但基於安全管理的角度考慮,它卻起到了至關重要的作用。
2、爲了安全和便於管理,需要將 MAC 地址與端口進行綁定,即,MAC 地址與端口綁定後,該MAC 地址的數據流只能從綁定端口進入,不能從其他端口進入。該端口可以允許其他MAC 地址的數據流通過。但是如果綁定方式採用動態lock 的方式會使該端口的地址學習功能關閉,因此在取消lock 之前,其他MAC 的主機也不能從這個端口進入。
三、 實驗設備
1、DCS-3926S 交換機1 臺
2、PC 機2 臺
3、Console 線1 根
4、直通網線 2 根
四、 實驗拓撲
五、 實驗要求
1、交換機 IP 地址爲192.168.1.11/24,PC1 的地址爲192.168.1.101/24;PC2 的地址爲
192.168.1.102/24。
2、在交換機上作 MAC 與端口綁定;
3、PC1 在不同的端口上ping 交換機的IP,檢驗理論是否和實驗一致。
4、PC2 在不同的端口上ping 交換機的IP,檢驗理論是否和實驗一致。
六、 實驗步驟
第一步:得到PC1主機的mac地址
Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.
C:\>ipconfig/all
Windows IP Configuration
Host Name . . . . . . . . . . . . : xuxp
Primary Dns Suffix . . . . . . . : digitalchina.com
Node Type . . . . . . . . . . . . : Broadcast
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter 本地連接:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connecti
on
Physical Address. . . . . . . . . : 00-A0-D1-D1-07-FF
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Autoconfiguration IP Address. . . : 169.254.27.232
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
C:\>
我們得到了PC1主機的mac地址爲:00-A0-D1-D1-07-FF。
第二步:交換機全部恢復出廠設置,配置交換機的IP地址
switch(Config)#interface vlan 1
switch(Config-If-Vlan1)#ip address 192.168.1.11 255.255.255.0
switch(Config-If-Vlan1)#no shut
switch(Config-If-Vlan1)#exit
switch(Config)#
第三步:使能端口的MAC地址綁定功能
switch(Config)#interface ethernet 0/0/1
switch(Config-Ethernet0/0/1)#switchport port-security
switch(Config-Ethernet0/0/1)#
第四步:添加端口靜態安全MAC地址,缺省端口最大安全MAC地址數爲1
switch(Config-Ethernet0/0/1)#switchport port-security mac-address
00-a0-d1-d1-07-ff
驗證配置:
switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
---------------------------------------------------------------------------
Ethernet0/0/1 1 1 Protect
---------------------------------------------------------------------------
Max Addresses limit per port :128
Total Addresses in System :1
switch#
switch#show port-security address
Security Mac Address Table
---------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1
---------------------------------------------------------------------------
Total Addresses in System :1
Max Addresses limit in System :128
switch#
第五步:使用ping命令驗證
PC 端口 Ping 結果 原因
PC1 0/0/1 192.168.1.11 通
PC1 0/0/7 192.168.1.11 不通
PC2 0/0/1 192.168.1.11 通
PC2 0/0/7 192.168.1.11 通
第六步:在一個以太口上靜態捆綁多個MAC
Switch(Config-Ethernet0/0/1)#switchport port-security maximum 4
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address
aa-aa-aa-aa-aa-aa
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address
aa-aa-aa-bb-bb-bb
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address
aa-aa-aa-cc-cc-cc
驗證配置:
switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
---------------------------------------------------------------------------
Ethernet0/0/1 4 4 Protect
---------------------------------------------------------------------------
Max Addresses limit per port :128
Total Addresses in System :4
switch#show port-security address
Security Mac Address Table
---------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1
1 aa-aa-aa-aa-aa-aa SecurityConfigured Ethernet0/0/1
1 aa-aa-aa-bb-bb-bb SecurityConfigured Ethernet0/0/1
1 aa-aa-aa-cc-cc-cc SecurityConfigured Ethernet0/0/1
---------------------------------------------------------------------------
Total Addresses in System :4
Max Addresses limit in System :128
switch#
上面使用的都是靜態捆綁MAC的方法,下面介紹動態mac地址綁定的基本方法,首先清空剛纔做過的捆綁。
第七步:清空端口與MAC綁定
switch(Config)#
switch(Config)#int ethernet 0/0/1
switch(Config-Ethernet0/0/1)#no switchport port-security
switch(Config-Ethernet0/0/1)#exit
switch(Config)#exit
驗證配置:
switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
---------------------------------------------------------------------------
---------------------------------------------------------------------------
Max Addresses limit per port :128
Total Addresses in System :0
第八步:使能端口的MAC地址綁定功能,動態學習MAC並轉換
switch(Config)#interface ethernet 0/0/1
switch(Config-Ethernet0/0/1)#switchport port-security
switch(Config-Ethernet0/0/1)#switchport port-security lock
switch(Config-Ethernet0/0/1)#switchport port-security convert
switch(Config-Ethernet0/0/1)#exit
驗證配置:
switch#show port-security address
Security Mac Address Table
---------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1
---------------------------------------------------------------------------
Total Addresses in System :1
Max Addresses limit in System :128
switch#
第九步:使用ping命令驗證
PC 端口 Ping 結果 原因
PC1 0/0/1 192.168.1.11 通
PC1 0/0/7 192.168.1.11 不通
PC2 0/0/1 192.168.1.11 不通
PC2 0/0/7 192.168.1.11 通
七、 注意事項和排錯
1、如果出現端口無法配置MAC地址綁定功能的情況,請檢查交換機的端口是否運行了Spanning-tree,802.1x,端口匯聚或者端口已經配置爲Trunk端口。MAC綁定在端口
上與這些配置是互斥的,如果該端口要打開MAC地址綁定功能,就必須首先確認端
口下的上述功能已經被關閉。
2、當動態學習MAC時,無法執行“convert”命令時,請檢查PC機網卡是否和該端口正確連接。
3、端口Lock之後,該端口MAC地址學習功能被關閉,不允許其他的MAC進入該端口。
八、 配置序列

九、 課後練習
1、使用三臺 PC 測試端口與MAC 綁定功能。
2、實現多個端口統一綁定。
十、 相關配置命令詳解
switchport port-security
命令:switchport port-security
no switchport port-security
功能:使能端口MAC 地址綁定功能;本命令的no 操作爲關閉端口MAC 地址綁定功能。
命令模式:端口配置模式
缺省情況:交換機端口不打開MAC 地址綁定功能。
使用指南:MAC 地址綁定功能與802.1x、Spanning Tree、端口匯聚功能存在互斥關係,因此如果要打開端口的MAC 地址綁定功能,就必須關閉端口上的802.1x、Spanning Tree、端口匯聚功能,且打開MAC 地址綁定功能的端口不能是Trunk 口。
舉例:使能端口1 的MAC 地址綁定功能。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security
switchport port-security convert
命令:switchport port-security convert
功能:將端口學習到的動態MAC 地址轉化爲靜態安全MAC 地址。
命令模式:端口配置模式
使用指南:必須在安全端口鎖定之後才能執行端口動態MAC 地址轉化命令。執行此命令之後,端口學習到的動態MAC 地址將轉化爲靜態安全MAC 地址。該命令沒有配置保留。
舉例:將端口1 的MAC 地址轉化爲靜態安全MAC 地址。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security convert
switchport port-security lock
命令:switchport port-security lock
no switchport port-security lock
功能:鎖定端口。端口被鎖定之後,端口的MAC地址學習功能將被關閉;本命令的no操作爲恢復端口的MAC地址學習功能。
命令模式:端口配置模式
缺省情況:端口未鎖定
使用指南:端口必須使能MAC 地址綁定功能之後才能執行端口鎖定命令。執行端口鎖定命令之後,端口將關閉動態MAC 學習功能。
舉例:鎖定端口1。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security lock
switchport port-security timeout
命令:switchport port-security timeout <value>
no switchport port-security timeout
功能:設置端口鎖定的定時器;本命令的no 操作爲恢復缺省值。
參數:<value> 鎖定時器時間間隔,取值範圍爲0~300s。
命令模式:端口配置模式
缺省情況:端口未打開端口鎖定的定時器。
使用指南:端口鎖定定時器功能是一種動態MAC 地址鎖定功能,鎖定定時器超時就執行MAC 地址鎖定操作及將動態MAC 轉換爲安全MAC 地址的操作。端口必須先開啓MAC 地址綁定功能後才能使用此命令。
舉例:設置端口1 的鎖定時器爲30 秒。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)# switchport port-security timeout 30
switchport port-security mac-address
命令:switchport port-security mac-address <mac-address>
no switchport port-security mac-address <mac-address>
功能:添加靜態安全MAC 地址;本命令的no 操作爲刪除靜態安全MAC 地址。
命令模式:端口配置模式參數:<mac-address>爲添加/刪除的MAC 地址。
使用指南:端口必須使能MAC 地址綁定功能之後才能添加端口靜態安全MAC 地址。
舉例:添加MAC 00-03-0F-FE-2E-D3 到端口1。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security mac-address 00-03-0F-FE-2E-D3
clear port-security dynamic
命令:clear port-security dynamic [address <mac-addr> | interface <interface-id> ]
功能:清除指定端口的動態MAC 地址。
命令模式:特權配置模式
參數:<mac-addr>爲MAC 地址;<interface-id>爲指定的端口號。
使用指南:必須在安全端口鎖定之後之後才能執行指定端口的動態MAC 清除操作。如果不指定端口、MAC 地址,則清除所有鎖定的安全端口的動態MAC;如果僅指定端口,不指定MAC 地址,則清除指定端口的所有動態MAC 地址。
舉例:刪除端口1 動態MAC。
Switch#clear port-security dynamic interface Ethernet 0/0/1
switchport port-security maximum
命令:switchport port-security maximum <value>
no switchport port-security maximum
功能:設置端口最大安全MAC 地址數;本命令的no 操作爲恢復最大安全地址數爲1。
命令模式:端口配置模式
參數:<value> 端口靜態安全MAC 地址上限,取值範圍1~128。
缺省情況:端口最大安全MAC 地址數爲1。
使用指南:端口必須使能MAC 地址綁定功能之後才能設置端口安全MAC 地址上限。如果端口靜態安全MAC 地址數大於設置的最大安全MAC 地址數,則設置失敗;必須刪除端口的靜態安全MAC 地址,直到端口靜態安全MAC 地址數不大於設置的最大安全MAC 地址數,設置纔會成功。
舉例:設置端口1 安全MAC 地址上限爲4。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security maximum 4
switchport port-security violation
命令:switchport port-security violation {protect | shutdown}
no switchport port-security violation
功能:設置端口違背模式;本命令的no 操作爲恢復違背模式爲protect。
命令模式:端口配置模式
參數:protect 爲保護模式;shutdown 爲關閉模式。
缺省情況:端口違背模式爲缺省爲protect。
使用指南:端口必須使能MAC 地址綁定功能之後才能設置端口違背模式。如果端口違背模式設置爲protect,那麼當端口安全MAC 地址超過設置的端口安全MAC 上限的時候,端口僅僅關閉動態MAC 地址學習功能;如果端口違背模式設置爲shutdown,那麼當端口安全MAC地址超過設置的端口安全MAC上限的時候,端口將被關閉,用戶可以通過no shutdown命令手工打開該端口。
舉例:設置端口1 的違背模式爲shutdown。
Switch(Config)#interface Ethernet 0/0/1
Switch(Config-Ethernet0/0/1)#switchport port-security violation shutdown
show port-security
命令:show port-security
功能:顯示全局安全端口配置情況。
命令模式:特權配置模式
缺省情況:交換機不顯示安全端口配置情況。
使用指南:本命令顯示交換機當前已經配置爲安全端口的端口信息。
舉例:
Switch#show port-security
Security Port MaxSecurityAddr CurrentAddr Security Action
(count) (count)
-----------------------------------------------------------------
Ethernet0/0/3 1 1 Protect
Ethernet0/0/4 10 1 Protect
Ethernet0/0/5 1 0 Protect
-----------------------------------------------------------------
Total Addresses in System :2
Max Addresses limit in System :128
顯示信息 解釋
Security Port 配置爲安全端口的端口名
MaxSecurityAddr 安全端口設置的最大安全MAC 地址數
CurrentAddr 安全端口當前安全MAC 地址數
Security Action 端口設置的違背模式
Total Addresses in System 系統中當前安全MAC 地址數
Max Addresses limit in System 系統中最大安全MAC 地址數
show port-security interface
命令:show port-security interface <interface-id>
功能:顯示安全端口配置情況。
命令模式:特權配置模式
參數:<interface-id> 指定的顯示端口。
缺省情況:交換機不顯示安全端口配置情況。
使用指南:本命令顯示交換機安全端口的詳細配置信息。
舉例:
Switch#show port-security interface ethernet 0/0/1
Port Security :Enabled
Port status :Security Up
Violation mode :Protect
Maximum MAC Addresses :1
Total MAC Addresses :1
Configured MAC Addresses :1
Lock Timer is ShutDown
Mac-Learning function is : Opened
顯示信息解釋
Port Security : 端口是否使能爲安全端口
Port status : 端口安全狀態
Violation mode : 端口設置的違背模式
Maximum MAC Addresses : 端口設置的安全MAC 地址上限
Total MAC Addresses : 端口當前安全MAC 地址數
Configured MAC Addresses : 端口靜態配置的安全MAC 地址數
Lock Timer 端口是否開啓鎖定的定時器(定時器時間)
Mac-Learning function 端口MAC 地址學習功能是否打開
show port-security address
命令:show port-security address [interface <interface-id>]
功能:顯示端口安全MAC 地址。
命令模式:特權配置模式
參數:<interface-id> 指定的顯示端口。
使用指南:本命令顯示端口安全MAC 地址信息,如果不指定端口則顯示所有端口安全MAC地址。顯示內容舉例如下:
Switch#show port-security address interface ethernet 0/0/1
Security Mac Address Table
------------------------------------------------------------------------
Vlan Mac Address Type Ports
1 0000.0000.1111 SecureConfigured Ethernet0/0/3
------------------------------------------------------------------------
Total Addresses :1
顯示信息 解釋
Vlan 安全MAC 地址的VLAN ID
Mac Address 安全MAC 地址
Type 安全MAC 地址類型
Ports 安全MAC 地址所屬端口
Total Addresses 系統中當前安全MAC 地址數 

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