Mikrotik RouterOS 上的 Multivan 和路由

介紹

撰寫這篇文章,除了虛榮心之外,是由於在俄語電報社區的個人資料組中關於該主題的問題頻率令人沮喪。 文章面向Mikrotik RouterOS(以下簡稱ROS)管理員新手。 它只處理多廂貨車,重點是路由。 作為獎勵,有足夠的設置來確保安全和方便的操作。 那些正在尋找隊列、負載平衡、vlan、網橋、通道狀態的多階段深度分析等主題的披露的人 - 可能不會浪費時間和精力閱讀。

初始數據

作為測試對象,選擇了具有 ROS 版本 6.45.3 的五端口 Mikrotik 路由器。 它將在兩個本地網絡(LAN1 和 LAN2)和三個提供商(ISP1、ISP2、ISP3)之間路由流量。 ISP1 的通道有一個靜態的“灰色”地址,ISP2 - “白色”,通過 DHCP 獲得,ISP3 - “白色”,具有 PPPoE 授權。 連接圖如圖所示:

Mikrotik RouterOS 上的 Multivan 和路由

任務是根據方案配置 MTK 路由器,以便:

  1. 提供到備份提供商的自動切換。 主要提供者是ISP2,第一儲備是ISP1,第二儲備是ISP3。
  2. 組織LAN1網絡只能通過ISP1訪問Internet。
  3. 提供通過基於地址列表的選定提供商將流量從本地網絡路由到 Internet 的能力。
  4. 提供從本地網絡發布服務到互聯網的可能性(DSTNAT)
  5. 設置防火牆過濾器以提供來自 Internet 的最低限度的安全性。
  6. 路由器可以通過三個提供商中的任何一個發出自己的流量,具體取決於所選的源地址。
  7. 確保響應數據包被路由到它們來自的通道(包括 LAN)。

評論。 我們將“從頭開始”配置路由器,以保證“開箱即用”的起始配置不會因版本而異。 選擇 Winbox 作為配置工具,其中的更改將直觀地顯示出來。 設置本身將由 Winbox 終端中的命令設置。 用於配置的物理連接是通過直接連接到 Ether5 接口來實現的。

關於什麼是多貨車的一些推理,這是一個問題還是圍繞編織陰謀網絡的狡猾聰明人

一個好奇而細心的管理員,自己設置了這樣或類似的方案,突然發現它已經在正常工作了。 是的,是的,沒有你的自定義路由表和其他路由規則,大多數關於這個主題的文章都充滿了這些。 讓我們檢查?

我們可以在接口和默認網關上配置尋址嗎? 是的:

在 ISP1 上,地址和網關已註冊 距離=2 и 檢查網關=平。
在 ISP2 上,默認的 dhcp 客戶端設置 - 因此,距離將等於 XNUMX。
在ISP3的pppoe客戶端設置時 添加默認路由=是默認路由距離=3.

不要忘記在出口處註冊 NAT:

/ip 防火牆 nat add 操作=偽裝鏈=srcnat out-interface-list=WAN

結果,本地站點的用戶通過主要的 ISP2 提供商下載貓很有趣,並且使用該機制進行了頻道預訂 檢查網關 見註 1

任務的第 1 點已實施。 帶有標記的多功能貨車在哪裡? 不…

更遠。 您需要通過 ISP1 從 LAN 中釋放特定客戶端:

/ip 防火牆 mangle 添加操作=路由鏈=預路由 dst-address-list=!BOGONS
直通=是 route-dst=100.66.66.1 src-address-list=Via_ISP1
/ip 防火牆 mangle 添加操作=路由鏈=預路由 dst-address-list=!BOGONS
passthrough=無路由-dst=100.66.66.1 src-address=192.168.88.0/24

任務的第 2 項和第 3 項已經實施。 標籤、郵票、路線規則,你在哪裡?!

需要為來自 Internet 的客戶端訪問地址為 172.17.17.17 的您最喜歡的 OpenVPN 服務器? 請:

/ip 雲設置 ddns-enabled=yes

