跳转至

RouterOS 基础配置规范

ROS路由器配置模板

第一部分、基础配置

Mikrotik设备

注意事项

1.1.1、Mikrotik设备默认账号admin,密码空配;

1.1.2、重置后使用/export查验是否有残留配置;

1.1.3、使用add 新增不带name等具有唯一性的参数命令时,需检查是否有重复导致垃圾配置;

1.1.4、移除临时测试等垃圾配置;

1.1.5、在线设备操作,务必考虑是否影响业务,设备脱管等情况,必须安全模式下操作【批量操作:每次少于100条修改,超100条修改导致中断的话安全模式也无法回滚】

(点击winbox的Settings下方的safe mode 按钮 或 命令行的 ctrl+x );

1.1.6、更换ip时,需考虑是否有关联的路由下一跳、本地GRE源ip 及 ipsec网关端的GRE目标ip等,同一接口可配置多组ip,建议采用建新拆旧;

1.1.7、移除Tunnel等接口时,需考虑关联接口的路由下一跳、NAT、ip地址等,建议采用建新拆旧。

1.1.8、默认修改winbox、ssh端口及限制访问ip,关闭telnet功能;

1.1.9、设备启用dns服务需要注意禁用来自互联网端的dns请求,参考2.1.7、DNS服务

1.1.10、winbox登陆后内容是空白,telnet或ssh print/export 不出内容的,尝试重启无效后可以 尝试调整对应出接口的MTU,(例如:mtu=1400)

1.2 准备项

1.2.1、首先要重置清空配置,申领符合客户业务所需的型号设备,SecureCRT/Putty串口115200比特位或Winbox mac “New Terminal”访问,重置(移除默认配置)并重启设备:

/system reset-configuration keep-users=no no-defaults=yes skip-backup=yes

Dangerous! Reset anyway? [y/N]: y

注:

如忘记密码可尝试硬复位(复位后进入设备再次执行上条命令进行默认配置的移除) :

方法一、按住路由器背面标有“reset”的孔中按键后通电10至15秒钟然后松开;

方法二、面板LCD通过PIN码重置,选择Reset Configuration,然后跳出PIN即可重置,出厂默认PIN码:1234。

1.2.2、升级版本:

在线升级(强烈建议):

设备接入DHCP环境网络下:

ether1自动获取ip参考下面命令,注:升级完毕后务必移除临时配置

1、Winbox命令行:

/ip dhcp-client add comment=defconf disabled=no interface=ether1 add-default-route=yes use-peer-dns=yes

2、

方式a、Winbox登入后在System-Packages-点击"Check For Updates"-Channel"stable"-点击"Download&Install",设备将自动重启升级;

方式b、命令行升级版本:

:do {

/system package update

check-for-updates once;

:delay 3s;

:if ( [get status] = "New version is available") do={ install }

}

3、

重启后,升级完成需移除dhcp配置:

/ip dhcp-client remove [ find ]

离线升级(不能在线升级才选择):

登陆官网https://mikrotik.com/download 根据型号下载最新(Stable)固件,通过Winbox放入设备Files 后重启升级到最新稳定版本;

/system reboot

Reboot, yes? [y/N]: y

1.3、通用配置,必配

1.3.1、ROS服务端口限制(关闭telnet)

/ip service set telnet disabled=yes
/ip service set ftp disabled=yes
/ip service set www disabled=yes
/ip service set ssh disabled=no port=22202
/ip service set api disabled=yes
/ip service set winbox disabled=no port=28291
/ip service set api-ssl disabled=yes

1.3.2、创建标准账号,移除admin账号

/user add group=full name=admin_user password="CHANGE_ME_TO_A_UNIQUE_STRONG_PASSWORD"
/user add password="CHANGE_ME_TO_ANOTHER_UNIQUE_STRONG_PASSWORD" group=read name=readonly_user
/user remove  [ find name=admin ] 

1.3.4、Snmp配置

/snmp community set [ find default=yes ] disabled=yes
/snmp community add name=snmp_readonly
/snmp set enabled=yes trap-community=snmp_readonly trap-version=2

1.4、按需配置

1.4.1、创建接口

/interface bridge
add name=loopback-ipsec-ct
add name=loopback-ipsec-cu

