1. 程式人生 > >CISCO交換機上實現MAC和埠、IP和埠、IP和MAC的繫結

CISCO交換機上實現MAC和埠、IP和埠、IP和MAC的繫結

一、針對於目前ARP病毒肆虐,利用ARP協議進行欺騙的網路問題也日漸嚴重。在防範過程中除了VLAN的劃分來抑制問題的擴散,如果將MAC地址與埠繫結配合起來會達到最佳的防範效果。
下面在Cisco交換機上實現簡單的埠繫結,舉Cisco 3550為例: 3550#config terminal 
//進入通用配置模式
3550(config)# Interface fastethernet 0/1 
//進入需要配置的具體埠配置模式
3550(config-if)#switchport mode access 
//設定交換機的埠模式為access模式,注意預設是dynamic 
//dynamic模式下是不能使用Port-security功能的
3550(config-if)#switchport port-secruity 
//啟用埠安全模式
3550(config-if )switchport port-security mac-address <後面寫上主機的MAC地址>
//配置該埠要繫結的主機的MAC地址
switch(config-if)#switchport port-security maximum 1
//其實預設就是1個 
switch(config-if)#switchport port-security violation shutdown
//設定違反埠安全規則,預設是shutdown 這個配置只可以一個埠繫結一個MAC地址,那麼要繫結多個IP地址與MAC地址應該如何處理呢?
看看下面的配置: 1.先建立兩個訪問控制列表,一個是關於MAC地址的,一個是關於IP地址的。
3550(config)#mac access-list extended mac-n
//配置一個命名的MAC地址訪問控制列表,命名為mac-n
3550(config-ext-macl)#permit host 0001.a1db.f987 any
//源MAC地址為0001.a1db.f987的主機可以訪問任意主機
3550(config-ext-macl)#permit any host 0001.a1db.f987
//所有主機可以訪問目的MAC地址為0001.a1db.f987的主機
3550(config)#ip access-list extended ip-n
//配置命名的IP地址訪問控制列表,命名為ip-n
3550(config-ext-nacl)#permit  ip  172.0.0.1 0.0.0.0 any
//允許172.0.0.1地址在網內工作 2.將建立好的訪問控制列表加入需要配置的埠
3550(config-if )#interface fa0/1
//進入配置具體埠的模式
3550(config-if )#mac access-group mac-n  in
3550(config-if )#ip access-group ip-n in PS:上面的配置是靜態可靠的MAC地址和埠的繫結,命令格式:Switch(config-if)#switchport port-security mac-address Mac地址 企業中如何快速將MAC地址與交換機埠繫結呢?在實際的運用中常用黏性可靠的MAC地址繫結:舉CISCO 2950為例 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檢視繫結的埠,確認配置正確。 二、在cisco交換機中為了防止ip被盜用或員工亂改ip,可以做以下措施,既ip與mac地址的繫結,和ip與交換機埠的繫結。 ip與mac地址的繫結,這種繫結可以簡單有效的防止ip被盜用,別人將ip改成了你綁定了mac地址的ip後,其網路不通,(tcp/udp協議不通,但netbios網路共項可以訪問),具體做法:
 