作為同行,我們給客戶端輸出結果:“:put [ip 雲獲取 dns 名稱]

我們從網上註冊端口轉發:

/ip 防火牆 nat 添加操作=dst-nat 鏈=dstnat dst-端口=1194
in-interface-list=WAN 協議=udp 到地址=172.17.17.17

項目 4 已準備就緒。

我們為第 5 點設置了防火牆和其他安全措施,與此同時,我們很高興一切都已經為用戶工作,並拿到裝有最喜歡飲料的容器......
A! 隧道被遺忘了。

google文章配置的l2tp-client,已經上升到你喜歡的Dutch VDS了嗎? 是的。
帶有 IPsec 的 l2tp 服務器已經上升,客戶端通過來自 IP 雲的 DNS 名稱(見上文)堅持? 是的。
我們靠在椅子上,喝著飲料,懶洋洋地思考任務的第 6 點和第 7 點。 我們認為 - 我們需要它嗎? 儘管如此,它還是像 (c) 那樣工作……因此,如果仍然不需要它,那就是它。 Multivan 實施。

什麼是多人貨車? 這是將多個 Internet 通道連接到一個路由器。

你不必進一步閱讀這篇文章,因為除了炫耀可疑的適用性之外還能有什麼?

對於那些留下來的人,他們對任務的第 6 點和第 7 點感興趣,並且也感到完美主義的渴望,我們將深入研究。

實施多廂貨車最重要的任務是正確的交通路線。 即:不管哪個(或哪個)見。 注意 3 ISP 的通道查看我們路由器上的默認路由,它應該返回對數據包來自的確切通道的響應。 任務很明確。 哪裡有問題? 事實上,在一個簡單的本地網絡中,任務是相同的,但沒有人會為額外的設置而煩惱,也不會感到麻煩。 不同之處在於,Internet 上的任何可路由節點都可以通過我們的每個通道訪問,而不是像在簡單的 LAN 中那樣通過嚴格特定的通道訪問。 而“麻煩”是,如果向我們請求 ISP3 的 IP 地址,那麼在我們的例子中,答案將通過 ISP2 通道,因為默認網關指向那裡。 離開並將被提供商丟棄為不正確。 問題已確定。 如何解決?

解決方案分為三個階段:

  1. 預設。 這個階段會設置路由器的基本設置:本地網絡、防火牆、地址列表、髮夾NAT等。
  2. 多貨車。 在此階段,必要的連接將被標記並分類到路由表中。
  3. 連接到 ISP。 在此階段,將配置提供到 Internet 連接的接口,將激活路由和 Internet 信道保留機制。

1. 預設

1.1. 我們使用以下命令清除路由器配置:

/system reset-configuration skip-backup=yes no-defaults=yes

同意 ”危險的! 還是重置? [是/否]:”,並且在重新啟動後,我們通過 MAC 連接到 Winbox。 在此階段,清除配置和用戶群。

1.2. 創建新用戶:

/user add group=full name=knight password=ultrasecret comment=”Not horse”

在其下登錄,刪除默認的:

/user remove admin

評論。 作者認為更安全並推薦使用的是刪除而不是禁用默認用戶。

1.3. 我們創建了基本的接口列表,以便於在防火牆、發現設置和其他 MAC 服務器中進行操作:

/interface list add name=WAN comment="For Internet"
/interface list add name=LAN comment="For Local Area"

使用註釋簽署接口

/interface ethernet set ether1 comment="to ISP1"
/interface ethernet set ether2 comment="to ISP2"
/interface ethernet set ether3 comment="to ISP3"
/interface ethernet set ether4 comment="to LAN1"
/interface ethernet set ether5 comment="to LAN2"

並填寫接口列表:

/interface list member add interface=ether1 list=WAN comment=ISP1
/interface list member add interface=ether2 list=WAN comment=ISP2 
/interface list member add interface=ether3 list=WAN comment="to ISP3"
/interface list member add interface=ether4 list=LAN  comment="LAN1"
/interface list member add interface=ether5 list=LAN  comment="LAN2"

