分类 网络 下的文章

免费的 Oracle Cloud 实例的确是太不好用了,经常给主动停机,这种鸡肋不要也罢。龙年到,更换一个网站服务器。

第一个 get_datetime 脚本是规范日期格式的写法:

:global DateTime
:local Date [/system clock get date]
:local Time [/system clock get time]
:local Month [:tostr ([:find [:toarray "jan,feb,mar,apr,may,jun,jul,ago,sep,oct,nov,dec"] [:pick $Date 0 3]]+1)]
#if MM
#:if ([:len $Month]<2) do={:set Month "0$Month"}
# Format YYYY-M-D H:MM:SS
#\E5\B9\B4 \E6\9C\88 \E6\97\A5
:set DateTime ([:pick $Date 7 11]."-".$Month."-".[:tonum [:pick $Date 4 6]]." ".[:tonum [:pick $Time 0 2]].[:pick $Time 2 8])

第二个 Check_WAN_IP 脚本是检测到路由器的公网地址变化时自动发送钉钉机器人消息:
(此脚本使用的是钉钉消息的自定义关键字模式,指定的关键字是[路由器]即[\E8\B7\AF\E7\94\B1\E5\99\A8]这几个字符串,可自行修改。)

:global currentIP;
:global DateTime;
:execute "get_datetime"
:local newIP [/ip address get [find interface="pppoe-out1"] address];
:if ($newIP != $currentIP) do={
#    :put "ip address $currentIP changed to $newIP";
    :local header "Content-Type:application/json";
    :local dingtalk "https://oapi.dingtalk.com/robot/send?access_token=xxxxxx";
    :local data "{\"msgtype\":\"text\",\"text\": {\"content\":\"$DateTime \E5\AE\BD\E5\B8\A6\E5\85\AC\E7\BD\91 IP \E5\8F\98\E6\9B\B4\E4\B8\BA: $newIP, [\E8\B7\AF\E7\94\B1\E5\99\A8]\"}}";
    :log info [/tool/fetch http-method=post mode=https http-header-field="$header" http-data="$data" url="$dingtalk"];
    :log warning "公网地址由 $currentIP 变为 $newIP";
    :set currentIP $newIP;
};

说明:此脚本中宽带拨号的接口是 pppoe-out1,用法是打开 /ppp/Profiles 下拨号使用的 profile 条目,在 script 标签页下的 On Up 对话框中输入如下内容(延迟三秒执行):

delay 3s
:execute "Check_WAN_IP"

NAT 回流(Hairpin NAT),简单地说就是在客户机用公网IP+端口的方式访问位于同一内网网段的服务器映射端口。RouterOS 在升级 V7.x 版本之前,使用一条 srcnat 规则将内网IP段做个地址伪装或snat即可,如下所示:

chain=srcnat action=masquerade to-addresses=192.168.1.254 src-address=192.168.1.0/24 dst-address=192.168.1.0/24

或:

chain=srcnat action=src-nat to-addresses=192.168.1.254 src-address=192.168.1.0/24 dst-address=192.168.1.0/24

但是自从RouterOS升级到 V7.x版本之后,这条 srcnat 规则就失效了,研究了很久未果。

今天去逛官方论坛,发现在一个帖子里有网友 ivicask 提到需要在 bridge 设置里关闭防火墙:

/interface/bridge/settings
set use-ip-firewall=no

试了一下,果然有效。