思科CiscoPT路由器ACL配置实现单向访问

问题背景

网络拓扑图
路由器及连接PC配置如下:

接口接口IP连接设备设备IP
Fa0/0192.168.0.2/24PC0192.168.0.1/24
Fa0/1192.168.1.2/24PC1192.168.1.1/24
Fa1/0192.168.2.2/24PC2192.168.2.1/24

此时PC1与PC2、PC3为连通状态:

C:\>ping 192.168.1.1

Pinging 192.168.1.1 with 32 bytes of data:

Reply from 192.168.1.1: bytes=32 time<1ms TTL=127
Reply from 192.168.1.1: bytes=32 time<1ms TTL=127
Reply from 192.168.1.1: bytes=32 time<1ms TTL=127
Reply from 192.168.1.1: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.1.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>ping 192.168.2.1

Pinging 192.168.2.1 with 32 bytes of data:

Reply from 192.168.2.1: bytes=32 time<1ms TTL=127
Reply from 192.168.2.1: bytes=32 time<1ms TTL=127
Reply from 192.168.2.1: bytes=32 time<1ms TTL=127
Reply from 192.168.2.1: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.2.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

问题:配置路由器ACL使PC0不能访问PC1,但可以访问PC2,同时PC1仍可正常访问PC0。

即实现PC1对PC0的单向访问。


ACL配置

由于Access-list的执行是按照条目顺序逐步检查的,所以要严格设置ACL条目顺序。

ACL条目:

  1. 允许转发从PC0到PC1的icmp报文反馈
  2. 拒绝转发从PC0到PC1的一切报文
  3. 允许转发任何报文

按照一般的配置规则,允许类的语句应放在靠后的位置以防止ACL放过应该过滤的流量;
但这里却放在第一条,是因为我们对PC0到PC1的流量阻断是绝对的,而要保证PC1仍能正常访问PC0,则需要先把PC0的反馈报文设置成“白名单”,允许它通过。

显而易见,这样的ACL应设置在路由器与PC0的接口上,并且是进入方向上的。

那么具体实现的配置命令就可以写出来了:

Router>en
Router#conf t
Router(config)#acc 101 per icmp 192.168.0.0 0.0.0.255 192.168.1.0 0.0.0.255 echo-reply
Router(config)#acc 101 den ip 192.168.0.0 0.0.0.255 192.168.1.0 0.0.0.255
Router(config)#acc 101 per ip any any
Router(config)#int f0/0
Router(config-if)#ip acc 101 in
Router(config-if)#exit

此时测试PC间的连通性:

C:\>ping 192.168.1.1

Pinging 192.168.1.1 with 32 bytes of data:

Reply from 192.168.0.2: Destination host unreachable.
Reply from 192.168.0.2: Destination host unreachable.
Reply from 192.168.0.2: Destination host unreachable.
Reply from 192.168.0.2: Destination host unreachable.

Ping statistics for 192.168.1.1:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

C:\>ping 192.168.2.1

Pinging 192.168.2.1 with 32 bytes of data:

Reply from 192.168.2.1: bytes=32 time<1ms TTL=127
Reply from 192.168.2.1: bytes=32 time<1ms TTL=127
Reply from 192.168.2.1: bytes=32 time<1ms TTL=127
Reply from 192.168.2.1: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.2.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

可以看到PC0已经不能访问PC1,但仍能正常访问PC2;

C:\>ping 192.168.0.1

Pinging 192.168.0.1 with 32 bytes of data:

Reply from 192.168.0.1: bytes=32 time<1ms TTL=127
Reply from 192.168.0.1: bytes=32 time<1ms TTL=127
Reply from 192.168.0.1: bytes=32 time<1ms TTL=127
Reply from 192.168.0.1: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

同时PC1仍能正常访问PC0,即实现了PC1到PC0的单向访问。


后记

  1. 其实可以用反射ACL实现,逻辑性更强,但尝试许久reflect语句均报错,可能是PT版本不支持。自反ACL的用法参见:Cisco 自反ACL真机配置实例
  2. 因为涉及到对目的地址的限制,本文章ACL必须用扩展型语句,各种ACL的配置语法详见:标准ACL、扩展ACL和命名ACL的配置详解
  3. 思路来源:思科设备实现单向ping通—GNS3、PT
  • 5
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值