I have two DOCSIS 3 Cable services (Charter Communications), each has a Dynamic IP.
My WAN interfaces are named "wan0" and "wan1".
I have two LAN interfaces, "lanBridge" and "iot_vlan" - The LAN's are not permitted to communicate. (I don't trust IoT devices on my LAN)
I use address lists and Interface lists where possible. I've also included a script that runs every 5 minutes that will update the routes when the public IP changes.
Note - the script WILL NOT run if you have more than 1 IP on a WAN interface.
WAN interface names are important. Need to be able to fine the interface and address
/interface ethernet
set [ find default-name=ether9 ] comment="wan0" name=wan0
set [ find default-name=ether10 ] comment="wan1" name=wan1
/interface list
add name=lanLinks
add name=wanLinks
/interface list member
add interface=iot_vlan list=lanLinks
add interface=lanBridge list=lanLinks
add interface=wan0 list=wanLinks
add interface=wan1 list=wanLinks
/ip dhcp-client
add default-route-distance=100 disabled=no interface=wan0 use-peer-dns=no use-peer-ntp=no
add default-route-distance=100 disabled=no interface=wan1 use-peer-dns=no use-peer-ntp=no
/ip route
add comment=wan0 distance=50 gateway=66.215.192.1 routing-mark=to_wan0
add comment=wan1 distance=50 gateway=66.215.176.1 routing-mark=to_wan1
/ip firewall nat
add action=masquerade chain=srcnat out-interface=wan0
add action=masquerade chain=srcnat out-interface=wan1
/ip firewall mangle
add action=mark-connection chain=input comment=pcc_rule in-interface=wan0 new-connection-mark=wan0_conn passthrough=no
add action=mark-connection chain=input comment=pcc_rule in-interface=wan1 new-connection-mark=wan1_conn passthrough=no
add action=mark-routing chain=output comment=pcc_rule connection-mark=wan0_conn new-routing-mark=to_wan0 passthrough=no
add action=mark-routing chain=output comment=pcc_rule connection-mark=wan1_conn new-routing-mark=to_wan1 passthrough=no
add action=accept chain=prerouting comment=pcc_rule dst-address-list=privateNetworks in-interface-list=lanBridge
add action=accept chain=prerouting comment=pcc_rule dst-address-list=wanSubnets in-interface-list=lanBridge
add action=mark-connection chain=prerouting comment=pcc_rule dst-address-type=!local in-interface-list=lanLinks new-connection-mark=wan0_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/0
add action=mark-connection chain=prerouting comment=pcc_rule dst-address-type=!local in-interface-list=lanLinks new-connection-mark=wan1_conn passthrough=yes per-connection-classifier=both-addresses-and-ports:2/1
add action=mark-routing chain=prerouting comment=pcc_rule connection-mark=wan0_conn in-interface-list=lanLinks new-routing-mark=to_wan0 passthrough=yes
add action=mark-routing chain=prerouting comment=pcc_rule connection-mark=wan1_conn in-interface-list=lanLinks new-routing-mark=to_wan1 passthrough=yes
/ip firewall address-list
add address=192.168.0.0/16 list=privateNetworks
add address=172.16.0.0/16 list=privateNetworks
add address=10.0.0.0/8 list=privateNetworks
add address=66.215.192.0/22 comment=wan0 list=wanSubnets
add address=66.215.176.0/22 comment=wan1 list=wanSubnets
/ip firewall filter
add action=accept chain=Filter connection-state=established,related
add action=drop chain=Filter comment="Invalid packets (No valid current connection)" connection-state=invalid
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=!fin,!syn,!rst,!ack
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=fin,syn
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=fin,rst
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=fin,!ack
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=fin,urg
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=syn,rst
add action=drop chain=Filter comment="Invalid TCP flag combo" protocol=tcp tcp-flags=rst,urg
add action=drop chain=Filter comment="Invalid TCP source port (0)" protocol=tcp src-port=0
add action=drop chain=Filter comment="Invalid TCP destination port (0)" dst-port=0 protocol=tcp
add action=drop chain=Filter comment="Invalid UDP source port (0)" protocol=udp src-port=0
add action=drop chain=Filter comment="Invalid UDP destination port (0)" dst-port=0 protocol=udp
add action=return chain=Filter comment="Return to the chain that jumped"
add action=jump chain=input comment="Check for bad stuff in \"Filters\" chain" jump-target=Filter
add action=accept chain=input in-interface-list=lanLinks
add action=accept chain=input dst-port=22,8291 protocol=tcp
add action=drop chain=input in-interface-list=wanLinks
add action=jump chain=forward comment="Check for bad stuff in \"Filter\" chain" jump-target=Filter
add action=accept chain=forward in-interface=lanBridge out-interface-list=wanLinks
add action=accept chain=forward in-interface=iot_vlan out-interface-list=wanLinks
add action=drop chain=forward log=yes
This script need to run every few minutes. It will update your gateways and address lists with your current WAN gateway and subnets
# Dynamic IP Updater
:local wan0name "wan0";
:local wan1name "wan1";
:global wan0address;
:global wan1address;
:local wan0ip [/ip dhcp-client get [find interface="$wan0name"] value-name=address];
:if ($wan0address != $wan0ip) do={
:global wan0address [:pick $wan0ip 0 [:find $wan0ip "/"]];
:local wan0gateway [/ip dhcp-client get [find interface="$wan0name"] value-name=gateway];
:local wan0temp [/ip address get [find interface="$wan0name"] value-name=network ]
:local wan0subnet ($wan0temp . "/" . [:pick $wan0ip ([:find $wan0ip "/"]+1) [:len $wan0ip] ] )
/ip route set [find comment="wan0"] gateway=$wan0gateway;
/ip firewall address-list set [find comment="wan0"] address=$wan0subnet;
}
:local wan1ip [/ip dhcp-client get [find interface="$wan1name"] value-name=address];
:if ($wan1address != $wan1ip) do={
:global wan1address [:pick $wan1ip 0 [:find $wan1ip "/"]];
:local wan1gateway [/ip dhcp-client get [find interface="$wan1name"] value-name=gateway];
:local wan1temp [/ip address get [find interface="$wan1name"] value-name=network ]
:local wan1subnet ($wan1temp . "/" . [:pick $wan1ip ([:find $wan1ip "/"]+1) [:len $wan1ip] ] )
/ip route set [find comment="wan1"] gateway=$wan1gateway;
/ip firewall address-list set [find comment="wan1"] address=$wan1subnet;
}
I hope this helps simplify the Dual WAN / Dynamic IP PCC config for anything that needs it.
If it helped - I'd love some extra Karma points