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

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