Dual Wan with Dymanic WAN IP

Hi everyone,

I am newbie, I have 2 ISP connect to my ROS, and both lines are dynamic WAN IP.
I would like to build up Dual WAN load balance connection.
But I cannot find template/sample is related to Dynamic WAN IP

I find this script (Fixed WAN IP), but I dunno how to modify the source IP(interface?)
Please kindly help to guide me step by step, thanks so much!


/ip address
add address=192.168.0.1/24 network=192.168.0.0 broadcast=192.168.0.255 interface=Local
add address=192.168.1.2/24 network=192.168.1.0 broadcast=192.168.1.255 interface=WAN1
add address=192.168.2.2/24 network=192.168.2.0 broadcast=192.168.2.255 interface=WAN2

/ip dns set allow-remote-requests=yes cache-max-ttl=1w cache-size=5000KiB max-udp-packet-size=512 servers=221.132.112.8,8.8.8.8

/ip firewall mangle
add chain=input in-interface=WAN1 action=mark-connection new-connection-mark=WAN1_conn
add chain=input in-interface=WAN2 action=mark-connection new-connection-mark=WAN2_conn

add chain=output connection-mark=WAN1_conn action=mark-routing new-routing-mark=to_WAN1
add chain=output connection-mark=WAN2_conn action=mark-routing new-routing-mark=to_WAN2

add chain=prerouting dst-address=192.168.1.0/24 action=accept in-interface=Local
add chain=prerouting dst-address=192.168.2.0/24 action=accept in-interface=Local

add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:2/0 action=mark-connection new-connection-mark=WAN1_conn passthrough=yes
add chain=prerouting dst-address-type=!local in-interface=Local per-connection-classifier=both-addresses-and-ports:2/1 action=mark-connection new-connection-mark=WAN2_conn passthrough=yes

add chain=prerouting connection-mark=WAN1_conn in-interface=Local action=mark-routing new-routing-mark=to_WAN1
add chain=prerouting connection-mark=WAN2_conn in-interface=Local action=mark-routing new-routing-mark=to_WAN2

/ip route
add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 check-gateway=ping

/ip firewall nat
add chain=srcnat out-interface=WAN1 action=masquerade
add chain=srcnat out-interface=WAN2 action=masquerade

Many Many thanks!

I have not tried the configuration with dhcp ip, may be i could help to analyze the code.

add address=[color=#FF0000]192.168.1.2/24[/color] network=[color=#FF0000]192.168.1.0[/color] broadcast=[color=#FF0000]192.168.1.255[/color] interface=WAN1
add address=[color=#FF0000]192.168.2.2/24[/color] network=[color=#FF0000]192.168.2.0[/color] broadcast=[color=#FF0000]192.168.2.255[/color] interface=WAN2

You don’t need this two codes, since the IP’s on both interfaces will be assign by dhcp services.

/ip firewall mangle
add chain=prerouting dst-address=[color=#FF0000]192.168.1.0/24[/color] action=accept in-interface=Local
add chain=prerouting dst-address=[color=#FF0000]192.168.2.0/24[/color] action=accept in-interface=Local

This code will prevent the connection to those network will be load balanced by PCC. Maybe we could just change the dst-address parameter with dst-address-type=Local. Or just remove the code, Just try.

/ip route
add dst-address=0.0.0.0/0 gateway=[color=#FF0000]192.168.1.1[/color] routing-mark=to_WAN1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=[color=#FF0000]192.168.2.1[/color] routing-mark=to_WAN2 check-gateway=ping

add dst-address=0.0.0.0/0 gateway=[color=#FF0000]192.168.1.1[/color] distance=1 check-gateway=ping
add dst-address=0.0.0.0/0 gateway=[color=#FF0000]192.168.2.1[/color] distance=2 check-gateway=ping

Instead using gateway’s IP address maybe you could put the interface’s name, once again just try.

Lets us know if that’s working.