RouterOS 简单调优

学习文档

强烈推荐 athlon 的《RouterOS 入门到精通》下载地址页:http://www.irouteros.com/?page_id=186
此文只记录实现功能,具体原理及基础请参考文档

端口转发

1
add action=dst-nat chain=dstnat protocol=tcp dst-port=9090 in-interface=pppoe-out1 to-addresses=10.1.1.6 to-ports=9090 comment=test-nat

把公网端口 9090 转发到 ip 10.1.1.6,端口 9090
需要注意的是,端口转发不收防火墙规则影响

静态 ip 绑定

image.png设置静态 ip,确定后,重新打开可修改 ip

设置 DHCP 属性

可用于给个别设备分配不同网关 ip,例如分配为 openwrt 旁路由
image.png
在静态 ip 配置中选择新建的属性即可
image.png

网络唤醒

Tools -> Wol,填入需要唤醒设备的 mac 地址即可,其他需要修改设备相关的请搜索其他文章,本文不做描述
每次记住 mac 地址很麻烦,可以设置为脚本

1
/system/script/add name=test source="/tool wol interface=ether1 mac=xx:xx:xx:xx:xx:xx"

时间设置

System->Clock 时区设置为 Asia/Shanghai
image.png
设置 ntp server 为阿里云
image.png

简单限速

1
/queue/simple/add name=test target=10.1.1.127 max-limit=1M/10M

10.1.1.127 限速上传 1M,下载 10M

DDNS

此处仅使用 cloudflare,阿里云,腾讯云等其他请参考其他文章
添加以下脚本,设置需要的 cloudflare 参数,此脚本支持检查是否变更,变更后才会调用 api 更新 dns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Cloudflare Dynamic DNS update script
# Required policy: read, write, test, policy
# Add this script to scheduler
# Install DigiCert root CA or disable check-certificate
# Configuration ---------------------------------------------------------------------

:local TOKEN "_TOKEN_"
:local ZONEID "_ZONEID_"
:local RECORDID "_RECORDID_"
:local RECORDNAME "_RECORDNAME_"
:local WANIF "pppoe-out1"

#------------------------------------------------------------------------------------

:global IP4NEW
:global IP4CUR

:local url "https://api.cloudflare.com/client/v4/zones/$ZONEID/dns_records/$RECORDID/"

:if ([/interface get $WANIF value-name=running]) do={
# Get the current public IP
:local requestip [/tool fetch url="http://ifconfig.io/ip" mode=http output=user as-value]
:set IP4NEW [:pick ($requestip->"data") 0 ([:len ($requestip->"data")]-1)]
# Check if IP has changed
:if ($IP4NEW != $IP4CUR) do={
:log info "CF-DDNS: Public IP changed to $IP4NEW, updating"
:local cfapi [/tool fetch http-method=put mode=https url=$url check-certificate=yes output=user as-value \
http-header-field="Authorization: Bearer $TOKEN,Content-Type: application/json" \
http-data="{\"type\":\"A\",\"name\":\"$RECORDNAME\",\"content\":\"$IP4NEW\",\"ttl\":1,\"proxied\":false}"]
:set IP4CUR $IP4NEW
:log info "CF-DDNS: Host $RECORDNAME updated with IP $IP4CUR"
} else={
:log info "CF-DDNS: Previous IP $IP4NEW not changed, quitting"
}
} else={
:log info "CF-DDNS: $WANIF is not currently running, quitting"
}

添加任务

1
/system/scheduler/add name=ddns-scheduler interval=00:05:00 on-event=ddns

每 5 分钟执行一次