/interface gre
add keepalive=10s,3 allow-fast-path=no local-address=198.19.0.22 name=gre-ct remote-address=203.0.113.242
add keepalive=10s,3 allow-fast-path=no local-address=198.19.0.23 name=gre-cu remote-address=203.0.113.208

1.4.2、接口地址

/ip address
add address=198.19.0.22 comment=ipsec-ct interface=loopback-ipsec-ct network=198.19.0.22
add address=198.19.0.23 comment=ipsec-cu interface=loopback-ipsec-cu network=198.19.0.23


add address=198.19.1.26/30 comment=to-provider-ct interface=gre-ct network=198.19.1.24
add address=198.19.1.30/30 comment=to-provider-cu interface=gre-cu network=198.19.1.28

1.4.3、配置wan口DHCP、(是否下发默认路由)

#wan口为dhcp时,用dhcp-client的功能保护203.0.113.242/32路由
/ip dhcp-client add interface=ether1 add-default-route=yes script=":if (\$bound=1) do={:do {/ip route remove [find comment=\"to-forti-ipsec-wan\"]} on-error={}; /ip route add dst-address=203.0.113.242/32 gateway=\$\"gateway-address\" comment=\"to-forti-ipsec-wan\"}"

#不加默认路由
/ip dhcp-client
add add-default-route=no interface=ether1 script=":if (\$bound=1) do={:do {/ip route remove [find comment=\"to-forti-ipsec-wan\"]} on-error={}; /ip route add dst-address=203.0.113.242/32 gateway=\$\"gateway-address\" comment=\"to-forti-ipsec-wan\"}"

1.4.4、配置ipsec

/ip ipsec profile
add dh-group=ecp384 dpd-interval=10s dpd-maximum-failures=5 enc-algorithm=aes-256 hash-algorithm=sha384 name=profile-forti

/ip ipsec peer
add address=203.0.113.242/32 exchange-mode=ike2 name=peer-ct profile=profile-forti

/ip ipsec proposal
add auth-algorithms="" enc-algorithms=aes-256-gcm pfs-group=ecp384 name=proposal-forti

/ip ipsec identity
add my-id=address:198.19.0.19 peer=peer-ct secret="CHANGE_ME_TO_A_UNIQUE_IPSEC_PSK"

/ip ipsec policy
add dst-address=203.0.113.242/32 peer=peer-ct proposal=proposal-forti protocol=gre src-address=198.19.0.19/32 tunnel=yes

1.4.5、配置隧道默认路由

/ip route
add dst-address=0.0.0.0/0 gateway=198.19.2.5

1.4.5、配置防火墙放行gre和mss分片

/ip firewall nat
add action=accept chain=srcnat comment=ipsec-gre-bypass dst-address=203.0.113.242 protocol=gre src-address=198.19.0.22
add action=accept chain=srcnat comment=ipsec-gre-bypass dst-address=203.0.113.208 protocol=gre src-address=198.19.0.23

/ip firewall mangle
add action=change-mss chain=forward comment="clamp MSS return via gre-ct" new-mss=1300 out-interface=gre-ct protocol=tcp tcp-flags=syn tcp-mss=1301-65535
add action=change-mss chain=forward comment="clamp MSS return via gre-ct" in-interface=gre-ct new-mss=1300 protocol=tcp tcp-flags=syn tcp-mss=1301-65535
add action=change-mss chain=forward comment="clamp MSS return via gre-cu" new-mss=1300 out-interface=gre-cu protocol=tcp tcp-flags=syn tcp-mss=1301-65535
add action=change-mss chain=forward comment="clamp MSS return via gre-cu" in-interface=gre-cu new-mss=1300 protocol=tcp tcp-flags=syn tcp-mss=1301-65535

1.4.5、配置管理网段

/ip route
add disabled=no dst-address=10.0.0.0/8 gateway=198.19.4.9 routing-table=main
add disabled=no distance=1 dst-address=100.96.0.0/24 gateway=198.19.11.25 routing-table=main scope=30 target-scope=10

/system clock set time-zone-name=Asia/Shanghai

/system ntp client set enabled=yes

/system ntp client servers

add address=ntp.aliyun.com

add address=ntp.tencent.com

add address=cn.pool.ntp.org