Community discussions

MikroTik App
 
iredden
newbie
Topic Author
Posts: 47
Joined: Thu Jan 27, 2005 8:42 am
Location: Campbellford, Ontario CANADA

Problem load balancing (PCC) with IP's assigned by DHCP

Fri Apr 26, 2013 1:59 am

Here is the scenario:
WAN1
IP: 1.114.229.3/22
Gateway: 1.114.228.1

WAN2
IP: 1.230.160.168/27
Gateway: 1.230.160.161

I have DHCP-client setup the following:
/ip dhcp-client
add add-default-route=yes default-route-distance=1 disabled=no host-name=router interface=WAN1 use-peer-dns=no use-peer-ntp=no
add add-default-route=no disabled=no host-name=router interface=WAN2 use-peer-dns=no use-peer-ntp=no

Routing is setup:
/ip route
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.230.160.161 routing-mark=to_wan2 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.114.228.1 routing-mark=to_wan1 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.230.160.161 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=2 dst-address=0.0.0.0/0 gateway=1.114.228.1 scope=30 target-scope=10

and just for giggles, here is my firewall mangle:
/ip firewall mangle
add action=mark-connection chain=input disabled=no in-interface=wan1 new-connection-mark=wan1_conn passthrough=yes
add action=mark-connection chain=input disabled=no in-interface=wan2 new-connection-mark=wan2_conn passthrough=yes
add action=mark-routing chain=output connection-mark=wan1_conn disabled=no new-routing-mark=to_wan1 passthrough=yes
add action=mark-routing chain=output connection-mark=wan2_conn disabled=no new-routing-mark=to_wan2 passthrough=yes
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local in-interface=lan new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/0
add action=mark-connection chain=prerouting disabled=no dst-address-type=!local in-interface=lan new-connection-mark=wan2_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/1
add action=mark-routing chain=prerouting connection-mark=wan1_conn disabled=no in-interface=lan new-routing-mark=to_wan1 passthrough=yes
add action=mark-routing chain=prerouting connection-mark=wan2_conn disabled=no in-interface=lan new-routing-mark=to_wan2 passthrough=yes
add action=accept chain=prerouting disabled=no dst-address=1.230.160.160/27 in-interface=lan
add action=accept chain=prerouting disabled=no dst-address=1.114.228.0/22 in-interface=lan

This setup works perfectly. The problem is since the gateway and ip are assigned via DHCP, if the lease expires AND I am suddenly in a different block from the ISP (thus having a different gateway) my setup breaks. My WAN2 provider uses very small block assignments (/27, /29) and my IP does change from time to time breaking my setup.

I have tried using gateway=<interfacename> but it breaks:
/ip route
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wan2 routing-mark=to_teksavvy scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wan1 routing-mark=to_onekingwest scope=30 target-scope=10
add check-gateway=ping disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wan2 scope=30 target-scope=10
add check-gateway=ping disabled=no distance=2 dst-address=0.0.0.0/0 gateway=wan1 scope=30 target-scope=10

No internet connectivity.

My question -- How do I tell Mikrotik to get the gatewayip from the dhcplease for interface=X?