返回列表 發帖

MikroTik router 怎样每天更换IP address?

本帖最後由 角色 於 2018-10-19 11:26 編輯

=== gfx 提供 的方法更加精彩 Link ===
=== 在安装第一楼的script前,请看第二楼信息,和先安装第三楼的script,买个保险 ===

因为科学上网,导致梯子经常给发现(通过不同的大陆IP address接到国外的服务器),如果阿爷系统侦测到,先干扰后block IP,所以每天必须更换IP address才能尽量避开被block ip的命运。

之前我用过怎样更改mac address,但是比较复杂,还有没有必要,现在下面有个简单的方法。

下面的script,就是把ether1关(disabled=yes),然后等8分钟,再把ether1 开(disabled=no)。IP就会自动更换,一般系统5分钟就可以把之前分配的IP给忘了,现在我用8分钟,是比要求长一定。我是用PCCW,估计系统ISP,如HKBN,或者HGC也可以。

用winbox打开MikroTik router,然后在system->script,加上一个script叫ether1-down-up,如下图:

.

上图的code:
  1. /interface ethernet set ether1 disabled=yes
  2. :log warning "Interface 1 is down"

  3. delay "8m";

  4. /interface ethernet set ether1 disabled=no
  5. :log warning "Interface 1 is up"
複製代碼
.

在sytem->scheduler,加入一个每天凌晨4点钟进行更换IP。


Start Time: 04:00:00
Interval: 1d 00:00:00

1d = 1 day (每天)

如果你想进行快速测试(每15分钟),Interval可以修改为
Interval = 00:15:00

在大陆的DNS server,需要大约等10分钟,新的IP Address才能更新到大陆来,如果在ether1 up后10分钟,在大陆才能access到香港改了IP adress的Mikrotik router。
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

在使用上会遇到很多不知道的结果,例如我喜欢用command line打命令,还有script的“预计结果”有误,导致到WAN口ether1被关上,要等晚上家里人回来接上电脑才能把router ether1唤醒(打开ether1)。有的时候因为所有interface etherX都被关上,有电脑和LAN cable都没有用,要用serial cable才能唤醒,而香港也很好买到那种cable,需要在大陆淘宝,然后寄回香港,再把router用serial cable才能打开,所以大家一定要小心行事。

经历过N次,ether1被关上,本人想出另外一个方法,就是自动把WAN口ether1欢呼到打开。

TOP

本帖最後由 角色 於 2018-10-17 12:56 編輯

为了防止在上面的ether1被错误理解指令被关上,大家可以用下面的script。


.
  1. /interface ethernet set ether1 disabled=no
  2. :log warning "Interface 1 is forced to up"
  3. /code].


  4. .

  5. [code]
  6. /system script run ether1-up
複製代碼
.
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

TOP

上面的script,有需要就开着或者关着,但是做实验必须开着ether1-wake-up

就在“+” enable,“-” disable

附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

TOP

谢谢CHing,我把你上面的script exactly copied我的MikroTik Router,明天就知道结果。

TOP

经过测试确实可以用,谢谢CHing。

从[1]里的信息,都有类似师兄的script来源:
  1. /ip dhcp-client
  2. add add-default-route=no dhcp-options=hostname,clientid disabled=no interface=ether2 script="{\r\
  3.     \n    :local rmark \"WAN1\"\r\
  4.     \n    :local count [/ip route print count-only where comment=\"WAN1\"]\r\
  5.     \n    :if (\$bound=1) do={\r\
  6.     \n        :if (\$count = 0) do={\r\
  7.     \n            /ip route add gateway=\$\"gateway-address\" comment=\"WAN1\" routing-mark=\$rmark\r\
  8.     \n        } else={\r\
  9.     \n            :if (\$count = 1) do={\r\
  10.     \n                :local test [/ip route find where comment=\"WAN1\"]\r\
  11.     \n                :if ([/ip route get \$test gateway] != \$\"gateway-address\") do={\r\
  12.     \n                    /ip route set \$test gateway=\$\"gateway-address\"\r\
  13.     \n                }\r\
  14.     \n            } else={\r\
  15.     \n                :error \"Multiple routes found\"\r\
  16.     \n            }\r\
  17.     \n        }\r\
  18.     \n    } else={\r\
  19.     \n        /ip route remove [find comment=\"WAN1\"]\r\
  20.     \n    }\r\
  21.     \n}\r\
  22.     \n"
複製代碼
.

Ref:
[1] https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Client

TOP

回復 5# gfx86674

CHing, 从图上开的default route distance = 5,而我是 = 1,是否 = 5有别的用途呢?

TOP

返回列表