Refactor multiwan_mikrotik_setup.md to improve clarity and consistency in configuration. Renamed PPPoE client interface to 'RTK-Internet', updated routing table entries for failover and health checks in the main routing table, and adjusted connection marking rules for better readability. Added commands for monitoring routes in the main table.
This commit is contained in:
@@ -0,0 +1,412 @@
|
||||
# Динамическое управление маршрутами через OSPF и BFD
|
||||
|
||||
## Проблема
|
||||
|
||||
У вас есть статические маршруты с gateway `swe-hiphost`, которые настраиваются через routing rules, и нужно, чтобы они динамически изменялись в зависимости от активности туннеля через OSPF и BFD.
|
||||
|
||||
## Решение: Динамические маршруты через OSPF redistribute
|
||||
|
||||
### Архитектура решения
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph "HOME"
|
||||
HOME[HOME<br/>home.rt.shx.su]
|
||||
RT[Routing Table<br/>YouTube]
|
||||
RR[Routing Rules]
|
||||
end
|
||||
|
||||
subgraph "Москва"
|
||||
IHOR[MSK-IHOR<br/>msk.ihor.rt.shx.su]
|
||||
OSPF[OSPF Instance<br/>redistribute=static]
|
||||
end
|
||||
|
||||
subgraph "Швеция"
|
||||
SWE[SWE-HIPHOST<br/>swe.hiphost.rt.shx.su]
|
||||
BFD[BFD Session]
|
||||
end
|
||||
|
||||
%% Связи
|
||||
HOME -- "GRE туннели" --> IHOR
|
||||
HOME -- "GRE туннели" --> SWE
|
||||
IHOR -- "GRE туннель" --> SWE
|
||||
|
||||
%% OSPF и BFD
|
||||
IHOR -. "OSPF redistribute" .- HOME
|
||||
IHOR -. "BFD monitoring" .- SWE
|
||||
|
||||
%% Routing
|
||||
RT -. "OSPF route" .- HOME
|
||||
RR -. "Policy routing" .- RT
|
||||
|
||||
style HOME fill:#e1f5fe
|
||||
style IHOR fill:#ff9800
|
||||
style SWE fill:#4caf50
|
||||
style OSPF fill:#ff5722
|
||||
style BFD fill:#9c27b0
|
||||
```
|
||||
|
||||
## Пошаговая настройка
|
||||
|
||||
### Шаг 1: Настройка BFD для мониторинга туннеля IHOR→SWE
|
||||
|
||||
#### На MSK-IHOR (msk.ihor.rt.shx.su):
|
||||
```shell
|
||||
# Настроить BFD для GRE туннеля к SWE
|
||||
/routing bfd
|
||||
add interface=gre-SWE-HIPHOST interval=100ms multiplier=3
|
||||
|
||||
# Включить BFD для OSPF
|
||||
/routing ospf interface-template
|
||||
set [ find where interfaces=gre-SWE-HIPHOST ] bfd=yes
|
||||
```
|
||||
|
||||
#### На SWE-HIPHOST (swe.hiphost.rt.shx.su):
|
||||
```shell
|
||||
# Настроить BFD для GRE туннеля от IHOR
|
||||
/routing bfd
|
||||
add interface=gre-IHOR-SWE interval=100ms multiplier=3
|
||||
|
||||
# Включить BFD для OSPF
|
||||
/routing ospf interface-template
|
||||
set [ find where interfaces=gre-IHOR-SWE ] bfd=yes
|
||||
```
|
||||
|
||||
### Шаг 2: Настройка условных статических маршрутов на IHOR
|
||||
|
||||
#### На MSK-IHOR (msk.ihor.rt.shx.su):
|
||||
```shell
|
||||
# Создать статические маршруты с проверкой доступности туннеля
|
||||
/ip route
|
||||
add dst-address=173.194.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=74.125.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=142.250.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=172.217.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=216.58.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=34.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=35.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
add dst-address=142.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=ping
|
||||
|
||||
# Альтернативно - использовать check-gateway=bfd
|
||||
/ip route
|
||||
add dst-address=173.194.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=74.125.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=142.250.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=172.217.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=216.58.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=34.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=35.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=142.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
```
|
||||
|
||||
### Шаг 3: Настройка OSPF redistribute на IHOR
|
||||
|
||||
#### На MSK-IHOR (msk.ihor.rt.shx.su):
|
||||
```shell
|
||||
# Включить redistribute статических маршрутов в OSPF
|
||||
/routing ospf instance
|
||||
set [ find default=yes ] redistribute=connected,static
|
||||
|
||||
# Настроить фильтрацию для redistribute (опционально)
|
||||
/routing ospf redistribute
|
||||
add instance=default type=static route-filter=173.194.0.0/16
|
||||
add instance=default type=static route-filter=74.125.0.0/16
|
||||
add instance=default type=static route-filter=142.250.0.0/16
|
||||
add instance=default type=static route-filter=172.217.0.0/16
|
||||
add instance=default type=static route-filter=216.58.0.0/16
|
||||
add instance=default type=static route-filter=34.0.0.0/8
|
||||
add instance=default type=static route-filter=35.0.0.0/8
|
||||
add instance=default type=static route-filter=142.0.0.0/8
|
||||
```
|
||||
|
||||
### Шаг 4: Настройка routing rules на HOME
|
||||
|
||||
#### На HOME (home.rt.shx.su):
|
||||
```shell
|
||||
# Создать routing table YouTube
|
||||
/routing table
|
||||
add name=YouTube fib
|
||||
|
||||
# Создать address-list для YouTube
|
||||
/ip firewall address-list
|
||||
add list=YouTube list=173.194.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=74.125.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=142.250.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=172.217.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=216.58.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=34.0.0.0/8 comment="YouTube"
|
||||
add list=YouTube list=35.0.0.0/8 comment="YouTube"
|
||||
add list=YouTube list=142.0.0.0/8 comment="YouTube"
|
||||
|
||||
# Routing rules для YouTube трафика
|
||||
/routing rule
|
||||
add dst-address=173.194.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=74.125.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=142.250.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=172.217.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=216.58.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=34.0.0.0/8 action=lookup table=YouTube
|
||||
add dst-address=35.0.0.0/8 action=lookup table=YouTube
|
||||
add dst-address=142.0.0.0/8 action=lookup table=YouTube
|
||||
|
||||
# Маршрут в таблице YouTube через IHOR (будет получаться через OSPF)
|
||||
/ip route
|
||||
add dst-address=0.0.0.0/0 gateway=10.100.4.2 routing-table=YouTube distance=1
|
||||
```
|
||||
|
||||
## Альтернативное решение: Скрипт для динамического управления маршрутами
|
||||
|
||||
### Создание скрипта на IHOR
|
||||
|
||||
#### На MSK-IHOR (msk.ihor.rt.shx.su):
|
||||
```shell
|
||||
# Создать скрипт для мониторинга BFD и управления маршрутами
|
||||
/system script
|
||||
add name=check-swe-tunnel source={
|
||||
:local bfdStatus [/routing bfd print where interface=gre-SWE-HIPHOST]
|
||||
:local routeExists [/ip route print count-only where dst-address=173.194.0.0/16]
|
||||
|
||||
:if ([:len $bfdStatus] > 0) do={
|
||||
:if ($routeExists = 0) do={
|
||||
:log info "SWE tunnel is UP - adding YouTube routes"
|
||||
/ip route add dst-address=173.194.0.0/16 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=74.125.0.0/16 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=142.250.0.0/16 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=172.217.0.0/16 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=216.58.0.0/16 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=34.0.0.0/8 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=35.0.0.0/8 gateway=10.200.2.2 distance=1
|
||||
/ip route add dst-address=142.0.0.0/8 gateway=10.200.2.2 distance=1
|
||||
}
|
||||
} else={
|
||||
:if ($routeExists > 0) do={
|
||||
:log info "SWE tunnel is DOWN - removing YouTube routes"
|
||||
/ip route remove [find where dst-address=173.194.0.0/16]
|
||||
/ip route remove [find where dst-address=74.125.0.0/16]
|
||||
/ip route remove [find where dst-address=142.250.0.0/16]
|
||||
/ip route remove [find where dst-address=172.217.0.0/16]
|
||||
/ip route remove [find where dst-address=216.58.0.0/16]
|
||||
/ip route remove [find where dst-address=34.0.0.0/8]
|
||||
/ip route remove [find where dst-address=35.0.0.0/8]
|
||||
/ip route remove [find where dst-address=142.0.0.0/8]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Создать scheduler для запуска скрипта каждые 10 секунд
|
||||
/system scheduler
|
||||
add name=check-swe-tunnel interval=10s on-event=check-swe-tunnel
|
||||
```
|
||||
|
||||
## Решение через OSPF cost manipulation
|
||||
|
||||
### Настройка динамического cost на основе BFD
|
||||
|
||||
#### На MSK-IHOR (msk.ihor.rt.shx.su):
|
||||
```shell
|
||||
# Создать скрипт для изменения OSPF cost на основе BFD статуса
|
||||
/system script
|
||||
add name=adjust-ospf-cost source={
|
||||
:local bfdStatus [/routing bfd print where interface=gre-SWE-HIPHOST]
|
||||
:local ospfInterface [/routing ospf interface-template find where interfaces=gre-SWE-HIPHOST]
|
||||
|
||||
:if ([:len $bfdStatus] > 0) do={
|
||||
# Туннель активен - низкий cost
|
||||
/routing ospf interface-template set $ospfInterface cost=10
|
||||
:log info "SWE tunnel UP - OSPF cost set to 10"
|
||||
} else={
|
||||
# Туннель неактивен - высокий cost
|
||||
/routing ospf interface-template set $ospfInterface cost=1000
|
||||
:log info "SWE tunnel DOWN - OSPF cost set to 1000"
|
||||
}
|
||||
}
|
||||
|
||||
# Запускать скрипт каждые 5 секунд
|
||||
/system scheduler
|
||||
add name=adjust-ospf-cost interval=5s on-event=adjust-ospf-cost
|
||||
```
|
||||
|
||||
## Проверка настройки
|
||||
|
||||
### На MSK-IHOR:
|
||||
```shell
|
||||
# Проверить BFD статус
|
||||
/routing bfd print
|
||||
|
||||
# Проверить статические маршруты
|
||||
/ip route print where dst-address~"173.194"
|
||||
|
||||
# Проверить OSPF redistribute
|
||||
/routing ospf redistribute print
|
||||
|
||||
# Проверить OSPF маршруты
|
||||
/routing ospf route print
|
||||
```
|
||||
|
||||
### На HOME:
|
||||
```shell
|
||||
# Проверить OSPF маршруты
|
||||
/routing ospf route print
|
||||
|
||||
# Проверить routing table YouTube
|
||||
/ip route print where routing-table=YouTube
|
||||
|
||||
# Проверить routing rules
|
||||
/routing rule print where table=YouTube
|
||||
```
|
||||
|
||||
## Тестирование
|
||||
|
||||
### Тест 1: Проверка автоматического добавления маршрутов
|
||||
```shell
|
||||
# На IHOR проверить что маршруты добавлены
|
||||
/ip route print where dst-address~"173.194"
|
||||
|
||||
# На HOME проверить что маршруты получены через OSPF
|
||||
/routing ospf route print
|
||||
```
|
||||
|
||||
### Тест 2: Проверка failover при отключении туннеля
|
||||
```shell
|
||||
# Отключить GRE туннель на IHOR
|
||||
/interface gre disable [find where name=gre-SWE-HIPHOST]
|
||||
|
||||
# Подождать 10-30 секунд и проверить что маршруты исчезли
|
||||
/ip route print where dst-address~"173.194"
|
||||
|
||||
# Включить туннель обратно
|
||||
/interface gre enable [find where name=gre-SWE-HIPHOST]
|
||||
|
||||
# Проверить что маршруты появились снова
|
||||
/ip route print where dst-address~"173.194"
|
||||
```
|
||||
|
||||
### Тест 3: Проверка BFD мониторинга
|
||||
```shell
|
||||
# Проверить BFD сессии
|
||||
/routing bfd print detail
|
||||
|
||||
# Проверить BFD логи
|
||||
/log print where topics~"bfd"
|
||||
```
|
||||
|
||||
## Мониторинг и логирование
|
||||
|
||||
### Настройка логирования на IHOR:
|
||||
```shell
|
||||
# Включить логирование для BFD
|
||||
/system logging
|
||||
add topics=bfd
|
||||
|
||||
# Включить логирование для OSPF
|
||||
/system logging
|
||||
add topics=ospf
|
||||
|
||||
# Включить логирование для routing
|
||||
/system logging
|
||||
add topics=route
|
||||
```
|
||||
|
||||
### Создание дашборда для мониторинга:
|
||||
```shell
|
||||
# Скрипт для отображения статуса
|
||||
/system script
|
||||
add name=show-tunnel-status source={
|
||||
:log info "=== Tunnel Status Report ==="
|
||||
:log info "BFD Status:"
|
||||
/routing bfd print
|
||||
:log info "YouTube Routes:"
|
||||
/ip route print where dst-address~"173.194"
|
||||
:log info "OSPF Routes:"
|
||||
/routing ospf route print
|
||||
:log info "=== End Report ==="
|
||||
}
|
||||
|
||||
# Запускать каждую минуту
|
||||
/system scheduler
|
||||
add name=status-report interval=1m on-event=show-tunnel-status
|
||||
```
|
||||
|
||||
## Полная конфигурация для копирования
|
||||
|
||||
### MSK-IHOR (msk.ihor.rt.shx.su):
|
||||
```shell
|
||||
# BFD для GRE туннеля
|
||||
/routing bfd
|
||||
add interface=gre-SWE-HIPHOST interval=100ms multiplier=3
|
||||
|
||||
# OSPF с BFD
|
||||
/routing ospf interface-template
|
||||
set [ find where interfaces=gre-SWE-HIPHOST ] bfd=yes
|
||||
|
||||
# Статические маршруты с проверкой
|
||||
/ip route
|
||||
add dst-address=173.194.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=74.125.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=142.250.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=172.217.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=216.58.0.0/16 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=34.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=35.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
add dst-address=142.0.0.0/8 gateway=10.200.2.2 distance=1 check-gateway=bfd
|
||||
|
||||
# OSPF redistribute
|
||||
/routing ospf instance
|
||||
set [ find default=yes ] redistribute=connected,static
|
||||
```
|
||||
|
||||
### SWE-HIPHOST (swe.hiphost.rt.shx.su):
|
||||
```shell
|
||||
# BFD для GRE туннеля
|
||||
/routing bfd
|
||||
add interface=gre-IHOR-SWE interval=100ms multiplier=3
|
||||
|
||||
# OSPF с BFD
|
||||
/routing ospf interface-template
|
||||
set [ find where interfaces=gre-IHOR-SWE ] bfd=yes
|
||||
```
|
||||
|
||||
### HOME (home.rt.shx.su):
|
||||
```shell
|
||||
# Routing table YouTube
|
||||
/routing table
|
||||
add name=YouTube fib
|
||||
|
||||
# Address-list YouTube
|
||||
/ip firewall address-list
|
||||
add list=YouTube list=173.194.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=74.125.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=142.250.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=172.217.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=216.58.0.0/16 comment="YouTube"
|
||||
add list=YouTube list=34.0.0.0/8 comment="YouTube"
|
||||
add list=YouTube list=35.0.0.0/8 comment="YouTube"
|
||||
add list=YouTube list=142.0.0.0/8 comment="YouTube"
|
||||
|
||||
# Routing rules
|
||||
/routing rule
|
||||
add dst-address=173.194.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=74.125.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=142.250.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=172.217.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=216.58.0.0/16 action=lookup table=YouTube
|
||||
add dst-address=34.0.0.0/8 action=lookup table=YouTube
|
||||
add dst-address=35.0.0.0/8 action=lookup table=YouTube
|
||||
add dst-address=142.0.0.0/8 action=lookup table=YouTube
|
||||
|
||||
# Маршрут в таблице YouTube
|
||||
/ip route
|
||||
add dst-address=0.0.0.0/0 gateway=10.100.4.2 routing-table=YouTube distance=1
|
||||
```
|
||||
|
||||
## Заключение
|
||||
|
||||
Данное решение обеспечивает:
|
||||
|
||||
1. **Автоматическое управление маршрутами** через OSPF redistribute
|
||||
2. **Быстрое обнаружение проблем** через BFD (100ms интервал)
|
||||
3. **Динамическое добавление/удаление маршрутов** в зависимости от состояния туннеля
|
||||
4. **Сохранение routing rules** на HOME для Policy Based Routing
|
||||
5. **Автоматический failover** при проблемах с туннелем
|
||||
|
||||
Теперь ваши статические маршруты с gateway `swe-hiphost` будут автоматически появляться и исчезать в зависимости от активности туннеля, контролируемой OSPF и BFD.
|
||||
Reference in New Issue
Block a user