Switch ISPs

Sometimes it’s useful to have more than one ISP account. These scripts make it easier to switch between them, and also help configure other parts of the system (like the bandwidth management).

This is set up for two accounts, but it is trivial to add more.

The scripts assume you have already configured PPPOE clients under Interfaces. Use pppoe-out1 for ISP1, pppoe-out2 for ISP2, etc.

You can schedule the scripts to switch accounts as necessary, or manually execute them.

# switch_isp1
# Switch to ISP1
:local alreadyup false;
:global unotellyUpdateRequired;

:if ([/interface get pppoe-out1 value-name=running] && !$alreadyup) do={
  :set alreadyup true;
}

if (!$alreadyup) do={
   :put [/interface pppoe-client disable pppoe-out2]
   :put [/interface pppoe-client enable pppoe-out1]
   :log info "Switched to ISP1"
   :set unotellyUpdateRequired true;
   :delay 10s;
   :put [/system script run unotelly_update]
   # The below line adjusts the parent of the bandwidth queue tree I have set
   # up. This account max speed is 6mbit
   :put [/queue tree; set [find name=ppp_download] queue=max_download_6m]
} else={ :log info "Already on ISP1, no switch necessary" }
# switch_isp2
# Switch to ISP2
:local alreadyup false;
:global unotellyUpdateRequired;

:if ([/interface get pppoe-out2 value-name=running] && !$alreadyup) do={
  :set alreadyup true;
}

if (!$alreadyup) do={
   :put [/interface pppoe-client disable pppoe-out1]
   :put [/interface pppoe-client enable pppoe-out2]
   :log info "Switched to ISP2"   
   :set unotellyUpdateRequired true;
   :delay 10s;
   :put [/system script run unotelly_update]
   # The below line adjusts the parent of the bandwidth queue tree I have set
   # up. This account max speed is unlimited, but my line max speed is 10mbit.
   :put [/queue tree; set [find name=ppp_download] queue=max_download_10m]
} else={ :log info "Already on ISP2, no switch necessary" }