Skip to content

Instantly share code, notes, and snippets.

@frizz925
Created December 15, 2019 11:10
Show Gist options
  • Save frizz925/2babe30da8e2676b259c244d632a8c13 to your computer and use it in GitHub Desktop.
Save frizz925/2babe30da8e2676b259c244d632a8c13 to your computer and use it in GitHub Desktop.
RouterOS commands and scripts for failover setup + load-balancing using PCC
/ip dhcp-client
add interface=ether2 add-default-route=no script=""
# The following is the script used to automatically add and remove the gateway from the DHCP client
:if ($bound = 1) do={
/ip route add dst-address=8.8.8.8 gateway=$"gateway-address" scope=10 comment="ether2 gateway"
} else={
/ip route remove [find comment="ether2 gateway"]
}
/ip firewall mangle
add chain=prerouting action=mark-connection new-connection-mark=ether1_conn connection-mark=no-mark in-interface=ether1
add chain=prerouting action=mark-connection new-connection-mark=ether2_conn connection-mark=no-mark in-interface=ether2
add chain=prerouting action=mark-connection new-connection-mark=ether1_conn connection-mark=no-mark in-interface=bridge dst-address-type=!local per-connection-classifier=both-addresses:2/0
add chain=prerouting action=mark-connection new-connection-mark=ether2_conn connection-mark=no-mark in-interface=bridge dst-address-type=!local per-connection-classifier=both-addresses:2/1
add chain=prerouting action=mark-routing new-routing-mark=to_ether1 connection-mark=ether1_conn in-interface=bridge
add chain=prerouting action=mark-routing new-routing-mark=to_ether2 connection-mark=ether2_conn in-interface=bridge
add chain=output action=mark-routing new-routing-mark=to_ether1 connection-mark=ether1_conn
add chain=output action=mark-routing new-routing-mark=to_ether2 connection-mark=ether2_conn
/ip routes
add dst-address=1.1.1.1 gateway=192.168.0.1 route=10 comment="ether1 gateway"
add distance=1 gateway=1.1.1.1 routing-mark=to_ether1 check-gateway=ping comment="ether1 main"
add distance=1 gateway=8.8.8.8 routing-mark=to_ether2 check-gateway=ping comment="ether2 main"
add distance=2 gateway=8.8.8.8 routing-mark=to_ether1 check-gateway=ping comment="ether1 failover"
add distance=2 gateway=1.1.1.1 routing-mark=to_ether2 check-gateway=ping comment="ether2 failover"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment