MikroTik RouterOS Port Knocking 安全配置教程

为什么需要 Port Knocking?

为了让你家里的私人服务端口、路由器端口暴露在公网后更加安全,不那么容易被扫描和入侵。简单点说通过RouterOS 防火墙功能里的一个小机制,实现只有按特定顺序对指定端口“敲门”后,才能访问服务。

第一步:创建敲门规则

# 第1次敲门 – 监听端口10008

/ip firewall filter add chain=input action=add-src-to-address-list \
protocol=udp address-list=knock1 address-list-timeout=5s \
in-interface-list=WAN dst-port=10008 comment="1st knock"

这里建立了一个叫做knock1 的地址列表,当udp10008 端口被访问的时候,来源公网IP 会被记录,但只保存5秒。

# 第2次敲门 – 监听端口10002

/ip firewall filter add chain=input action=add-src-to-address-list \
protocol=udp src-address-list=knock1 address-list=knock2 \
address-list-timeout=12h in-interface-list=WAN dst-port=10002 \
comment="2nd knock"

这里建立了一个叫做knock2 的地址列表,当udp10002 端口被访问,同时来源公网IP 在knock1 列表里,那么就会被记录,这个记录会保存12小时。

第二步:配置访问控制

/ip firewall filter add chain=forward action=drop protocol=tcp \
src-address-list=!knock2 in-interface-list=WAN \
dst-port=22,8291,8728 comment="block non-knocked IPs"

除了knock2 列表里的地址访问敏感端口都会被拒绝。

这是一个比较简单的配置实现,为了更加安全可以增加更多的端口knock 来确保不会被暴力破解,访问控制那里也可以按照自己的实际情况更改。

客户端部分,macOS 和iOS 推荐PortKnock 这个小巧的APP 来触发Port Knocking。

Leave a Reply

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).