我有一个关于 Cisco ACL 的问题。
如果路由器有一个拒绝 ping 和回复的 ACL,这会阻止 LAN 上的任何设备 ping 互联网,但路由器仍然可以 ping 互联网,为什么会出现这种情况?
这是因为路由器不受 ACL 影响而 PC 受 ACL 影响吗?
谢谢
我有一个关于 Cisco ACL 的问题。
如果路由器有一个拒绝 ping 和回复的 ACL,这会阻止 LAN 上的任何设备 ping 互联网,但路由器仍然可以 ping 互联网,为什么会出现这种情况?
这是因为路由器不受 ACL 影响而 PC 受 ACL 影响吗?
谢谢
我并不是要将此视为答案,我只是想显示测试@OzNetNerd 答案的输出。
我配置了三个路由器:
R1 ----- R2 ----- R3
给他们每个人一个 IP 和一个 Loopback 接口。配置 ACL 以阻止 ICMP 流量:
R2#show ip access-lists
Extended IP access list DENY-ICMP
10 deny icmp any any
20 permit ip any any
并在面向 R3 的接口上应用方向 OUT:
R2#show ip interface | i line|Internet|list
FastEthernet0/0 is up, line protocol is up
Internet address is 10.1.2.2/24
Outgoing access list is not set
Inbound access list is not set
FastEthernet0/1 is up, line protocol is up
Internet address is 10.2.3.2/24
Outgoing access list is DENY-ICMP
Inbound access list is not set
Loopback0 is up, line protocol is up
Internet address is 2.2.2.2/32
Outgoing access list is not set
Inbound access list is not set
我跑了三个测试,从 R2 本地 ping 3.3.3.3,然后从接口 L0 获取,然后从接口 fa0/0 获取。这三个都成功了:
R2#ping 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 60/69/92 ms
R2#ping 3.3.3.3 source l0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
Packet sent with a source address of 2.2.2.2
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 52/80/104 ms
R2#ping 3.3.3.3 source fa0/0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
Packet sent with a source address of 10.1.2.2
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/30/52 ms
ACL 命中计数一直保持在 0(甚至是许可):
R2#show ip access-list
Extended IP access list DENY-ICMP
10 deny icmp any any
20 permit ip any any
并且一直 R1 无法 ping R3:
R1#ping 3.3.3.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
UUUUU
Success rate is 0 percent (0/5)
R1 的尝试确实增加了 ACL Hitcount:
R2#show ip access-list
Extended IP access list DENY-ICMP
10 deny icmp any any (15 matches)
20 permit ip any any
R2#
(尽管为什么它在只发送了 5 次尝试的情况下在 15 之前这样做很奇怪,但有人有什么想法吗?)
我做了同样的测试,从 IP 2.2.2.2 和 10.1.2.2(R2 的 L0 接口和面向 R1 的接口上的地址)获取 ping,结果是一样的。所有这些都在运行 12.4 的 GNS3 上:
R2#show ver | i Ver
Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25), RELEASE SOFTWARE (fc2)
ROM: 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(25), RELEASE SOFTWARE (fc2)
我的测试证实,@OzNetNerd 是正确的,ACL 不适用于源自路由器本身的流量。
我确实测试了在 R2 的 f0/1(面向 R3 的接口)上应用入站 ACL。这确实成功地阻止了来自 R3 的返回 ICMP 响应。但最初的 ICMP Echo 确实做到了,并到达了 R3(如预期的那样)。我通过 R3 上的调试确认了这一点。
这是因为路由器不受 ACL 影响而 PC 受 ACL 影响吗?
是的,这是正确的。路由器的 ACL 不会影响由路由器本身发起的流量(例如,路由器 ping 互联网地址)。无论 ACL 是否放置在入站、出站、SVI、物理接口等上,都是如此。
如果你想过滤来自路由器的流量,你需要使用“ ip local policy route-map ”命令。
编辑:根据 YLearn 的建议添加参考:
根据我发现的 Cisco 文档,来自路由器的流量不受路由器接口上的访问列表的影响,仅受通过路由器的流量影响。
以下是链接到各自文档的 Cisco 文档中的一些引用:
现在,这些陈述似乎确实有例外。Ron 已经能够证明 ACL 确实有效果,至少在某些情况下是这样。我还没有找到任何文档来支持这一点,但也许具有 L2 功能的设备(例如他使用的 ISR)表现不同?我有时可以访问非生产 7600,所以如果我有机会测试它,我会更新我的发现。
以下是我在实验室中的路由器(1800s、2500s、2600/2600XM 和 3825)中可以通过各种代码一致获得的结果。我还要注意,我确实在一些点上剪掉了一些线以减少输出的长度(我的一些额外的播放/测试,与此测试无关的界面输出等)。首先,让我们通过显示此路由器上的串行接口、此路由器上的环回、显示邻居路由器的 cdp 邻居、路由到邻居路由器上的环回(包括那侧的串行 IP)和用于设置基线的基本 ping:
r7#sh ip int brie
Interface IP-Address OK? Method Status Protocol
Serial0/0 10.78.1.1 YES NVRAM up up
Loopback0 10.7.1.1 YES NVRAM up up
r7#sh cdp nei
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater
Device ID Local Intrfce Holdtme Capability Platform Port ID
r8 Ser 0/0 134 R 2610 Ser 0/0
r7#sh ip route 10.8.1.1
Routing entry for 10.8.1.1/32
Last update from 10.78.1.2 on Serial0/0, 6w4d ago
Routing Descriptor Blocks:
* 10.78.1.2, from 10.78.1.2, 6w4d ago, via Serial0/0
r7#ping 10.78.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.78.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
那么,让我们开始乐趣吧:
r7#sh ip access-lists
Extended IP access list TestACL
deny icmp any any echo
deny icmp any any echo-reply
permit ip any any
r7#config t
r7(config)#int Ser 0/0
r7(config-if)#ip access-group TestACL out
r7(config-if)#end
r7#ping 10.78.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.78.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
r7#ping 10.8.1.1 source lo 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.8.1.1, timeout is 2 seconds:
Packet sent with a source address of 10.7.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
r7#ping 10.78.1.2 source lo 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.78.1.2, timeout is 2 seconds:
Packet sent with a source address of 10.7.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
r7#sh ip access-lists
Extended IP access list TestACL
deny icmp any any echo
deny icmp any any echo-reply
permit ip any any
因此,我显示我的访问列表,将其应用于串行接口,并运行相同的 ping,然后 ping 来自环回的两个远程 IP 地址。所有三个工作都很好并再次显示访问列表,请注意没有命中。但也许我把它倒过来了?
r7(config)#int Ser 0/0
r7(config-if)#no ip access-group out
r7(config-if)#ip access-group TestACL in
r7(config-if)#end
r7#ping 10.78.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.78.1.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
现在看起来它被阻止了,但不是因为我向后应用了它。我们再来看看访问列表:
r7#sh ip access-lists
Extended IP access list TestACL
deny icmp any any echo
deny icmp any any echo-reply (10 matches)
permit ip any any (17 matches)
我们可以根据计数器看到,进入接口时被阻止的是来自邻居路由器的 echo-reply。这是我们使用此 ACL 入站时所期望的。请注意,permit 语句现在也有匹配项。这些是来自相邻路由器的路由更新和其他流量,但请注意,即使本地路由器也参与路由,出站 ACL 也没有获得任何许可匹配。
细心的读者可能会指出我的 ACL 与 Ron 的不匹配。它实际上是基于 OP 发布的原始问题。但是让我们运行一个类似于 Ron 的测试来排除这种情况。我还继续明确地允许我的第二个 IP 具有匹配计数器(如果它适用)。
r7#config t
r7(config)#int ser 0/0
r7(config-if)#no ip access-group in
r7(config-if)#exit
r7(config)#no ip access-list extended TestACL
r7(config)#ip access-list extended TestACL
r7(config-ext-nacl)#permit icmp any host 10.8.1.1
r7(config-ext-nacl)#deny icmp any host 10.78.1.2
r7(config-ext-nacl)#permit ip any any
r7(config-ext-nacl)#end
r7(config)#int ser 0/0
r7(config-if)#ip access
r7(config-if)#ip access-group TestACL out
r7(config-if)#end
r7#sh ip access-lists TestACL
Extended IP access list TestACL
permit icmp any host 10.8.1.1
deny icmp any host 10.78.1.2
permit ip any any
r7#ping 10.8.1.1 sourc lo 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.8.1.1, timeout is 2 seconds:
Packet sent with a source address of 10.7.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
r7#ping 10.78.1.2 source lo 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.78.1.2, timeout is 2 seconds:
Packet sent with a source address of 10.7.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
r7#sh ip access-lists
Extended IP access list TestACL
permit icmp any host 10.8.1.1
deny icmp any host 10.78.1.2
permit ip any any
这实际上取决于 ping 来自 ACL 的哪一侧。如果您在 LAN 端口上有入站 ACL,则源自 LAN 的 ping 甚至不会进入路由器,但来自路由器的 ping 已经在路由器中,因此它们永远不会交叉或由 ACL 评估。
有标准 ACL 和扩展 ACL,ACL 应用于一个方向(入站或出站)的接口。ACL 什么都不做,除非流量以正确的方向通过它,然后根据 ACL 评估流量,并根据 ACL 规则允许或拒绝流量。
测试:
Router1(config)#ip access-list extended Test
Router1(config-ext-nacl)#deny icmp any host 203.0.113.8
Router1(config-ext-nacl)#permit ip any any
Router1(config-ext-nacl)#int vlan100
Router1(config-if)#ip access-group Test out
Router1(config-if)#do ping 203.0.113.8
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.8, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Router1(config-if)#do ping 203.0.113.7
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.7, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Router1(config-if)#do ping 203.0.113.8 source loopback 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.8, timeout is 2 seconds:
Packet sent with a source address of 192.0.0.8
.....
Success rate is 0 percent (0/5)
Router1(config-if)#do ping 203.0.113.7 source loopback 0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.7, timeout is 2 seconds:
Packet sent with a source address of 192.0.0.8
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Router1(config-if)#do ping 203.0.113.8 source vlan 101
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.8, timeout is 2 seconds:
Packet sent with a source address of 203.0.113.129
.....
Success rate is 0 percent (0/5)
Router1(config-if)#do ping 203.0.113.7 source vlan 101
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.7, timeout is 2 seconds:
Packet sent with a source address of 203.0.113.129
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Router1(config-if)#do ping 203.0.113.8 source vlan 102
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.8, timeout is 2 seconds:
Packet sent with a source address of 192.0.2.253
.....
Success rate is 0 percent (0/5)
Router1(config-if)#do ping 203.0.113.7 source vlan 102
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 203.0.113.7, timeout is 2 seconds:
Packet sent with a source address of 192.0.2.253
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Router1(config-if)#
编辑:
我当然可以感谢@YLearn 和@Eddie 所做的所有彻底测试。我没有想过要深入研究它,我只是在做一个快速而肮脏的测试,看看会发生什么,而我上面的内容是我测试的全部范围。我会看看我能否在几周内做一些更好的测试。我愿意承认,在我测试的路由器上已经存在的其余配置中可能还有其他东西影响了我的测试。