你的浏览器无法正常显示内容,请更换或升级浏览器!

MikroTik防火墙配置实战

tenfei
tenfei
发布于2026-04-21 16:47 阅读4次
MikroTik防火墙配置实战
全面讲解MikroTik RouterOS防火墙的配置方法与实战技巧,涵盖Filter规则链、安全策略设计、端口扫描防护以及常见攻击防御方案,助你构建坚不可摧的网络安全防线。
# MikroTik 防火墙配置实战 MikroTik RouterOS 内置了功能强大的防火墙系统,基于 Linux netfilter 框架,支持 Filter、NAT、Mangle、Raw 四张表,能够满足从家庭网络到企业级部署的各种安全需求。本文聚焦 Filter 表的实战配置。 ## 一、防火墙基础架构 RouterOS 防火墙有三条内置链: - **input** — 处理进入路由器自身的流量 - **forward** — 处理穿越路由器转发的流量 - **output** — 处理从路由器自身发出的流量 每条链中的规则从上到下依次匹配,一旦命中即执行动作,不再继续往下。因此规则的顺序至关重要。 ## 二、安全配置原则 ### 1. 默认拒绝 最安全的策略是默认拒绝所有流量,再逐条放行必要的服务: ``` /ip firewall filter add chain=input action=drop comment="Drop All" ``` 将此规则放在最后作为兜底,前面的规则放行合法流量。 ### 2. 分层防护 按照以下优先级组织规则: 1. 放行已建立和相关的连接(established/related) 2. 放行特定服务(ICMP、Winbox、SSH 等) 3. 丢弃无效连接(invalid) 4. 兜底拒绝 ## 三、Input 链配置示例 保护路由器自身的安全是最优先的事项: ``` /ip firewall filter add chain=input action=accept connection-state=established,related comment="Accept Established/Related" add chain=input action=accept protocol=icmp comment="Accept ICMP" add chain=input action=accept in-interface=bridge comment="Accept from LAN" add chain=input action=drop connection-state=invalid comment="Drop Invalid" add chain=input action=drop comment="Drop All Other" ``` 这段配置确保只有来自内网的流量和已建立的连接才能访问路由器,外部完全无法直接连接。 ### 限制 Winbox 访问 Winbox 是管理 MikroTik 的主要工具,务必限制其访问来源: ``` /ip firewall filter add chain=input action=accept protocol=tcp dst-port=8291 src-address-list=LAN comment="Winbox from LAN only" ``` 通过 src-address-list 限制只有内网地址才能访问 Winbox 端口。 ## 四、Forward 链配置示例 Forward 链控制内网与外网之间的流量转发: ``` /ip firewall filter add chain=forward action=accept connection-state=established,related comment="Accept Established/Related" add chain=forward action=drop connection-state=invalid comment="Drop Invalid" add chain=forward action=accept in-interface=bridge out-interface=ether1 comment="LAN to WAN" add chain=forward action=drop comment="Drop All Other" ``` ### 阻止端口扫描 攻击者常通过端口扫描探测网络服务,可以在 Raw 表中提前阻断: ``` /ip firewall raw add chain=prerouting action=drop protocol=tcp psd=21,3s,3,1 comment="Drop Port Scan" ``` psd 参数含义:前 3 秒内从同一 IP 收到 21 个不同端口的 TCP SYN 包则判定为端口扫描。 ## 五、常用安全加固措施 ### 1. 禁用不必要的服务 ``` /ip service disable telnet,ftp,www ``` 只保留必要的服务端口,减少攻击面。 ### 2. 更改默认管理端口 ``` /ip service set winbox port=18291 ``` 将 Winbox 端口从默认的 8291 改为非标准端口,避免自动化扫描工具。 ### 3. 地址列表白名单 ``` /ip firewall address-list add address=192.168.88.0/24 list=LAN ``` 在规则中引用地址列表而非硬编码网段,方便后续维护。 ## 六、日志与排错 配置防火墙时建议开启日志,方便排查问题: ``` /ip firewall filter add chain=input action=log log-prefix="INPUT-DROP" action=drop ``` 通过 `/log print where message~"INPUT-DROP"` 查看被丢弃的数据包信息。 ## 七、总结 MikroTik 防火墙的核心思路是:默认拒绝、分层防护、最小放行。配置时从 input 链开始保护路由器自身,再配置 forward 链控制转发流量。配合 Raw 表的端口扫描防护和服务加固措施,可以构建出企业级的安全防线。

1

0

文章点评
赞助商广告位
Copyright © from 2021 by namoer.com
458815@qq.com QQ:458815
蜀ICP备2022020274号-2