cisco(config)#arp 10.138.208.81 0000.e268.9980 ARPA 這樣就將10.138.208.81 與mac:0000.e268.9980 ARPA繫結在一起了。 ip與交換機埠的繫結,此種方法繫結後的埠只有此ip能用,改為別的ip後立即斷網。有效的防止了亂改ip。 cisco(config)#   interface FastEthernet0/17 cisco(config-if)# ip access-group 6 in        cisco(config)#access-list 6 permit 10.138.208.81  這樣就將交換機的FastEthernet0/17埠與ip:10.138.208.81綁定了。 補:我們也可以通過MAC地址來限制埠流量,此配置允許一TRUNK口最多通過100個MAC地址,超過100時,但來自新的主機的資料幀將丟失。 3550-1#conf t 3550-1(config)#int f0/1 3550-1(config-if)#switchport trunk encapsulation dot1q 3550-1(config-if)#switchport mode trunk /配置埠模式為TRUNK。 3550-1(config-if)#switchport port-security maximum 100 /允許此埠通過的最大MAC地址數目為100。 3550-1(config-if)#switchport port-security violation protect /當主機MAC地址數目超過100時,交換機繼續工作,但來自新的主機的資料幀將丟失。 上面的配置根據MAC地址來允許流量,下面的配置則是根據MAC地址來拒絕流量。 此配置在Catalyst交換機中只能對單播流量進行過濾,對於多播流量則無效。 3550-1#conf t 3550-1(config)#mac-address-table static 00-90-F5-10-79-C1 vlan 2 drop /在相應的Vlan丟棄流量。 3550-1#conf t 3550-1(config)#mac-address-table static 00-90-F5-10-79-C1 vlan 2 int f0/1 /在相應的介面丟棄流量。

Switch

通過Arp泛紅來進行MAC地址的學習,並匯聚成一張"MAC address tables",一個埠下可以有多個MAC地址的學習,因為MAC地址表的本身是有限制的,如果超過了最大定義的MAC數量,那麼以後發來的MAC定址在網路中都會進行以arp泛紅的形式進行通話,這樣就可以在任意的主機上抓取通訊的內容,安全性得不到最大的保障。另外埠安全與arp繫結有類似的功能,靈活運用可以限制主機上網數量,總結一下埠安全配置及簡單應用。

    1.首先進入需要繫結的埠,比如一個埠上接一個HUBHUB下掛了幾臺主機,但是隻允許其中一個主

機通過該交換機的這個埠。
    2.
開啟埠安全繫結策略
    3.

設定埠上允許通過的MAC地址的數量。
    4.
選擇繫結的模式,是靜態繫結(指定MAC地址,在MAC地址表中也會自動新增繫結)還是動態繫結(即

先訪問此埠的MAC地址)。
    5.
設定埠上的安全策略,對沒有被繫結的MAC地址流量想要通過此埠的處理方法,分為報警且不放行

、不報警也不放行、報警並關閉埠。
    6.
檢視埠安全設定及,安全MAC表的設定是否正確

埠安全配置命令如下:
1.interface f0/1
2.switchport mode access
3.switchport port-security
4.switchport port-security maximun 1
5.switchport port-security mac-address [0001.0001.0001\sticky]
6.switchport port-security violation   [protect\restrict\shutdown]
7.show port-security interface f0/1
8.show port-security address

完成安全埠的配置


(例如)exp1:為f0/1埠指定一個MAC地址通過,其他MAC地址想要通過時拒絕並報警,但不關閉埠
1.interface f0/1
2.switchport mode access
3.switchport port-security
4.switchport port-security maximun 1
5.switchport port-security mac-address 0001.0001.0001
6.switchport port-security violation   restrict

7.show port-security interface f0/1
Port Security              : Enabled  
 埠安全開啟
Port Status                : Secure-up
Violation Mode             : Restrict           
 型別:拒絕並報警
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled
Maximum MAC Addresses      : 1   
 最大通過MAC地址數量
Total MAC Addresses        : 1   
Configured MAC Addresses   : 1
Sticky MAC Addresses       : 0
Last Source Address:Vlan   : 0002.0002.0002:1   
 這裡顯示的是最後一次通過埠的MAC及該MAC(192.168.1.2ping192.168.1.3得要的)

屬的vlan,本例中是0002.0002.0002 vlan1,因為策略中繫結的是0001.0001.0001這個MAC,所以顯然0002.0002.0002這個MAC沒有被放行通過。
Security Violation Count   : 9

8.show port-security address
   Secure Mac Address Table
-------------------------------------------------------------------------------
Vlan Mac Address Type (
型別報警) Ports  Remaining Age
        (mins)
---- ----------- ----   -----  -------------
1 0001.0001.0001 SecureConfigured FastEthernet0/1  -
------------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 1024
以上資訊也可以看出繫結的是0001.0001.0001MAC