評論。 編寫易於理解的註釋是值得花時間在這上面的,而且它極大地促進了故障排除和理解配置。

出於安全原因,作者認為有必要將 ether3 接口添加到“WAN”接口列表中,儘管 ip 協議不會通過它。

不要忘記在ether3 上提升PPP 接口後,還需要將其添加到接口列表“WAN”中

1.4. 我們通過 MAC 將路由器隱藏在提供商網絡的鄰居檢測和控制之外:

/ip neighbor discovery-settings set discover-interface-list=!WAN
/tool mac-server set allowed-interface-list=LAN
/tool mac-server mac-winbox set allowed-interface-list=LAN

1.5. 我們創建了最少的防火牆過濾規則集來保護路由器:

/ip firewall filter add action=accept chain=input comment="Related Established Untracked Allow" 
connection-state=established,related,untracked

(該規則為從連接的網絡和路由器本身發起的已建立和相關連接提供許可)

/ip firewall filter add action=accept chain=input comment="ICMP from ALL" protocol=icmp

(ping 而不僅僅是 ping。所有 icmp 都允許進入。對於查找 MTU 問題非常有用)

/ip firewall filter add action=drop chain=input comment="All other WAN Drop" in-interface-list=WAN

(關閉輸入鏈的規則禁止來自互聯網的所有其他內容)

/ip firewall filter add action=accept chain=forward 
comment="Established, Related, Untracked allow" 
connection-state=established,related,untracked

(該規則允許通過路由器的已建立和相關連接)

/ip firewall filter add action=drop chain=forward comment="Invalid drop" connection-state=invalid

(該規則通過路由器重置連接狀態=無效的連接。Mikrotik 強烈推薦,但在極少數情況下它會阻止有用的流量)

/ip firewall filter add action=drop chain=forward comment="Drop all from WAN not DSTNATed"  
connection-nat-state=!dstnat connection-state=new in-interface-list=WAN

(該規則禁止來自 Internet 且未通過 dstnat 程序的數據包通過路由器。這將保護本地網絡免受入侵者的侵害,入侵者與我們的外部網絡處於同一廣播域中,將我們的外部 IP 註冊為網關,從而嘗試“探索”我們的本地網絡。)

評論。 讓我們假設網絡 LAN1 和 LAN2 是可信的,並且它們之間和來自它們的流量未被過濾。

1.6. 創建一個包含不可路由網絡列表的列表:

/ip firewall address-list
add address=0.0.0.0/8 comment=""This" Network" list=BOGONS
add address=10.0.0.0/8 comment="Private-Use Networks" list=BOGONS
add address=100.64.0.0/10 comment="Shared Address Space. RFC 6598" list=BOGONS
add address=127.0.0.0/8 comment=Loopback list=BOGONS
add address=169.254.0.0/16 comment="Link Local" list=BOGONS
add address=172.16.0.0/12 comment="Private-Use Networks" list=BOGONS
add address=192.0.0.0/24 comment="IETF Protocol Assignments" list=BOGONS
add address=192.0.2.0/24 comment=TEST-NET-1 list=BOGONS
add address=192.168.0.0/16 comment="Private-Use Networks" list=BOGONS
add address=198.18.0.0/15 comment="Network Interconnect Device Benchmark Testing"
 list=BOGONS
add address=198.51.100.0/24 comment=TEST-NET-2 list=BOGONS
add address=203.0.113.0/24 comment=TEST-NET-3 list=BOGONS
add address=224.0.0.0/4 comment=Multicast list=BOGONS
add address=192.88.99.0/24 comment="6to4 Relay Anycast" list=BOGONS
add address=240.0.0.0/4 comment="Reserved for Future Use" list=BOGONS
add address=255.255.255.255 comment="Limited Broadcast" list=BOGONS

(這是無法路由到 Internet 的地址和網絡的列表,將相應地遵循。)

評論。 該列表可能會發生變化,因此我建議您定期檢查相關性。

