Skip to content

Instantly share code, notes, and snippets.

@wannadrunk
Last active March 24, 2025 19:29
Show Gist options
  • Save wannadrunk/d3ea3f4f071a9d31fb1bfa16fd082be8 to your computer and use it in GitHub Desktop.
Save wannadrunk/d3ea3f4f071a9d31fb1bfa16fd082be8 to your computer and use it in GitHub Desktop.
Mikrotik script to reconnect the pppoe when get the private/nat IP from ISP, keep trying to get a public ip.
# Don't forget to change the "wanInterface" value below to your PPPoE interface
:global reconnectCount;
:local wanInterface "pppoe-out1";
:if ($"local-address" in 100.64 .0.0/10) do={
:if ($reconnectCount < 10) do={
:set reconnectCount ($reconnectCount+1);
:log warning ("$wanInterface: Got Private IP ".$"local-address"." Reconnecting the interface...");
/interface pppoe-client disable $wanInterface;
:delay 5s;
/interface pppoe-client enable $wanInterface;
} else={
:log error ("$wanInterface: Reconnect count exceeded, currently using ".$"local-address");
}
} else={
:set reconnectCount 0;
:log info ("$wanInterface: Got Public IP ".$"local-address");
}
@pakkalin
Copy link

ตรง 100.64 .0.0/10 ต้องลบ space ออกครับ

@wannadrunk
Copy link
Author

wannadrunk commented Nov 18, 2024

:global reconnectCount = 0;
:local wanInterface = "pppoe-out1";

:if ($"local-address" in 100.64.0.0/10) do={
    :if ($reconnectCount < 10) do={
        :set reconnectCount ($reconnectCount + 1);
        :log warning ("$wanInterface: Got Private IP ".$"local-address"." Reconnecting the interface...");

        /interface pppoe-client disable $wanInterface;
        :delay 5s;
        /interface pppoe-client enable $wanInterface;

        :log info ("$wanInterface: Reconnection attempt $reconnectCount completed.");
    } else={
        :log error ("$wanInterface: Reconnect count exceeded, currently using ".$"local-address". " Please check the connection manually.");
    }
} else={
    :set reconnectCount 0;
    :log info ("$wanInterface: Got Public IP ".$"local-address");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment