Mikrotik软路由安全配置

最近Mikrotik路由器老是被攻击,因此特意研究了一下官方wiki中的安全建议,下面这些方法可根据自身情况进行操作

1、升级软路由版本

首先升级你的RouterOS版本, 一些较旧的版本具有某些弱点或漏洞, 使设备保持最新状态,以确保设备安全。

2、新建用户

新建一个“full”组的新用户,密码设置得尽量复杂一些,使用该用户登陆后,把默认的用户admin删除。

/user add name=myname password=mypassword group=full
/user remove admin

3、设置用户允许的IP地址

/user set 0 allowed-address=192.168.88.0/24

4、使用安全的方式管理软路由

所有生产中的路由器都必须通过ssh、安全的winbox或https服务进行管理,注意,在最新的winbox版本中,“安全模式”默认为打开,不能再关闭。
在这里插入图片描述

5、关闭不安全的服务

#查看所有的服务
/ip service print

#关闭不安全的服务
/ip service disable telnet,ftp,www,api,api-ssl

#更改ssh默认端口
/ip service set ssh port=2200

#每个服务都可以设置只允许指定的ip访问
/ip service set winbox address=192.168.88.0/24

6、禁用MAC远程登录

禁用该功能后winbox就无法使用MAC地址登录了

/tool mac-server set allowed-interface-list=none
/tool mac-server print

/tool mac-server mac-winbox set allowed-interface-list=none
/tool mac-server mac-winbox print

/tool mac-server ping set enabled=no
/tool mac-server ping print

7、禁用Neighbor Discovery(邻居发现)

MikroTik邻居发现协议用于显示和识别网络中的其他MikroTik路由器,在所有接口上禁用邻居发现,禁用该功能后在winbox的Neighbors中就无法搜索到软路由了

/ip neighbor discovery-settings set discover-interface-list=none 

8、Bandwidth server

Bandwidth server 用于测试两个MikroTik路由器之间的吞吐量, 在生产环境中禁用它。

/tool bandwidth-server set enabled=no 

9、DNS cache

DNS缓存:路由器可能启用了DNS缓存,从而减少了从客户端到远程服务器的DNS请求的解析时间。
如果您的路由器上不需要DNS缓存,或者其他路由器上已经开启了DNS缓存,那么请将其禁用。

/ip dns set allow-remote-requests=no

10、其他的一些clients services

RouterOS可能启用了其他服务(默认情况下,它们是被RouterOS禁用的)若不需要,则将其禁用。

/ip proxy set enabled=no
/ip socks set enabled=no
/ip upnp set enabled=no
/ip cloud set ddns-enabled=no update-time=no

11、打开SSH strong crypto

RouterOS对SSH使用更强的加密,大多数较新的程序都使用它,可以将其打开。

/ip ssh set strong-crypto=yes

12、禁用未使用的接口

最好禁用路由器上所有未使用的接口,以减少对路由器的未授权访问。

/interface print
/interface set x disabled=yes

13、禁用LCD

有些线路板有LCD模块,用于提供信息、设置引脚或是禁用它。

/lcd set enabled=no

14、设置防火墙

14.1 IPv4防火墙

14.1.1 路由器的IPv4防火墙

强烈建议打开防火墙,如下面防火墙规则可以使RouterOS更安全,请在了解规则的作用后,应用规则:
1、使用新的连接来减少路由器的负载;
2、为允许访问路由器的IP地址创建地址列表;
3、启用ICMP访问(可选);
4、丢弃其他所有内容,可能会添加log = yes来记录符合特定规则的数据包。

/ip firewall filter
add action=accept chain=input comment="default configuration" connection-state=established,related
add action=accept chain=input src-address-list=allowed_to_router
add action=accept chain=input protocol=icmp
add action=drop chain=input

/ip firewall address-list
add address=192.168.88.2-192.168.88.254 list=allowed_to_router

14.1.2 客户端的IPv4防火墙

1、 已建立/相关的数据包被添加到fasttrack中,以获得更快的数据吞吐量,防火墙将仅与新连接一起工作;
2、删除无效连接并用前缀invalid记录;
3、丢弃尝试从您的本地网络访问非公共地址的操作,在此之前应用 address-list=not_in_internet,bridge1是本地网络接口,使用 !public_from_LAN 记录尝试;
4、丢弃未经过NAT的传入数据包,ether1是公共接口,使用 !NAT 前缀记录尝试次数;
5、丢弃来自Internet的传入数据包,这些数据包不是公共IP地址,ether1是公共接口,使用前缀记录尝试 !public;
6、从没有局域网IP的局域网中丢弃数据包,192.168.88.0/24是局域网使用的子网。