1.7. 為路由器本身設置 DNS:

/ip dns set servers=1.1.1.1,8.8.8.8

評論。 在當前版本的 ROS 中,動態服務器優先於靜態服務器。 名稱解析請求按列表中的順序發送到第一個服務器。 噹噹前服務器不可用時,將執行到下一個服務器的轉換。 超時時間長 - 超過 5 秒。 返回,當“倒下的服務器”恢復時,不會自動發生。 鑑於此算法和 multivan 的存在,作者建議不要使用提供商提供的服務器。

1.8. 設置本地網絡。
1.8.1. 我們在 LAN 接口上配置靜態 IP 地址:

/ip address add interface=ether4 address=192.168.88.254/24 comment="LAN1 IP"
/ip address add interface=ether5 address=172.16.1.0/23 comment="LAN2 IP"

1.8.2. 我們通過主路由表設置到本地網絡的路由規則:

/ip route rule add dst-address=192.168.88.0/24 table=main comment=”to LAN1”
/ip route rule add dst-address=172.16.0.0/23 table=main comment="to LAN2"

評論。 這是使用不通過默認路由的路由器接口的外部 IP 地址源訪問 LAN 地址的快速簡便方法之一。

1.8.3. 為 LAN1 和 LAN2 啟用 Hairpin NAT:

/ip firewall nat add action=src-nat chain=srcnat comment="Hairpin to LAN1" 
out-interface=ether4 src-address=192.168.88.0/24 to-addresses=192.168.88.254
/ip firewall nat add action=src-nat chain=srcnat comment="Hairpin to LAN2" 
out-interface=ether5 src-address=172.16.0.0/23 to-addresses=172.16.1.0

評論。 這允許您在網絡內部時通過外部 IP 訪問您的資源 (dstnat)。

2.其實multivan的實現很正確

為了解決“answer where they asked from”的問題,我們將使用兩個 ROS 工具: 連接標記 и 路由標記. 連接標記 允許您標記所需的連接,然後使用此標籤作為應用的條件 路由標記. 並且已經有了 路由標記 可以工作 IP路由 и 路由規則. 我們找到了工具,現在您需要決定要標記哪些連接 - 一次,確切地標記在哪裡 - 兩次。

對於第一個,一切都很簡單 - 我們必須標記通過適當渠道從 Internet 到達路由器的所有連接。 在我們的例子中,這將是三個標籤(按通道數):“conn_isp1”、“conn_isp2”和“conn_isp3”。

第二個的細微差別是傳入連接將有兩種類型:傳輸和用於路由器本身的連接。 連接標記機制在表中工作 撕裂. 在簡化圖上考慮包的移動,由 mikrotik-trainings.com 資源(非廣告)的專家友情編譯:

Mikrotik RouterOS 上的 Multivan 和路由

沿著箭頭,我們看到數據包到達“輸入接口”,通過鏈條“預路由” 然後才在街區里分為中轉和本地“路由決定”。 因此,要用一塊石頭殺死兩隻鳥,我們使用 連接標記 在表中 破壞預路由 鏈條 預路由.

備註. 在 ROS 中,“Routing mark”標籤在 Ip/Routes/Rules 部分以“Table”形式列出,在其他部分以“Routing Mark”形式列出。 這可能會給理解帶來一些混亂,但實際上,這是一回事,是 linux 上 iproute2 中 rt_tables 的類比。

2.1. 我們標記來自每個提供商的傳入連接:

/ip firewall mangle add action=mark-connection chain=prerouting 
comment="Connmark in from ISP1" connection-mark=no-mark in-interface=ether1  new-connection-mark=conn_isp1 passthrough=no

/ip firewall mangle add action=mark-connection chain=prerouting 
comment="Connmark in from ISP2" connection-mark=no-mark in-interface=ether2  new-connection-mark=conn_isp2 passthrough=no

/ip firewall mangle add action=mark-connection chain=prerouting 
comment="Connmark in from ISP3" connection-mark=no-mark in-interface=pppoe-isp3  new-connection-mark=conn_isp3 passthrough=no

