Board logo

標題: [VPN] 黑貓VPN pptp-client的pcc,並搭配Script修正! [打印本頁]

作者: gfx86674    時間: 2015-1-2 01:05     標題: 黑貓VPN pptp-client的pcc,並搭配Script修正!

本帖最後由 gfx86674 於 2015-1-13 19:01 編輯

小弟試做二個黑貓VPN pptp-client的pcc,並搭配Script做修正!
有興趣可以參考:


二個黑貓VPN帳號 pptp-client /route /nat /mangle設定:


二條pptp-client做pcc ,怕的是其中一個斷線,均分會出問題.
斷線的流量會分到default route ,而非另一個pptp-client遞補..

且斷線的pptp-client會不斷的重新連線 ,若伺服器掛點
必造成log不斷的被pptp-client重新連線資訊給洗版.

所以搭配腳本修正,
若其中一條pptp-client斷線便自動修正成單線負載.
斷線的pptp-client會自動關閉,定時透過ping來測試伺服器反應.
等伺服器有回應時再重新嘗試連接.
等pptp-client上線後,待腳本恢復原本的pcc負載即可.

目前黑貓是屬於斷網的狀態,所有的VPN設定將被腳本干預全部關閉.
就算您手動enable部份功能,下一秒也會被腳本disable
作者: 角色    時間: 2015-1-2 01:17

你的OS是哪个version?,我的6.23 local只能single line 用,而不可以跨越":".
作者: gfx86674    時間: 2015-1-2 02:10

本帖最後由 gfx86674 於 2015-1-4 12:48 編輯

v6.24
要在new terminal視窗宣告:local 前,
第一行要先執行 "{"這個符號代表開始,最後一行輸入 "}"代表結束.

所以在terminal視窗run腳本要這麼做:


若是將Script存到排程,腳本開始的"{" 與尾端的"}"可以忽略.
但請依官網指示在尾端加2行空白行.
作者: 角色    時間: 2015-1-2 13:45

明白。CHing,你是怎样run script呢?我好像用import sample.rsc
作者: gfx86674    時間: 2015-1-2 15:20

本帖最後由 gfx86674 於 2015-1-2 22:13 編輯

把Script貼到排程去,設定每次循環的時間就可以上工了


如前所述Script頭尾不用再補上"{"與"}" ,但最後要加兩行空白行.
作者: gfx86674    時間: 2015-1-4 00:47

本帖最後由 gfx86674 於 2015-1-4 01:48 編輯

與一樓同,但改用迴圈編譯.
參數是從address-list抓取衍生.

因不像一樓名稱與地址是手動直接給的,
所以每次循環都要重新搜尋值,導致路由器執行腳本時CPU負載偏高.

從另一面來看,或許是Mikrotik RB450G該汰換升級了

作者: yiucsw    時間: 2015-1-13 17:25

有没有其他VPN 例如SSTP的自动更新Script.
作者: gfx86674    時間: 2015-1-13 17:45

本帖最後由 gfx86674 於 2015-1-13 18:09 編輯
有没有其他VPN 例如SSTP的自动更新Script.
yiucsw 發表於 2015-1-13 17:25

自動從address-list挑選筑波大學的SSTP-Server, 若是伺服器無法使用休息2小時後再重新連接.


作者: yiucsw    時間: 2015-1-13 19:02

今晚试试
作者: yiucsw    時間: 2015-1-13 19:06

回復 8# gfx86674

在中国移动宽带,PPTP 被block. 所有只能用其他。SSTP/openvpn 等。现在试SSTP。
作者: gfx86674    時間: 2015-1-13 19:24

回復  gfx86674

在中国移动宽带,PPTP 被block. 所有只能用其他。SSTP/openvpn 等。现在试SSTP。 ...
yiucsw 發表於 2015-1-13 19:06

若要引用我編輯的腳本,先注意名稱與Script對應的內容!!



圈起來的24 28 代表抓取address-list註解內的24~28符號 ,
也就是sstp-vpn port號.

若您的環境不同 ,部份內容也要跟著做修正!!
作者: yiucsw    時間: 2015-1-26 23:56

我刚买多一个RB951,变成(2 X SSTP client (RB2011) 对 1 X RB2011 Server +1 X RB951 Server.
想用你的Script 但发现下载不了。可以Upload AS Text format 吗?
我的想法比较简单。Load Balance 2 SSTP channel by address list。 要是一条SSTP 断开,用IP  route 的将另一个都route 到没有问题的SSTP tunnel?
还是有其他的建议?
作者: gfx86674    時間: 2015-1-29 19:11

回復 12# yiucsw
前幾天小弟用兩台Rb450g的GRE功能建site to site,很讚

只要設定interface/address/route/nat就好,很容易。
不會像pptp/l2tp/sstp/ovpn 這些site to sito建立後,除route/nat外,
sever to client還得需編寫script自動修改nat腳本。

免得vpn斷線重接的過程,server這邊nat的out-interface會從原本設定的名稱,變為unknow發生錯誤。
作者: yiucsw    時間: 2015-1-29 23:28

GRE 不是在中国不能用吗?我尝试一下。有没有Screen Capture. 可以跟一下
作者: yiucsw    時間: 2015-1-29 23:39

peer IP 是什么?现在我的SSTP连到Server 是用DDNS。GRE可以一样吗。
在Client (中国) 是没有Public IP address. 好像缺了一点。
作者: yiucsw    時間: 2015-1-31 17:18

回復 8# gfx86674

我发现SSTP Dynamic interface 常常自动启动。所有的Firewall Rule 变得有问题。
[attach]3445[/attach][attach]3445[/attach]

想自动disable Dynamic, 不知道如何写Script,以下的script 有什么问题。在CLI 打find name="<sstp-hksstp>" 没有Return.
if ([/interface sstp-server get [find name="<sstp-hksstp>"] running]=true) \
do=(/interface sstp-server disable [find name="<sstp-hksstp>"])
作者: yiucsw    時間: 2015-2-1 11:13

没法找到/interface sstp-server get XXX running 的 Status.最终是以下的Script。
每5分钟看到dynamic Interface, 便Remove 一次。static interface 便会连接。
/interface sstp-server remove [find name=<sstp-xxsstp>]

我猜主要原因是RB不Stable,太重的Workload 便会Reset一般分Resource。(BT 时发现)。Reset Resource 后SSTP 会连到Dynamic interface。所有要remove Dynamic interface.
作者: gfx86674    時間: 2015-2-2 01:02

本帖最後由 gfx86674 於 2015-2-2 01:04 編輯
回復  gfx86674

我发现SSTP Dynamic interface 常常自动启动。所有的Firewall Rule 变得有问题。


想自 ...
yiucsw 發表於 2015-1-31 17:18

您這何需用到Script ?
會出現<sstp-hksstp> 代表遠端連進您本地的hksstp帳號 ,
您把hksstp帳號給關了遠端自然連不進來,自然不會有<sstp-hksstp>

另外srcipt的:if ()是判斷true 才會run do={}
像running的真/否 本身即true/false.
所以:if ([/interface sstp-server get [find name="<sstp-hksstp>"] running]=true) \
do=(/interface sstp-server disable [find name="<sstp-hksstp>"])
語法是正確的,但您可以省略 running]=true ,直接
:if ([/interface sstp-server get [find name="<sstp-hksstp>"] running]) \
do=(........)
即可.

假如是希望running]=false
:if (![/interface sstp-server get [find name="<sstp-hksstp>"] running]) \
do=(........)

前面加個"!"就可以了
作者: yiucsw    時間: 2015-2-2 08:55

回復 18# gfx86674

hksstp 是Static/Dynamic sstp 帐号。 不知道如何只删掉动态的帐号?
作者: yiucsw    時間: 2015-2-2 08:58

:if ([/interface sstp-server get [find name="<sstp-hksstp>"] running]) \
do=(........)

好像 get 没有 Status 回来,如何了解Get 有没有Return?
作者: gfx86674    時間: 2015-2-2 11:35

本帖最後由 gfx86674 於 2015-2-2 11:57 編輯
回復  gfx86674

hksstp 是Static/Dynamic sstp 帐号。 不知道如何只删掉动态的帐号? ...
yiucsw 發表於 2015-2-2 08:55

那有所謂的固定/浮動帳號?
出現<名稱>這是別人透過你開放的sstp帳號進入Route主機的,
只要你關閉帳號或變更密碼,對方進得了主機嗎?
作者: yiucsw    時間: 2015-2-2 12:33

从以下的文本看到的。 静态/动态的 Interface 的用户名是一样的。都在PPP内设定的。我是 Site to Site 的 SSTP。 通过Server 的Interface 回到中国的Client。

http://wiki.mikrotik.com/wiki/Ma ... P#Site-to-Site_SSTP
SSTP Server
Sub-menu: /interface sstp-server
This sub-menu shows interfaces for each connected SSTP client.
An interface is created for each tunnel established to the given server. There are two types of interfaces in SSTP server's configuration
Static interfaces are added administratively if there is a need to reference the particular interface name (in firewall rules or elsewhere) created for the particular user.
Dynamic interfaces are added to this list automatically whenever a user is connected and its username does not match any existing static entry (or in case the entry is active already, as there can not be two separate tunnel interfaces referenced by the same name).
Dynamic interfaces appear when a user connects and disappear once the user disconnects, so it is impossible to reference the tunnel created for that use in router configuration (for example, in firewall), so if you need a persistent rules for that user, create a static entry for him/her. Otherwise it is safe to use dynamic configuration.
作者: fems    時間: 2015-2-4 04:52

本帖最後由 fems 於 2015-2-4 04:54 編輯
我的想法比较简单。Load Balance 2 SSTP channel by address list。 要是一条SSTP 断开,用IP  route 的将另一个都route 到没有问题的SSTP tunnel?  ...
yiucsw 發表於 2015-1-26 23:56


简单点增加备份route就可以了,仅供参考:
http://forum.mikrotik.com/viewto ... p;hilit=PCC#p452395
作者: czjlj    時間: 2015-2-9 10:37

请问楼主能放出脚本吗,这个是图片啊,非常感谢!
作者: yiucsw    時間: 2015-2-9 17:22

回復 23# fems


    现在是将unblockIPlist 来分,现在想改Interface有问题是Route 的第二Interface。还有没有时间做。
作者: yiucsw    時間: 2015-6-29 06:41

刚上多一条Broadband (中国电信)线。现在是一条中国移动宽带(ADSL)加一条中国电信(ADSL)。在RB如何Setup?
要是加了SSTP, 如何LoadBalance?
作者: gfx86674    時間: 2015-6-29 10:35

本帖最後由 gfx86674 於 2015-6-29 10:42 編輯
刚上多一条Broadband (中国电信)线。现在是一条中国移动宽带(ADSL)加一条中国电信(ADSL)。在RB如何Set ...
yiucsw 發表於 2015-6-29 06:41

在設定之前您要思考中國移動寬帶 與中國電信 這兩個通道,
只允許一個從外面進入,還是兩個都開放?
如VPN連入,是開放中國移動寬帶 當入口;還是中國電信 ? 還是兩者皆可?

連接ADSL所設置PPPoE,算是PPP工具的一份子.
所以等於Router內有三個連線隧道,分別是 中國移動寬帶/中國電信/sstp
不曉得您做LoadBalance時 ,是只考慮 中國移動寬帶/中國電信 ;還是把sstp也納進去?

另外您有開放web-proxy給外地用戶使用嗎?
若沒開放,您只需做內部DHCP用戶的LoadBalance即可;

若有使用web-proxy ,則LoadBalance還必需考量Router ,
這樣web-proxy用戶連接時 ,Router才會做LoadBalance .

或許您會問為何LoadBalance需區分DHCP用戶與Router ??
這與路由判斷有關:
[attach]3623[/attach]

您從圖表中看到封包進入,從第一次路由判斷後被區分成路徑A 與路徑B.
DHCP用戶即路徑B ,Router即路徑A ...所以這兩個規劃是不同的.

平常用戶只需做路徑B即可看到LoadBalance的效果 ;

但使用web-proxy時,因為是Router先連接處理,再將封包轉送代理用戶.
所以這時您就必須思考除DHCP用戶外 ,路徑A (Router)是否也得做LoadBalance.
作者: 雯雯    時間: 2015-6-29 16:53

回復 26# yiucsw

中國移動好像沒有真IP吧? 但是中國移動出海較快.
作者: yiucsw    時間: 2015-6-29 17:35

回復 27# gfx86674

现在已有VPN,中国移动打入。有两个问题所有加中国电信宽带:1)DNS/HTTP - 中国移动Block太多DNS,HTTP 地址。2)不稳定,在本地都常常断线。

现在想
是中国电信有路由猫,分两条Network 到RB Router同TV Box。
是中国移动,PPOE连到RB。
SSTP 是打出。
作者: yiucsw    時間: 2015-6-29 17:36

主要是 Load Balance SSTP。
同用中国电信的DNS
中国电信 是 12M, 中国移动是20M
作者: gfx86674    時間: 2015-6-30 02:09