(例如)exp2:讓f0/1埠只允許一個MAC地址通過(通常是第一個訪問埠的主機MAC地址),其他的一

律拒絕,如果有其他MAC企圖通過時,關閉埠
1.interface f0/1
2.switchport mode access
3.switchport port-security
4.switchport port-security maximun 1
5.switchport port-security mac-address sticky
6.switchport port-security violation shutdown

7.show port-security interface f0/1
Switch#show port-security interface f0/1
Port Security              : Enabled  
 埠安全開啟
Port Status                : Secure-up
Violation Mode             : Shutdown  
 型別:拒絕並關閉埠
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled  
Maximum MAC Addresses      : 1   
 最大允許MAC地址數量
Total MAC Addresses        : 1
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 1
Last Source Address:Vlan   : 0002.0002.0002:1
Security Violation Count   : 0

8.show port-security address
   Secure Mac Address Table
-------------------------------------------------------------------------------
Vlan Mac Address Type (
型別shutdown) Ports  Remaining Age
        (mins)
---- ----------- ----   -----  -------------
1 0002.0002.0002 SecureSticky  FastEthernet0/1  -
------------------------------------------------------------------------------
Total Addresses in System (excluding one mac per port)     : 0
Max Addresses limit in System (excluding one mac per port) : 1024

這樣如果有不是MAC0002.0002.0002MAC要通過f0/1埠的時候,埠就會自動shutdown。檢視埠狀態如下

Switch#show interfaces f0/1
FastEthernet0/1 is down, line protocol is down (err-disabled)  
 顯示因為錯誤而關閉(192.168.1.1ping192.168.1.3得到的)
  Hardware is Lance, address is 0060.706e.b601 (bia 0060.706e.b601)
 BW 100000 Kbit, DLY 1000 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA, loopback not set
  Keepalive set (10 sec)
  Half-duplex, 100Mb/s
  input flow-control is off, output flow-control is off
  ARP type: ARPA, ARP Timeout 04:00:00
  Last input 00:00:08, output 00:00:05, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue :0/40 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     956 packets input, 193351 bytes, 0 no buffer
     Received 956 broadcasts, 0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     0 watchdog, 0 multicast, 0 pause input
     0 input packets with dribble condition detected
     2357 packets output, 263570 bytes, 0 underruns
     0 output errors, 0 collisions, 10 interface resets
     0 babbles, 0 late collision, 0 deferred
     0 lost carrier, 0 no carrier
     0 output buffer failures, 0 output buffers swapped out

Switch#show port-security interface f0/1
Port Security              : Enabled
Port Status                : Secure-shutdown
Violation Mode             : Shutdown
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled
Maximum MAC Addresses      : 1
Total MAC Addresses        : 1
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 1
Last Source Address:Vlan   : 0001.0001.0001:1     
 最後一次訪問的MAC地址
Security Violation Count   : 1

 以上可以看到,通過show interface f0/1  show port-security interface f0/1兩條命令可以看到

MAC地址為0001.0001.0001MAC地址企圖通過埠f0/1,而導致了f0/1埠關閉。在show interface

f0/1中可以看到提示資訊FastEthernet0/1 is down, line protocol is down (err-disabled)現在用普通的方法進行埠的啟用:進入f0/1執行no shutdown命令
Switch(config)#interface f0/1
Switch(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to down
無法進行埠的啟用,正確的啟用方法為:先進性shutdown關閉,再no shutdown啟用。
Switch(config)#interface f0/1
Switch(config-if)#shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
Switch(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Switch(config-if)#do show interface f0/1
FastEthernet0/1 is up, line protocol is up (connected)
鏈路及協議都up,啟用成功。

方法二可以使用策略關閉的埠自動恢復,詳細見埠廣播風暴抑制。

命令:

L5(config)#errdisable recovery cause security-violation       為security-violation啟用自動恢復
L5(config)#errdisable recovery interval 1800                  恢復時間為1800s後

L5#show errdisable recovery                                   檢視哪些策略開啟了自動恢復及恢復時間