„src/change-default-gw.md“ hinzufügen

Signed-off-by: Theenoro <theenoro@noreply.git.dev-c.at>
main
Theenoro 2022-09-04 18:55:12 +02:00
parent 44c729dda9
commit 6759120a1d
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
# Change default GW
## Preparing
- `MAINGW` is your main route where all traffic goes
- `DSL` is default route to your DSL router, set the distance there to 2, and set the comment `DSL`
- `LTE` is default route to your LTE router, set the distance there to 2, and set the comment `LTE`
- set one route to 1.1.1.1 to your DSL router
The script will set the `DSL` GW IP on the `MAINGW` if 1.1.1.1 is reachable, if not it will change to LTE
```perl
:local PingTargetOne 1.1.1.1
:local FailThreshholdOne 3
:global PingFailCountOne
:local maingw [/ip route get [find comment="MAINGW"] gateway ];
:local dslgw [/ip route get [find comment="DSL"] gateway ];
:local ltegw [/ip route get [find comment="LTE"] gateway ];
:set $PingResult [ping 1.1.1.1 count=1]
:put $PingResult
:if ($PingResult = 0) do={
:if ($PingFailCountONE < ($FailTresholdOne+2)) do={
:set $PingFailCountOne ($PingFailCountOne + 1)
:log warning "HMM Ping to $PingTargetONE failed."
:if ( PingFailCountOne >= $FailTreshold) do={
:log warning "Ping Failed."
/ip route set [find comment="MAINGW"] gateway=$ltegw;
}
}
}
:if ($PingResult = 1) do={
:if ($PingFailCountOne > 0) do={
:set PingFailCountOne 0
:log info "Reset route to DSL"
/ip route set [find comment="MAINGW"] gateway=$dslgw;
}
}
```