評論。 為了不標記已經標記的連接,我使用 connection-mark=no-mark 條件而不是 connection-state=new 因為我認為這樣更正確,以及在輸入過濾器中拒絕丟棄無效連接。


passthrough=no - 因為在這種實現方法中,重新標記被排除在外,為了加快速度,您可以在第一次匹配後中斷規則的枚舉。

應該記住,我們還沒有以任何方式乾擾路由。 現在只有準備階段。 下一實施階段將處理從本地網絡中的目的地通過已建立的連接返回的傳輸流量。 那些。 沿途通過路由器的那些數據包(參見圖表):

“Input Interface”=>“Prerouting”=>“Routing Decision”=>“Forward”=>“Post Routing”=>“Output Interface” 並到達本地網絡中的收件人。

重要的信息! 在 ROS 中,沒有外部接口和內部接口的邏輯劃分。 如果我們按照上圖追踪響應數據包的路徑,那麼它會遵循與請求相同的邏輯路徑:

“Input Interface”=>“Prerouting”=>“Routing Decision”=>“Forward”=>“Post Routing”=>“Output Interface” 只是為了一個請求”輸入接口”是 ISP 接口,答案是 LAN

2.2. 我們將響應傳輸流量定向到相應的路由表:

/ip firewall mangle add action=mark-routing chain=prerouting 
comment="Routemark transit out via ISP1" connection-mark=conn_isp1 
dst-address-type=!local in-interface-list=!WAN new-routing-mark=to_isp1 passthrough=no

/ip firewall mangle add action=mark-routing chain=prerouting 
comment="Routemark transit out via ISP2" connection-mark=conn_isp2 
dst-address-type=!local in-interface-list=!WAN new-routing-mark=to_isp2 passthrough=no

/ip firewall mangle add action=mark-routing chain=prerouting 
comment="Routemark transit out via ISP3" connection-mark=conn_isp3 
dst-address-type=!local in-interface-list=!WAN new-routing-mark=to_isp3 passthrough=no

評論。 in-interface-list=!WAN - 我們只處理來自本地網絡和 dst-address-type=!local 的流量,它沒有路由器本身接口地址的目標地址。

沿途到達路由器的本地數據包也是如此:

“輸入接口”=>“預路由”=>“路由決策”=>“輸入”=>“本地進程”

重要的信息! 答案將按以下方式進行:

”Local Process”=>”Routing Decision”=>”Output”=>”Post Routing”=>”Output Interface”

2.3. 我們將響應本地流量定向到相應的路由表:

/ip firewall mangle add action=mark-routing chain=output 
comment="Routemark local out via ISP1" connection-mark=conn_isp1 dst-address-type=!local 
new-routing-mark=to_isp1 passthrough=no

/ip firewall mangle add action=mark-routing chain=output 
comment="Routemark local out via ISP2" connection-mark=conn_isp2 dst-address-type=!local 
new-routing-mark=to_isp2 passthrough=no

/ip firewall mangle add action=mark-routing chain=output 
comment="Routemark local out via ISP3" connection-mark=conn_isp3 dst-address-type=!local 
new-routing-mark=to_isp3 passthrough=no

在這個階段,可以認為準備向發出請求的 Internet 通道發送響應的任務已經解決。 一切都被標記、標記並準備好被路由。
此設置的一個極好的“副作用”是能夠同時使用來自兩個(ISP2、ISP3)提供商的 DSNAT 端口轉發。 一點也不,因為在 ISP1 上我們有一個不可路由的地址。 這種影響很重要,例如,對於具有兩個查看不同 Internet 通道的 MX 的郵件服務器。

為了消除具有外部 IP 路由器的本地網絡運行的細微差別,我們使用段落中的解決方案。 1.8.2 和 3.1.2.6。

另外,你可以使用帶有標記的工具來解決第3段的問題。 我們這樣實現:

2.4. 我們將來自本地客戶端的流量從路由列表定向到適當的表:

