20 ธันวาคม 2565

Mikrotik script :: Add default route to wireguard for dynamic wan ip

RouterOS7

wireguard server public ip 10.0.0.1
wireguard server private ip 192.168.0.1

/ip route add dst-address=0.0.0.0/0 gateway=192.168.0.1 scope=10 check-gateway=ping

Change dhcp-client "Default Route Distance" to 5 
#### script dhcp-client

:if ($bound=1) do={    
    /ip route remove [/ip route find comment="route-wireguard-wan"]
    /ip route add gateway=$"gateway-address" dst-address="10.0.0.1" scope=10  comment="route-wireguard-wan"
} else={
    /ip route remove [/ip route find comment="route-wireguard-wan"]
}