标准 ACL 只匹配源地址,扩展 ACL 可匹配源/目的、协议、端口和标志位。ACL 从上到下匹配,命中即停止;Cisco 扩展 ACL 末尾有隐式 deny ip any any,Junos filter 未命中默认丢弃。方向以设备为参照:inbound 是进入接口的报文,outbound 是离开接口的报文。ACL 是无状态的,回程流量要单独放行。
把 ACL 应用到管理接口、VTY 或安全策略前,先确认不会切断 SSH/SNMP 和业务流量。保留 Console 或带外通道,Cisco 可先 reload in 10 作为保险;回滚是移除 ip access-group、traffic-filter、packet-filter 或 Junos filter 引用。不同厂商对未匹配报文的默认动作不同,以设备版本为准,并在现网实测。
Cisco IOS/IOS-XE
access-list 10 permit 192.0.2.0 0.0.0.255
access-list 100 permit tcp 192.0.2.0 0.0.0.255 host 203.0.113.10 eq 443
access-list 100 deny ip any any log
interface GigabitEthernet0/1
ip access-group 100 in
show ip access-lists 100
Huawei VRP
acl number 3000
rule 5 permit tcp source 192.0.2.0 0.0.0.255 destination 203.0.113.10 0 destination-port eq 443
rule 10 deny ip
interface GigabitEthernet0/0/1
traffic-filter inbound acl 3000
display acl 3000
H3C Comware
acl advanced 3000
rule 5 permit tcp source 192.0.2.0 0.0.0.255 destination 203.0.113.10 0 destination-port eq 443
interface GigabitEthernet1/0/1
packet-filter 3000 inbound
display acl 3000
Juniper Junos
set firewall family inet filter IN term 10 from source-address 192.0.2.0/24
set firewall family inet filter IN term 10 from destination-address 203.0.113.10/32
set firewall family inet filter IN term 10 from protocol tcp
set firewall family inet filter IN term 10 from destination-port 443
set firewall family inet filter IN term 10 then accept
set firewall family inet filter IN term 20 then discard
set interfaces ge-0/0/1 unit 0 family inet filter input IN
0.0.0.255 对应 /24;写成 255.255.255.0 会匹配错误范围。log 会带来额外 CPU 和日志量,生产环境谨慎开启。合上页面,先回答,再展开对照。
deny ip any any 丢弃,所以规则设计要覆盖回程和必要协议。
小程序版
微信扫码,随时查命令