/ip firewall mangle add action=mark-routing chain=prerouting 
comment="Address List via ISP1" dst-address-list=!BOGONS new-routing-mark=to_isp1 
passthrough=no src-address-list=Via_ISP1

/ip firewall mangle add action=mark-routing chain=prerouting 
comment="Address List via ISP2" dst-address-list=!BOGONS new-routing-mark=to_isp2 
passthrough=no src-address-list=Via_ISP2

/ip firewall mangle add action=mark-routing chain=prerouting 
comment="Address List via ISP3" dst-address-list=!BOGONS new-routing-mark=to_isp3 
passthrough=no src-address-list=Via_ISP3

結果,它看起來像這樣:

Mikrotik RouterOS 上的 Multivan 和路由

3. 建立與 ISP 的連接並啟用品牌路由

3.1. 建立與 ISP1 的連接:
3.1.1. 配置靜態 IP 地址:

/ip address add interface=ether1 address=100.66.66.2/30 comment="ISP1 IP"

3.1.2. 設置靜態路由:
3.1.2.1. 添加默認的“緊急”路由:

/ip route add comment="Emergency route" distance=254 type=blackhole

評論。 該路由允許來自本地進程的流量通過路由決策階段,而不管任何提供商的鏈接狀態如何。 傳出本地流量的細微差別是,為了讓數據包至少移動到某個地方,主路由表必須有一條到默認網關的活動路由。 如果沒有,那麼包裹將被簡單地銷毀。

作為工具擴展 檢查網關 為了更深入地分析通道狀態,我建議使用遞歸路由方法。 該方法的實質是我們告訴路由器不是直接尋找到它的網關的路徑,而是通過一個中間網關。 將分別選擇 4.2.2.1、4.2.2.2 和 4.2.2.3 作為 ISP1、ISP2 和 ISP3 的“測試”網關。

3.1.2.2. 路由到“驗證”地址:

/ip route add check-gateway=ping comment="For recursion via ISP1"  
distance=1 dst-address=4.2.2.1 gateway=100.66.66.1 scope=10

評論。 我們將 ROS 目標範圍中的範圍值降低為默認值,以便將來使用 4.2.2.1 作為遞歸網關。 我強調:到“測試”地址的路由范圍必須小於或等於將引用測試地址的路由的目標範圍。

3.1.2.3. 沒有路由標記的流量的遞歸默認路由:

/ip route add comment="Unmarked via ISP1" distance=2 gateway=4.2.2.1

評論。 使用 distance=2 值是因為根據任務條件 ISP1 被聲明為第一個備份。

3.1.2.4。 具有路由標記“to_isp1”的流量的遞歸默認路由:

/ip route add comment="Marked via ISP1 Main" distance=1 gateway=4.2.2.1 
routing-mark=to_isp1

評論。 實際上,在這裡我們終於開始享受在第 2 段中進行的準備工作的成果。


在此路由上,所有具有標記路由“to_isp1”的流量都將被定向到第一個提供程序的網關,而不管當前主表的哪個默認網關處於活動狀態。

3.1.2.5。 ISP2 和 ISP3 標記流量的第一個回退遞歸默認路由:

/ip route add comment="Marked via ISP2 Backup1" distance=2 gateway=4.2.2.1 
routing-mark=to_isp2
/ip route add comment="Marked via ISP3 Backup1" distance=2 gateway=4.2.2.1 
routing-mark=to_isp3

評論。 除其他事項外,需要這些路由來保留來自地址列表“to_isp*”成員的本地網絡的流量

3.1.2.6. 我們通過ISP1為路由器的本地流量註冊到Internet的路由:

/ip route rule add comment="From ISP1 IP to Inet" src-address=100.66.66.2 table=to_isp1

評論。 結合第 1.8.2 節中的規則,它提供了對具有給定源的所需頻道的訪問。 這對於構建指定本地端 IP 地址(EoIP、IP-IP、GRE)的隧道至關重要。 由於ip route rules中的規則是從上到下執行的,直到第一次匹配到條件,那麼這條規則應該在1.8.2的規則之後。

