您的位置:首页 > 其它

CISCO交换机上实现MAC和端口、IP和端口、IP和MAC的绑定

2017-08-28 15:36 429 查看
原文地址:http://chezw.blog.51cto.com/67821/134572

一、针对于目前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 /在相应的接口丢弃流量。

cisco交换机端口安全之端口MAC地址限制

原文地址:http://blog.csdn.net/alone_map/article/details/51840512

Switch通过Arp泛红来进行MAC地址的学习,并汇聚成一张"MAC
address tables",一个端口下可以有多个MAC地址的学习,因为MAC地址表的本身是有限制的,如果超过了最大定义的MAC数量,那么以后发来的MAC寻址在网络中都会进行以arp泛红的形式进行通话,这样就可以在任意的主机上抓取通信的内容,安全性得不到最大的保障。另外端口安全与arp绑定有类似的功能,灵活运用可以限制主机上网数量,总结一下端口安全配置及简单应用。

    1.首先进入需要绑定的端口,比如一个端口上接一个HUB,HUB下挂了几台主机,但是只允许其中一个主

机通过该交换机的这个端口。

    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

这样如果有不是MAC为0002.0002.0002的MAC要通过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.0001的MAC地址企图通过端口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                                   查看哪些策略开启了自动恢复及恢复时间
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: