一月 17

在RouterOS中,如果你有使用PPTP VPN連線的話,然後撥接的位置又是不固定IP

那麼你就會遇到這個問題

第一次的時候是可以撥接成功的,但後面因為IP變了,接下來你就撥接不上去了

如果用winbox這個工具進去管理RouterOS,你會發現要連到那一台主機那邊,可以打Domain Name

不過很抱歉,你儲存的時候winbox會把你的Domain Name轉成IP

所以說,就算你的Domain Name內的解析有變了,RouterOS還是不知道新的IP

這時候就需要一個固定更新的的Script來解決問題

流程很簡單:
1.找出目前RouterOS使用中的PPTP IP
2.反解相關Domain Name的IP
3.如果不一樣,就更新

相關的Script如下,請享用。相關說明看一下註解,應該不難

有問題的話再詢問吧

#Script在RouterOS 4.4中測試通過
#Date:2010/01/17
#Script Name:自動更新Domain Name的IP到PPTP的位置

#要設定的PPTP撥接名稱
:local pptpName "PPTP_Home"
#要撥接的DoaminName
:local pptpDomainName "xxxx.minitw.com"
#取得目前的撥接IP
:local systemPPTPIP [/interface pptp-client get $pptpName connect-to ]
#經由DNS取得新的PPTP Server IP
:local currentPPTPIP [:resolve $pptpDomainName]

:if ($systemPPTPIP != $currentPPTPIP) do={
    /interface pptp-client set $pptpName connect-to=$currentPPTPIP
    :log info "PPTP_DNS_Update: $currentPPTPIP (CHT:更新PPTP的DomainIP)"
}




七月 17

如果你於RouterOS中使用負載平衡時,你會發現要從RapidShare下載檔案有很大的機會失敗

這是因為當你第1次連到RapidShare上的IP,然後等完看廣告的時間之後要下載檔案的IP不一樣所造成的

舉個例來說,假設第1次連上到RapidShare上的IP是123.1.1.1,但是要下載檔案時

因為負載平衡的關係,使得本次連到RapidShare 的已經變成123.1.1.2

這時就會發生無法下載的情況。

最簡單的解決方式就是,把要連到RapidShare上的連線全部走同1條線路

那麼要怎麼判斷那些連線是要到RapidShare的呢

就是看RouterOS DNS快取裡的Doman與IP的對照表

這個時候就需要使用Script來自動把RapidShare相關的IP濾出來,放到Address List供我們使用

相關的Script如下。新增Script的方式為到Winbox裡 System -> Scripts -> 按介面上的 +

把下面這個Script命名為 Update_RapidShare_IP ,後面會用到

# 把DNS快取裡資料全部讀出來
:foreach i in=[/ip dns cache find] do={
    :local bNew "true";
# 檢查DNS快取裡是否有包含rapidshare的關鍵字
    :if ([:find [/ip dns cache get $i name] "rapidshare"] != 0) do={
        :local tmpAddress [/ip dns cache get $i address] ;

# 轉換rapidshare的IP到"/16"的網段
        :local mjesto ([:find $tmpAddress "."]);
        :set mjesto ([:find $tmpAddress "." $mjesto]);
        :local tmpAddress ([:pick $tmpAddress 0 $mjesto]);
        :set tmpAddress ($tmpAddress . ".0.0/16");

#---- 如果address list是空的就不用查檢了(直接把IP加入)
        :if ( [/ip firewall address-list find ] = "") do={
            /ip firewall address-list add address=$tmpAddress list=RapidShare_IP disabled=no;
        } else={
#------- 檢查每一列的值
            :foreach j in=[/ip firewall address-list find ] do={
#---------- 如果IP已經存在address list就不用新增了
                :if ( [/ip firewall address-list get $j address] = $tmpAddress ) do={
                    :set bNew "false";
                }
            }
#------- 如果IP不存在就新增一筆上去address list
            :if ( $bNew = "true" ) do={
                /ip firewall address-list add address=$tmpAddress list=RapidShare_IP disabled=no
            }
        }
    }
}

接下來則是設定每30秒自動執行1次(相關設定如圖所示),隨時更新

System -> Scheduler -> 按介面上的 +

把這個 Scheduler 命名為 Auto_Update_RapidShare_IP

/system script run Update_RapidShare_IP

最後一個步驟就是判斷只要目的位置是在RapidShare_IP這個Address List裡的話

就強迫走單一路由。怎麼設定就因人而異了,不過大方向是不變的

有了RapidShare的相關IP,要針對RapidShare做限速、擋掉....等,都很方便了

相關參考資料:
Fight against P2P on port 80





六月 24

要在RouterOS上實作QoS是不難的

實作之前首先要先知道什麼是PCQ (Per Connection Queue)

說的白話一點,PCQ就是一個最佳化後的QoS系統

如果你對PCQ的詳細技後有興趣可以到這邊觀看技術文件

強烈建議一定要去看一下PCQ的技術文件,裡面有很多很好的觀念

如果要實作PCQ可以參考這篇文章PCQ Examples

如果你有在RouterOS上啟用Web-Proxy,而且要使用PCQ的話請參考
Queue with Masquerading and Internal Web-Proxy

0

PCQ除了可以實作一般的限流外,也可以配合Burst這個參數來讓網頁開啟更順暢

怎麼說呢?我舉個例子:

假設我們想讓使用者下載檔案時速度限制在10KB/s,但是如果連開網頁也限制在10KB/s,豈不是等到瘋掉。

這時候Burst這個參數就派上用場了。我們知道一般網頁的檔案都很小,下載不需要花費很多時間。而一般的檔案都很大,下載需要花很多時間。

這時候我們是不是可以多一個功能,在一開始的時候速度限制在50KB,

但是如果這個連線一直持續下載超過5MB時,就開始限速10KB/s,該怎麼做呢?就是用前面所說的Burst參數

在RouterOS中Winbox的介面如下

其中Queue Type 的設定如下圖示所

如果你需要更詳細的PCQ參數設定,可以參考這份文件 MikroTik RouterOS Workshop QoS Best Practice

20101114_1

0

這邊補充說明一下~~RouterOS裡 1M bits/s = 1,000,000 bits/s = 125,000 Bytes/s = 122KB/s

Max Limit :常態時的速度限制

Burst Limit:瞬時的最高速度限制

Burst Threshold:平均流量(需與Burst Time搭配使用)到達多少時開始停止使用Burst Limit

以上面這張圖片的設定檔來做說明的話

****************************************************************
一開始流量可以衝到4M bits/s

但是如果流量維持在 1Mbits/s 以上,而且在5秒內下載量達到 610KB (1M bits/s * 5)時

就停止使用Burst Limit而開始啟用Max Limit,此後速度會一直限速在2M bits/s
****************************************************************

以圖片來說明的話,流量會像下面的圖一樣

綠色的線就是使用者可以感受到的網路速度





六月 03

首先先說明一下實做的環境,如下圖

要在 RouterOS 中實現多條 ADSL 負載平衡與自動備援並不困難

但是主要的問題會是 ADSL 的 閘道(Gateway),都是同一個位置(假設是同一家ISP)

要解決這個問題必需使用 Mangle 裡的標記(mark) 且配合 nth,請看以下範例

使用 Mangle 裡的標記(mark) 且配合 nth 可以解決ADSL 負載平衡的問題。

而自動備援的問題,則是在 NAT 裡加入一行不指定條件的 masquerade 即可(需放置於正常有指定條件masquerade的後面)

設定檔的使用方式很簡單,先在 Winbox 的左邊點選 New Terminal

然後把下面的設定檔貼上就可以了


#以下設定檔在 RouterOS 3.20 下測試通過

/interface pppoe-client
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment=\
"" dial-on-demand=no disabled=no interface=掛載ADSL-1的網卡 max-mru=1480 max-mtu=1480 \
mrru=disabled name=ADSL-1 password=ADSL-1密碼 profile=default service-name="" \
use-peer-dns=yes user=ADSL-1帳號
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment=\
"" dial-on-demand=no disabled=no interface=掛載ADSL-2的網卡 max-mru=1480 max-mtu=1480 \
mrru=disabled name=ADSL-2 password=ADSL-2密碼 profile=default service-name="" \
use-peer-dns=yes user=ADSL-2帳號

/ip firewall mangle
#讓外部可以連通本機多條 ADSL
add action=mark-connection chain=input comment=\
"\C5\FD\A5~\B3\A1\A5i\A5H\B3s\B3q\A5\BB\BE\F7\A6h\B1\F8 ADSL" disabled=no \
in-interface=ADSL-1 new-connection-mark=from_adsl_1 passthrough=yes
add action=mark-routing chain=output comment="" connection-mark=from_adsl_1 \
disabled=no new-routing-mark=to_adsl_1 passthrough=yes
add action=mark-connection chain=input comment="" disabled=no in-interface=\
ADSL-2 new-connection-mark=from_adsl_2 passthrough=yes
add action=mark-routing chain=output comment="" connection-mark=from_adsl_2 \
disabled=no new-routing-mark=to_adsl_2 passthrough=yes

#內部網路負載平衡
add action=mark-connection chain=prerouting comment=\
"\A4\BA\B3\A1\BA\F4\B8\F4\ADt\B8\FC\A5\AD\BF\C5" connection-state=new \
disabled=no in-interface=請改成你的內部網卡 new-connection-mark=nth_1 nth=2,1 \
passthrough=yes
add action=mark-routing chain=prerouting comment="" connection-mark=nth_1 \
disabled=no in-interface=請改成你的內部網卡 new-routing-mark=to_adsl_1 passthrough=no
add action=mark-connection chain=prerouting comment="" connection-state=new \
disabled=no in-interface=請改成你的內部網卡 new-connection-mark=nth_2 passthrough=yes
add action=mark-routing chain=prerouting comment="" connection-mark=nth_2 \
disabled=no in-interface=請改成你的內部網卡 new-routing-mark=to_adsl_2 passthrough=no

/ip firewall nat
#線路正常時,依負載平衡走不一樣的 ADSL 線路出去
add action=masquerade chain=srcnat comment="\BDu\B8\F4\A5\BF\B1`\AE\C9\A1A\A8\
\CC\ADt\B8\FC\A5\AD\BF\C5\A8\AB\A4\A3\A4@\BC\CB\AA\BA ADSL \BDu\B8\F4\A5X\
\A5h" disabled=no out-interface=ADSL-1 routing-mark=to_adsl_1
add action=masquerade chain=srcnat comment="" disabled=no out-interface=\
ADSL-2 routing-mark=to_adsl_2

#ADSL 斷線自動備援
add action=masquerade chain=srcnat comment=\
"ADSL \C2_\BDu\A6\DB\B0\CA\B3\C6\B4\A9" disabled=no

/ip route
#設定 ADSL 路由
add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ADSL-1 \
routing-mark=to_adsl_1
add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ADSL-2 \
routing-mark=to_adsl_2
add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=\
ADSL-1,ADSL-2

/ip route print




四月 06

top 是一個在 linux 中監看系統狀況的指令

要在 RouterOS 3.x 中加入top,首先請先下載這個封裝檔 (原作者:ksw520)

如果還沒把 RouterOS 的 ftp 功能打開,先到 IP -> Service 把 ftp 開啟

解開壓縮後利用 ftp 把 procps3.x.npk 丟到RouterOS 上去

重新啟動 RouterOS ,就會自動安裝了

接下來使用 pietty 或 putty 來連線

IP:RouterOS 的位置

Port:12345

帳號:metro

密碼:2911911

進去後可用 top 指令來監看系統狀況

如果要改密碼,輸入 password 就可以改密碼了

參考資料:ros下的top命令補丁