加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Cisco标准ACL的反掩码作用

(2014-04-05 18:13:21)

    对刚学Cisco的人来说,ACL是一个小难题,在这里我也走过不少的弯路,以前一直以为对的,却是错的,总结就是实验做少了。

   闲话少扯,我们来看下面的这个例子:先看拓扑

             http://s5/mw690/004kFIx1gy6HRXm7E5m74&690

在这个拓扑中我们启用EIGRP协议,将所有网络全部宣告进EIGRP

R1:

int ser0

 ip add 12.1.1.1 255.255.255.0

int lo0

 ip add 1.1.1.1 255.255.255.0
router eigrp 90
  network 0.0.0.0
  no auto-summary
  eigrp router-id 1.1.1.1

R2:

int ser0

ip add 12.1.1.2 255.255.255.0

int ser1

ip add 23.1.1.2 255.255.255.0

int lo0

ip add 2.2.2.2 255.255.255.0


router eigrp 90
  network 0.0.0.0
  no auto-summary
  eigrp router-id 2.2.2.2

R3:

int ser0

 ip add 23.1.1.3 255.255.255.0

int lo0

 ip add 3.3.1.1 255.255.255.0

int lo1

 ip add 3.3.2.1 255.255.255.0

int lo2

 ip add 3.3.3.1 255.255.255.0


router eigrp 90
  network 0.0.0.0
  no auto-summary
  eigrp router-id 3.3.3.3

我们先来看下R1的路由表:

R1#show ip rou


 

Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
      1.1.1.0 is directly connected, Loopback0
     2.0.0.0/24 is subnetted, 1 subnets
      2.2.2.0 [90/409600] via 12.1.1.2, 00:32:59, FastEthernet0/0
     3.0.0.0/8 is variably subnetted, 3 subnets, 1 masks
      3.3.1.0/24 [90/435200] via 12.1.1.2, 00:32:59, FastEthernet0/0
      3.3.2.0/24 [90/435200] via 12.1.1.2, 00:32:59, FastEthernet0/0
      3.3.3.0/24 [90/435200] via 12.1.1.2, 00:33:01, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
      23.1.1.0 [90/307200] via 12.1.1.2, 00:33:01, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
      12.1.1.0 is directly connected, FastEthernet0/0

假设这个时候有这样的一个要求,R3要对3.0网段进行汇总,ok。对于汇总我想大家一定已经烂熟与胸了吧,这三个子网段汇总后地址为3.3.0.0/22。

在R3上我们配置一下语句:

int ser1

  ip summary-address eigrp 90 3.3.0.0 255.255.252.0

再次查看R1的路由表:

 

R1#show ip route


Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
      1.1.1.0 is directly connected, Loopback0
     2.0.0.0/24 is subnetted, 1 subnets
      2.2.2.0 [90/409600] via 12.1.1.2, 00:40:48, FastEthernet0/0
     3.0.0.0/22 is subnetted, 1 subnets
      3.3.0.0 [90/435200] via 12.1.1.2, 00:40:48, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
      23.1.1.0 [90/307200] via 12.1.1.2, 00:40:48, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
      12.1.1.0 is directly connected, FastEthernet0/0

现在R1只存在汇总路由了,假设我又想放行汇总路由条目中的3.3.1.0/24和3.3.2.0/24这两个明细路由条目,我们的ACL到底该怎样写呢?

也许你会写成

ip access-list 10 permit  3.3.0.0 0.0.2.255

或者你会写成

ip access-list 10 permit 3.3.1.0 0.0.0.255

ip access-list 10 permit 3.3.2.0 0.0.0.255

可以很明确的告诉你,这个方法行,可是在这里我们要注意反掩码为1的部分我们是可以任意变的,我想抓的3.3.1.0/24和3.3.2.0/24这两个路由条目,而上述两种方法会抓住所有以3.3.0.0/22到3.3.3.255/32的网络,例如会抓住3.3.0.128/25、3.3.1.0/27等等诸如此类的网络,这等价于前缀列表中的以下语句

ip prefix-list 10 permit 3.3.0.0/22 le 32

因此被以上语句匹配的网络有很多,而我们的目的是只抓取那两条路由条目:最正确的写法是

R3:

ip access-list 10 permit 3.3.1.0 0.0.0.0

ip access-list 10 permit 3.3.2.0 0.0.0.0

route-map Test permit 10
 match ip address 10

int ser3

 ip summary-address eigrp 90 3.3.0.0 255.255.252.0 leak-map Test

再次查看R1的路由表:

R1#show ip rou


 

Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
      1.1.1.0 is directly connected, Loopback0
     2.0.0.0/24 is subnetted, 1 subnets
      2.2.2.0 [90/409600] via 12.1.1.2, 01:13:22, FastEthernet0/0
     3.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
      3.3.0.0/22 [90/435200] via 12.1.1.2, 01:13:22, FastEthernet0/0
      3.3.1.0/24 [90/435200] via 12.1.1.2, 00:00:02, FastEthernet0/0
      3.3.2.0/24 [90/435200] via 12.1.1.2, 00:00:02, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
      23.1.1.0 [90/307200] via 12.1.1.2, 01:13:23, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
      12.1.1.0 is directly connected, FastEthernet0/0

 

以上说的是在抓取控制层面的路由条目的时候如何使用标准ACL,但是在数据层面的时候,我们就不能如此写了,

例如,假设我想过滤3.3.1.0网段访问其他路由器网段的地址,我们就不能写成

ip access-list 20 deny 3.3.1.0 0.0.0.0

而是要写成

ip access-list 20 deny 3.3.1.0 0.0.0.255

 

总结:控制层面的标准ACL抓的是路由条目,由于路由条目在传递的时候只关注网络和掩码,因此抓取的时候只要完全匹配网络位即可,而数据层面抓取的是IP包头的源IP地址

例如

ip access-list 10 permit 3.3.1.0 0.0.0.0

用在控制层面表示抓取3.3.1.0/24为前缀的网络,而用在数据层面表示抓取的是3.3.1.0这个主机地址

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有