Для простой балансировки исходящего трафика хватает одной команды.
В случае когда есть 2 (или более) провайдера и через каждый мы пускам к себе например на web сервер настройка уже сложней. Для примера доступа к web серверу по 80 порту с IP 192.168.1.21 нужно сделать правила для каждого внешнего интерфейса (ether1 и ether2)
1 | ip firewall nat add chain=dstnat action=dst-nat in-interface=ether1 protocol=tcp dst-port=80 to-address=192.168.1.21 to-ports=80 |
2 | |
3 | ip firewall nat add chain=dstnat action=dst-nat in-interface=ether2 protocol=tcp dst-port=80 to-address=192.168.1.21 to-ports=80 |
Разрешаем прохождение пакетов через маршрутизатор адресованных web серверу (если у нас строгие правила):
1 | ip firewall filter add chain forward in-interface=ether1 protocol=tcp dst-port=80 dst-address=192.168.1.21 action=accept |
2 | ip firewall filter add chain forward in-interface=ether1 protocol=tcp dst-port=80 dst-address=192.168.1.21 action=accept |
Ну, а теперь самое интересно, помечаем входящие соединения, чтобы ответы шли через того провайдера с которого получен запрос:
1 | ip firewall mangle add chain=forward in-interface=ether1 action=mark-connection new-connection-mark=ether1_c passthrough=yes |
2 | ip firewall mangle add chain=forward in-interface=ether2 action=mark-connection new-connection-mark=ether2_c passthrough=yes |
3 | ip firewall mangle add chain=prerouting src-address=192.168.1.0/24 connection-mark=ether1_c action=mark-routing new-routing-mark=ether1_r passthrough=yes |
4 | ip firewall mangle add chain=prerouting src-address=192.168.1.0/24 connection-mark=ether2_c action=mark-routing new-routing-mark=ether2_r passthrough=yes |
Добавляем правила маршрутизации:
1 | ip route add routing-mark=ether1_r gateway=<IP_gw_SP1> |
2 | ip route add routing-mark=ether2_r gateway=<IP_gw_SP1> |
проверяем и радуемся