3.1.3. 我們為傳出流量註冊 NAT 規則:

/ip firewall nat add action=src-nat chain=srcnat comment="NAT via ISP1"  
ipsec-policy=out,none out-interface=ether1 to-addresses=100.66.66.2

評論。 NATim 所有出去的東西,除了進入 IPsec 策略的東西。 除非絕對必要,否則我盡量不使用 action=masquerade。 它比 src-nat 更慢且佔用更多資源,因為它會為每個新連接計算 NAT 地址。

3.1.4. 我們將禁止通過其他提供商訪問的列表中的客戶端直接發送到 ISP1 提供商的網關。

/ip firewall mangle add action=route chain=prerouting comment="Address List via ISP1 only" 
dst-address-list=!BOGONS passthrough=no route-dst=100.66.66.1 
src-address-list=Via_only_ISP1 place-before=0

評論。 action=route 具有更高的優先級,在其他路由規則之前應用。


place-before=0 - 將我們的規則放在列表的第一位。

3.2. 建立與 ISP2 的連接。

由於 ISP2 提供商通過 DHCP 為我們提供設置,因此使用觸發 DHCP 客戶端時啟動的腳本進行必要的更改是合理的:

/ip dhcp-client
add add-default-route=no disabled=no interface=ether2 script=":if ($bound=1) do={r
    n    /ip route add check-gateway=ping comment="For recursion via ISP2" distance=1 
           dst-address=4.2.2.2/32 gateway=$"gateway-address" scope=10r
    n    /ip route add comment="Unmarked via ISP2" distance=1 gateway=4.2.2.2;r
    n    /ip route add comment="Marked via ISP2 Main" distance=1 gateway=4.2.2.2 
           routing-mark=to_isp2;r
    n    /ip route add comment="Marked via ISP1 Backup1" distance=2 gateway=4.2.2.2 
           routing-mark=to_isp1;r
    n    /ip route add comment="Marked via ISP3 Backup2" distance=3 gateway=4.2.2.2 
           routing-mark=to_isp3;r
    n    /ip firewall nat add action=src-nat chain=srcnat ipsec-policy=out,none 
           out-interface=$"interface" to-addresses=$"lease-address" comment="NAT via ISP2" 
           place-before=1;r
    n    if ([/ip route rule find comment="From ISP2 IP to Inet"] ="") do={r
    n        /ip route rule add comment="From ISP2 IP to Inet" 
               src-address=$"lease-address" table=to_isp2 r
    n    } else={r
    n       /ip route rule set [find comment="From ISP2 IP to Inet"] disabled=no 
              src-address=$"lease-address"r
    n    }      r
    n} else={r
    n   /ip firewall nat remove  [find comment="NAT via ISP2"];r
    n   /ip route remove [find comment="For recursion via ISP2"];r
    n   /ip route remove [find comment="Unmarked via ISP2"];r
    n   /ip route remove [find comment="Marked via ISP2 Main"];r
    n   /ip route remove [find comment="Marked via ISP1 Backup1"];r
    n   /ip route remove [find comment="Marked via ISP3 Backup2"];r
    n   /ip route rule set [find comment="From ISP2 IP to Inet"] disabled=yesr
    n}r
    n" use-peer-dns=no use-peer-ntp=no

Winbox 窗口中的腳本本身:

Mikrotik RouterOS 上的 Multivan 和路由
評論。 腳本的第一部分在租約成功獲得時觸發,第二部分在租約釋放後觸發。見註 2

3.3. 我們建立了與 ISP3 提供商的連接。

由於設置提供程序為我們提供了動態,因此使用在 ppp 接口啟動後和下降後啟動的腳本進行必要的更改是合理的。

3.3.1. 首先我們配置配置文件:

