Настройка балансировки в EdgeOS | Ubiquiti форум UBNT: инструкции, настройка

Настройка балансировки в EdgeOS

fAntom

Super Moderator
Команда форума
24 Ноя 2017
6.216
378
5.065
ubnt.su
Настройка балансировки в EdgeOS

Рассмотрим вариант подключения двух провайдеров:
1. Интерфейс eth0 (протокол PPPoE Client, Gateway 10.10.0.254),
2. Интерфейс eth1 (протокол DHCP Client, Gateway 192.168.10.1).
Локальная сеть eth2-eth3, DHCPсервер, 192.168.20.0/24.

Для настройки необходимо будет подключиться к роутеру по ssh. В семействе Windowsдля этого используется putty. После ввода логина и пароля проверим соединения с провайдерами:

ubnt@ubnt:~$ show interfaces

Потом необходимо настроить доступ из локальной сети к провайдерам:

ubnt@ubnt:~$ configure
[edit]
ubnt@ubnt# set service nat rule 5010 outbound-interface eth0
[edit]
ubnt@ubnt# set service nat rule 5010 type masquerade
[edit]
ubnt@ubnt# set service nat rule 5020 outbound-interface pppoe0
[edit]
ubnt@ubnt# set service nat rule 5020 type masquerade
[edit]
ubnt@ubnt# commit
[edit]
ubnt@ubnt# save
Saving configuration to '/config/config.boot'...
Done
[edit]
ubnt@ubnt# exit
exit
ubnt@ubnt:~$


Далее настроим маршрутизацию:

ubnt@ubnt:~$ configure
[edit]
ubnt@ubnt# set protocols static route 0.0.0.0/0 next-hop 192.168.10.1
[edit]
ubnt@ubnt# set protocols static route 0.0.0.0/0 next-hop 10.10.0.254
[edit]
ubnt@ubnt# set protocols static table 1 mark 1
[edit]
ubnt@ubnt# set protocols static table 1 route 0.0.0.0/0 next-hop 192.168.10.1
[edit]
ubnt@ubnt# set protocols static table 2 mark 2
[edit]
ubnt@ubnt# set protocols static table 2 route 0.0.0.0/0 next-hop 10.10.0.254
[edit]
ubnt@ubnt#

Собственно сама балансировка, настраивается через Firewall:

ubnt@ubnt# set firewall modify balance rule 10 action modify
[edit]
ubnt@ubnt# set firewall modify balance rule 10 description 'restore mark from connection'
[edit]
ubnt@ubnt# set firewall modify balance rule 10 modify connmark restore-mark
[edit]
ubnt@ubnt# set firewall modify balance rule 20 action accept
[edit]
ubnt@ubnt# set firewall modify balance rule 20 description 'accept the packet if the mark isnt zero'
[edit]
ubnt@ubnt# set firewall modify balance rule 20 mark !0
[edit]
ubnt@ubnt# set firewall modify balance rule 30 action modify
[edit]
ubnt@ubnt# set firewall modify balance rule 30 description 'for new connections mark 50% with mark 1'
[edit]
ubnt@ubnt# set firewall modify balance rule 30 modify mark 1
[edit]
ubnt@ubnt# set firewall modify balance rule 30 protocol tcp_udp
[edit]
ubnt@ubnt# set firewall modify balance rule 30 state new enable
[edit]
ubnt@ubnt# set firewall modify balance rule 30 statistic probability 50%
[edit]
ubnt@ubnt# set firewall modify balance rule 40 action modify
[edit]
ubnt@ubnt# set firewall modify balance rule 40 description 'for packets with mark zero, mark with 2'
[edit]
ubnt@ubnt# set firewall modify balance rule 40 mark 0
[edit]
ubnt@ubnt# set firewall modify balance rule 40 modify mark 2
[edit]
ubnt@ubnt# set firewall modify balance rule 40 protocol tcp_udp
[edit]
ubnt@ubnt# set firewall modify balance rule 40 state new enable
[edit]
ubnt@ubnt# set firewall modify balance rule 50 action modify
[edit]
ubnt@ubnt# set firewall modify balance rule 50 description 'save the packet mark to the connection mark'
[edit]
ubnt@ubnt# set firewall modify balance rule 50 modify connmark save-mark
[edit]
ubnt@ubnt#

В правиле setfirewallmodifybalancerule 30 statisticprobability 50%, указываем процент трафика, который пойдет через провайдера помеченного как mark 1, а оставшийся через другого. В данном случае задано 50/50.


Применяем правила балансировки:

ubnt@ubnt# set interfaces ethernet eth2 firewall in modify balance
[edit]
ubnt@ubnt#

Устанавливаем и сохраняем всю конфигурацию:

ubnt@ubnt# commit
[ protocols static table 1 mark 1 ]
old mark undefined mark [1]
[ protocols static table 2 mark 2 ]
old mark undefined mark [2]
[edit]
ubnt@ubnt# save
Saving configuration to '/config/config.boot'...
Done
[edit]
ubnt@ubnt# exit
exit
ubnt@ubnt:~$


Увидеть более точную статистику, можно с помощью следующей команды:

show firewall modify statistics