📖
Dokumentasi FreeDDNS
FreeDDNSEnglish
English
English
  • Intro
  • Crypto Payment
    • Introduction
    • Transfer From Other Exchange
    • Transfer From Binance
  • Tips - VPN REMOTE
    • How to choose VPN server
    • MikroTik Interface Watchdog
Powered by GitBook
On this page

Was this helpful?

  1. Tips - VPN REMOTE

MikroTik Interface Watchdog

This script helps ensure your MikroTik router's OpenVPN connection remains stable by checking the interface status directly, without relying on ICMP ping. If the OpenVPN interface is not running, it w

PreviousHow to choose VPN server

Last updated 2 months ago

Was this helpful?

🧠 Overview

This script scans all OpenVPN client interfaces and checks their connection status. If any interface is not running, it will be disabled and re-enabled automatically.


Script setup

you can choose to use basic script or the one with telegram notification

⚙️Basic Script (No Notifications)
# --- Loop through all OpenVPN client interfaces ---
:foreach id in=[/interface ovpn-client find] do={

    :local isRunning [/interface ovpn-client get $id running]

    :if ($isRunning = false) do={

        :local ifaceName [/interface ovpn-client get $id name]
        /log warning "$ifaceName is not running. Restarting..."

        /interface ovpn-client disable $id
        :delay 2s
        /interface ovpn-client enable $id
        :delay 5s
    }
}

🛠️ This script works automatically for all OpenVPN client interfaces on your router.

💡With Telegram Notification

This version adds Telegram notifications whenever an OpenVPN client interface is restarted.

🔧 Configuration

Replace the botToken and telegramId with your own values from your Telegram Bot:

# --- Configuration ---
:local botToken "123456:ABCdefGHIjklMNOpqrSTUvwxYZ"
:local telegramId "123456789"

# --- Loop through all OpenVPN client interfaces ---
:foreach id in=[/interface ovpn-client find] do={

    :local isRunning [/interface ovpn-client get $id running]

    :if ($isRunning = false) do={

        :local ifaceName [/interface ovpn-client get $id name]
        :local vpnServer [/interface ovpn-client get $id connect-to]

        /log warning "$ifaceName is not running. Restarting..."

        /interface ovpn-client disable $id
        :delay 2s
        /interface ovpn-client enable $id
        :delay 5s

        :local pingResult [/ping $vpnServer count=4]
        :local message "OpenVPN interface *$ifaceName* was restarted.\n Server: $vpnServer\n Ping: $pingResult"

        /tool fetch url=("https://api.telegram.org/bot$botToken/sendMessage?chat_id=$telegramId&text=$message&parse_mode=Markdown") keep-result=no
    }
}

🛡️ Security Tip: Keep your bot token private. You can also use [:uriencode $message] if message formatting ever breaks.

🕐 Scheduler Setup

To make this script run on a schedule:

  1. Go to System > Scheduler, and create a new scheduler named ovpn-client watchdog or whatever that you like

  2. Paste the desired script (Basic or Telegram version).


✅ What This Script Does

Condition
Action

VPN is running

No action

VPN is down

Restarts interface

Telegram enabled

Sends alert message


🧪 Testing the Script

  • Temporarily disable your OpenVPN interface

  • Watch the Logs and your Telegram for confirmation.

dont forget to click apply and ok after you finish