Git Product home page Git Product logo

mikrotik-wireguard-ddns-reconnector's Introduction

MikroTik-WireGuard-DDNS-Reconnector

Description

This script is designed for MikroTik RouterOS devices and serves the purpose of handling WireGuard VPN connections in scenarios where peer domains are dynamic DNS (DDNS) addresses. It ensures the stability of the VPN connection by monitoring and restarting WireGuard peers, synchronizing connections with dynamic domain names. Ideal for environments requiring DDNS handling, such as mobile devices, home networks, etc.

Key Features

  • Automatically detects and restarts WireGuard connections
  • Handles scenarios where peer domains are dynamic DNS addresses
  • Specifically designed for MikroTik RouterOS devices

Usage

  1. Add the following script content to your MikroTik RouterOS device.
  2. Configure the dynamic DNS address for your WireGuard peer.
  3. The script will automatically monitor and maintain the connection.

Installation

  • Copy the following script content and execute it in the terminal:
/system/script/add name=wg-ddns source={
:foreach wg in=[/interface/wireguard/find disabled=no] do={
 :local peer [/interface/wireguard/get $wg name]
  :foreach i in=[/in/wireguard/peers/find interface=$peer endpoint-address~"[a-z]\$"] do={
    :local currentIP [/interface/wireguard/peers/get $i value-name=current-endpoint-addres]
    :local resolvedIP [:resolve [/interface/wireguard/peers/get $i value-name=endpoint-address]]
    :put "Checking $peer"
    :put "Current IP: $currentIP"
    :put "Resolved IP: $resolvedIP"
    :if ( $currentIP != $resolvedIP ) do={
      :put "IPs are not the same, restarting $peer"
      /in/wireguard/ disable $peer; :delay 1s; /in/wireguard/ enable  $peer;	
      };
    };
  };
}
/system/scheduler/add name=wg-ddns-scheduler interval=5m on-event=wg-ddns

mikrotik-wireguard-ddns-reconnector's People

Contributors

wminjay avatar

Stargazers

kevin cheng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.