本帖最後由 gfx86674 於 2015-6-30 02:23 編輯
回復  yiucsw
1)DNS/HTTP - 中國移動Block太多DNS,HTTP 地址。
2)不穩定,在本地都常常斷線。
3)中國移動,PPOE連到RB
4)SSTP 是打出
yiucsw 發表於 2015-6-29 17:35

[attach]3633[/attach]

1)firewall filter過濾:
udp port:53
/ip firewall filter
add action=drop chain=input  dst-port=53 protocol=udp  src-address-list=!All-Lan

tcp port:80
/ip firewall filter
add action=drop chain=input  dst-port=80 protocol=tcp src-address-list=!All-Lan
add action=drop chain=forward  dst-port=80 protocol=tcp src-address-list=!All-Lan

2)透過1 ,問題即迎刃而解.

3 )
PPPoE:
[attach]3629[/attach]
中國移動全不勾選 ;中國電信 "只勾選Use Peer DNS"

/ip dhcp-server network
[attach]3630[/attach]

/ip route 新增:
[attach]3631[/attach]

/ip dns
[attach]3632[/attach]
完成後將是以中國移動為主的路由 ;DNS則是使用中國電信

4)若3是使用中國移動為第一路由 ,SSTP則當然是用中國移動撥出 ;
若是用中國電信 ,則自然由中國電信撥出
作者: yiucsw    時間: 2015-6-30 11:37

这是网络架构图:
[attach]3634[/attach]
对不起,还没有用过双线。是两条宽带线一起连到Ethernet1,Ethernet2?然后如何?
主要的问题是已经有Policy Route, 如何加双线支持。
1)RB3 用中国电信DNS为主DNS。
2)RB3 打出SSTP到RB1/RB2, 主要用途:在中国端:用中国移动上传数据(优酷)数据到SSTP。用中国电信下载数据到SSTP。中国移动上传的速度快。
作者: yiucsw    時間: 2016-4-11 23:46

回復 8# gfx86674

主要是用Netwatch 看看SSTP的Server 是不是能Ping到。要是不能Ping到,而SSTP-Client 是running,/System Reboot, 要是
SSTP-Client是 SSTP-Client 不是Running, reset SSTP-Client.

想优化以下的Script:
1)我有两个SSTP Link,hksstp & nowsstp, 要是两个都Down,才System reboot,还有Reboot 后还有不运行能Delay 10分钟,再REboot.
2)现在的SSTP name 同 192.168.83.1 是没有联系的。能用 192.168.83.1 找回hksstp,减少hard code 的depend.

/tool netwatch
add down-script=":log info \"cn down\"" host=192.168.83.1 up-script=":log info \"cn up\"" interval=1m timeout=3s

## reset sstp client down
:if ([/interface sstp-client get hksstp-out1 running]=true)
do={:delay 60; /system reboot} else={:log warning "sstp-out1 NOT running";
:interface sstp-client disable sstp-out;
:delay 10;
:interface sstp-client enable sstp-out;};
作者: gfx86674    時間: 2016-4-12 01:01

回復  gfx86674

主要是用Netwatch 看看SSTP的Server 是不是能Ping到。要是不能Ping到,而SSTP-Client 是r ...
yiucsw 發表於 2016-4-11 23:46
修正:
  1. ## reset sstp client down
  2. :if (![/interface sstp-client get [find name=hksstp-out1] running] \
  3.          && ![/interface sstp-client get [find name=nowsstp-out1] running]) \
  4.     do={
  5.            :delay 1m
  6.            :if (![/interface sstp-client get [find name=hksstp-out1] running] \
  7.                     && ![/interface sstp-client get [find name=nowsstp-out1] running]) \
  8.                do={
  9.                       /system reboot
  10.                      } \
  11.                else={
  12.                         /interface sstp-client disable [find running=no]
  13.                         /interface sstp-client enable [find running=no]
  14.                        }
  15.           }\
  16.     else={
  17.              /interface sstp-client disable [find running=no]
  18.              /interface sstp-client enable [find running=no]
  19.             }
複製代碼

作者: yiucsw    時間: 2016-4-12 10:33

谢谢。初步测试没有问题。

/tool netwatch
add down-script=vpndown host=192.168.8X.1 interval=5m timeout=3s up-script=\
    ":log info \"HKY up\""
add down-script=vpndown host=192.168.18X.1 interval=5m timeout=3s up-script=\
    ":log info \"HKW up\""

还没有测试System Reboot.
作者: yiucsw    時間: 2016-4-13 08:49

回復 34# gfx86674