/ip firewall filter
add action=fasttrack-connection chain=forward comment=FastTrack connection-state=established,related
add action=accept chain=forward comment="Established, Related"  connection-state=established,related
add action=drop chain=forward comment="Drop invalid" connection-state=invalid log=yes log-prefix=invalid
add action=drop chain=forward comment="Drop tries to reach not public addresses from LAN" dst-address-list=not_in_internet in-interface=bridge1 log=yes log-prefix=!public_from_LAN out-interface=!bridge1
add action=drop chain=forward comment="Drop incoming packets that are not NATted" connection-nat-state=!dstnat connection-state=new in-interface=ether1 log=yes log-prefix=!NAT
add action=drop chain=forward comment="Drop incoming from internet which is not public IP" in-interface=ether1 log=yes log-prefix=!public src-address-list=not_in_internet
add action=drop chain=forward comment="Drop packets from LAN that do not have LAN IP" in-interface=bridge1 log=yes log-prefix=LAN_!LAN src-address=!192.168.88.0/24

/ip firewall address-list
add address=0.0.0.0/8 comment=RFC6890 list=not_in_internet
add address=172.16.0.0/12 comment=RFC6890 list=not_in_internet
add address=192.168.0.0/16 comment=RFC6890 list=not_in_internet
add address=10.0.0.0/8 comment=RFC6890 list=not_in_internet
add address=169.254.0.0/16 comment=RFC6890 list=not_in_internet
add address=127.0.0.0/8 comment=RFC6890 list=not_in_internet
add address=224.0.0.0/4 comment=Multicast list=not_in_internet
add address=198.18.0.0/15 comment=RFC6890 list=not_in_internet
add address=192.0.0.0/24 comment=RFC6890 list=not_in_internet
add address=192.0.2.0/24 comment=RFC6890 list=not_in_internet
add address=198.51.100.0/24 comment=RFC6890 list=not_in_internet
add address=203.0.113.0/24 comment=RFC6890 list=not_in_internet
add address=100.64.0.0/10 comment=RFC6890 list=not_in_internet
add address=240.0.0.0/4 comment=RFC6890 list=not_in_internet
add address=192.88.99.0/24 comment="6to4 relay Anycast [RFC 3068]" list=not_in_internet

14.2 IPv6防火墙

14.2.1 禁用IPv6功能

默认情况下IPv6功能是禁用的, 请小心启用软件包,因为RouterOS不会为IPv6创建任何默认防火墙规则。

/ipv6 nd set [find] disabled=yes

14.2.2 路由器的IPv6防火墙

1、处理新数据包,接受已建立/相关的数据包;
2、从Internet接口删除链接本地地址;
3、接受来自本地链接地址的路由器访问,接受用于管理目的的多播地址,接受
4、您的地址用于路由器访问;
5、丢下其他东西。

/ipv6 firewall filter
add action=accept chain=input comment="allow established and related" connection-state=established,related
add chain=input action=accept protocol=icmpv6 comment="accept ICMPv6"
add chain=input action=accept protocol=udp port=33434-33534 comment="defconf: accept UDP traceroute"
add chain=input action=accept protocol=udp dst-port=546 src-address=fe80::/16 comment="accept DHCPv6-Client prefix delegation."
add action=drop chain=input in-interface=sit1 log=yes log-prefix=dropLL_from_public src-address=fe80::/16
add action=accept chain=input comment="allow allowed addresses" src-address-list=allowed
add action=drop chain=input

/ipv6 firewall address-list
add address=fe80::/16 list=allowed
add address=xxxx::/48  list=allowed
add address=ff02::/16 comment=multicast list=allowed

14.2.3 客户端的IPv6防火墙

启用的IPv6使您的客户端可用于公共网络,设置适当的防火墙以保护安全。
1、接受已建立的/相关的并处理新的数据包;
2、丢弃无效的数据包并为规则添加前缀;
3、接受ICMP数据包;
4、接受客户到Internet的新连接;
5、放弃其他一切。

/ipv6 firewall filter
add action=accept chain=forward comment=established,related connection-state=established,related
add action=drop chain=forward comment=invalid connection-state=invalid log=yes log-prefix=ipv6,invalid
add action=accept chain=forward comment=icmpv6 in-interface=!sit1 protocol=icmpv6
add action=accept chain=forward comment="local network" in-interface=!sit1 src-address-list=allowed
add action=drop chain=forward log-prefix=IPV6

参考文档https://wiki.mikrotik.com/wiki/Manual:Securing_Your_Router

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章