/ppp profile
add comment="for PPPoE to ISP3" interface-list=WAN name=isp3_client 
on-down="/ip firewall nat remove  [find comment="NAT via ISP3"];r
    n/ip route remove [find comment="For recursion via ISP3"];r
    n/ip route remove [find comment="Unmarked via ISP3"];r
    n/ip route remove [find comment="Marked via ISP3 Main"];r
    n/ip route remove [find comment="Marked via ISP1 Backup2"];r
    n/ip route remove [find comment="Marked via ISP2 Backup2"];r
    n/ip route rule set [find comment="From ISP3 IP to Inet"] disabled=yes;" 
on-up="/ip route add check-gateway=ping comment="For recursion via ISP3" distance=1 
    dst-address=4.2.2.3/32 gateway=$"remote-address" scope=10r
    n/ip route add comment="Unmarked via ISP3" distance=3 gateway=4.2.2.3;r
    n/ip route add comment="Marked via ISP3 Main" distance=1 gateway=4.2.2.3 
    routing-mark=to_isp3;r
    n/ip route add comment="Marked via ISP1 Backup2" distance=3 gateway=4.2.2.3 
    routing-mark=to_isp1;r
    n/ip route add comment="Marked via ISP2 Backup2" distance=3 gateway=4.2.2.3 
    routing-mark=to_isp2;r
    n/ip firewall mangle set [find comment="Connmark in from ISP3"] 
    in-interface=$"interface";r
    n/ip firewall nat add action=src-nat chain=srcnat ipsec-policy=out,none 
    out-interface=$"interface" to-addresses=$"local-address" comment="NAT via ISP3" 
    place-before=1;r
    nif ([/ip route rule find comment="From ISP3 IP to Inet"] ="") do={r
    n   /ip route rule add comment="From ISP3 IP to Inet" src-address=$"local-address" 
    table=to_isp3 r
    n} else={r
    n   /ip route rule set [find comment="From ISP3 IP to Inet"] disabled=no 
    src-address=$"local-address"r
    n};r
    n"

Winbox 窗口中的腳本本身:

Mikrotik RouterOS 上的 Multivan 和路由
評論。 弦樂
/ip firewall mangle set [find comment="Connmark in from ISP3"] in-interface=$"interface";
允許您正確處理界面的重命名,因為它使用它的代碼而不是顯示名稱。

3.3.2. 現在,使用配置文件創建 ppp 連接:

/interface pppoe-client add allow=mschap2 comment="to ISP3" disabled=no 
interface=ether3 name=pppoe-isp3 password=isp3_pass profile=isp3_client user=isp3_client

最後,讓我們設置時鐘:

/system ntp client set enabled=yes server-dns-names=0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org

對於那些讀到最後的人

建議的實現 multivan 的方法是作者的個人偏好,並不是唯一可能的方法。 ROS工具包廣泛且靈活,一方面給初學者帶來了困難,另一方面也是其受歡迎的原因。 學習、嘗試、發現新的工具和解決方案。 例如,作為所獲得知識的應用,可以在 multivan 的實現中替換工具 檢查網關 遞歸路線 網絡觀察.

筆記

  1. 檢查網關 - 一種允許您在連續兩次檢查網關可用性失敗後停用路由的機制。 檢查每 10 秒執行一次,加上響應超時。 總的來說,實際切換時間在 20-30 秒的範圍內。 如果這樣的切換時間不夠,可以選擇使用該工具 網絡觀察,其中可以手動設置檢查計時器。 檢查網關 不會在鏈路上的間歇性數據包丟失時觸發。

    重要的! 停用主要路由將停用引用它的所有其他路由。 因此,讓他們指出 檢查網關=平 不必要。

  2. 碰巧DHCP機制出現故障,看起來像客戶端卡在了renew狀態。 在這種情況下,腳本的第二部分將不起作用,但它不會阻止交通正確行走,因為狀態跟踪相應的遞歸路線。
  3. ECMP(等價多路徑) - 在 ROS 中,可以設置具有多個網關和相同距離的路由。 在這種情況下,連接將使用循環算法按指定網關的數量按比例跨通道分配。

為了推動撰寫文章,幫助塑造其結構和重音位置 - 個人感謝 Evgeny @jscar

來源: www.habr.com