有点逻辑的问题。在中国PPPOE启动慢,SSTP 没有办法Resolve name. 有什么办法解决?
01:25:43 system,info verified routeros-mipsbe-6.31.npk
01:25:45 system,warning omitting package routeros-mipsbe-6.31: newer package router
os-mipsbe-6.35rc48 is already installed
01:25:51 pppoe,ppp,info pppoe-out1: initializing...
01:25:51 pppoe,ppp,info pppoe-out1: connecting...
01:25:51 sstp,ppp,info HKWXsstp-out1: initializing...
01:25:51 sstp,ppp,info HKWXsstp-out1: connecting...
01:25:51 sstp,ppp,info HKNXsstp-out1: initializing...
01:25:51 sstp,ppp,info HKNXsstp-out1: connecting...
01:25:51 sstp,ppp,info HKYXsstp-out1: initializing...
01:25:51 sstp,ppp,info HKYXsstp-out1: connecting...
01:26:01 pppoe,ppp,info pppoe-out1: terminating... - disconnected
01:26:01 pppoe,ppp,info pppoe-out1: disconnected
01:26:01 pppoe,ppp,info pppoe-out1: initializing...
01:26:01 pppoe,ppp,info pppoe-out1: connecting...
01:26:01 sstp,ppp,info HKNXsstp-out1: terminating... - could not resolve name
01:26:01 sstp,ppp,info HKNXsstp-out1: disconnected
01:26:01 sstp,ppp,info HKNXsstp-out1: initializing...
01:26:01 sstp,ppp,info HKNXsstp-out1: connecting...
01:26:01 sstp,ppp,info HKWXsstp-out1: terminating... - could not resolve name
01:26:01 sstp,ppp,info HKWXsstp-out1: disconnected
01:26:01 sstp,ppp,info HKWXsstp-out1: initializing...
01:26:01 sstp,ppp,info HKWXsstp-out1: connecting...
01:26:01 sstp,ppp,info HKYXsstp-out1: terminating... - could not resolve name
01:26:01 sstp,ppp,info HKYXsstp-out1: disconnected
01:26:01 sstp,ppp,info HKYXsstp-out1: initializing...
01:26:01 sstp,ppp,info HKYXsstp-out1: connecting...
01:26:10 pppoe,ppp,info pppoe-out1: terminating... - disconnected
01:26:10 pppoe,ppp,info pppoe-out1: disconnected
01:26:11 pppoe,ppp,info pppoe-out1: initializing...
01:26:11 pppoe,ppp,info pppoe-out1: connecting...
01:26:11 sstp,ppp,info HKYXsstp-out1: terminating... - could not resolve name
01:26:11 sstp,ppp,info HKYXsstp-out1: disconnected
01:26:11 sstp,ppp,info HKWXsstp-out1: terminating... - could not resolve name
作者: gfx86674    時間: 2016-4-13 09:38

本帖最後由 gfx86674 於 2016-4-14 09:52 編輯
回復  gfx86674

有点逻辑的问题。在中国PPPOE启动慢,SSTP 没有办法Resolve name. 有什么办法解决?
01:2 ...
yiucsw 發表於 2016-4-13 08:49
外圍再加一層pppoe-out1判斷,等pppoe-out1上線後,script才開始.
  1. :if ([/interface pppoe-client get [find name=pppoe-out1] running]) \
  2.     do={
  3.         ## reset sstp client down
  4.         :if (![/interface sstp-client get [find name=hksstp-out1] running] \
  5.              && ![/interface sstp-client get [find name=nowsstp-out1] running]) \
  6.             do={
  7.                 :delay 1m
  8.                 :if (![/interface sstp-client get [find name=hksstp-out1] running] \
  9.                       && ![/interface sstp-client get [find name=nowsstp-out1] running]) \
  10.                     do={
  11.                         /system reboot
  12.                        } \
  13.                     else={
  14.                           /interface sstp-client disable [find running=no]
  15.                           /interface sstp-client enable [find running=no]
  16.                          }
  17.                }\
  18.             else={
  19.                   /interface sstp-client disable [find running=no]
  20.                   /interface sstp-client enable [find running=no]
  21.                  }
  22.        }
複製代碼

作者: yiucsw    時間: 2016-4-14 09:36

pptp-client 是 pppoe-client ?
作者: gfx86674    時間: 2016-4-14 09:53

pptp-client 是 pppoe-client ?
yiucsw 發表於 2016-4-14 09:36
打錯字了,是pppoe-client
已更正~




歡迎光臨 電訊茶室 (http://telecom-cafe.com/forum/) Powered by Discuz! 7.2