GithubHelp home page GithubHelp logo

madsbacha / routeros-vpn Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 58 KB

Automatically setup Private Internet Access (PIA) WireGuard VPN on your MikroTik router, and auto-update ephemeral connection whenever needed.

License: MIT License

RouterOS Script 100.00%
mikrotik privateinternetaccess vpn routeros

routeros-vpn's Introduction

Private Internet Access WireGuard VPN on MikroTik Router

This repository contains a RouterOS script for creating and maintaining a private internet access VPN, by configuring the necessary WireGuard interface and peer, address, and handling of reconfiguring the interface when the connection is lost, because of inactivity, thus reestablishing the connection to always maintain a working configuration.

Important

This repository is still in active development. That being said, the code from the main branch is actively being used, and should therefore be in a working state.

This script is verified to work on RouterOS version 7.14 and newer.

Features

  • Setup WireGuard interface for PIA VPN
  • Add PIA peer to WireGuard interface
  • Reconfigure WireGuard interface if connection is lost
  • Setup PIA assigned address for the WireGuard interface
  • Automatically setup src masquerading for outgoing traffic on the VPN interface
  • Verifies TLS certificate of the PIA servers against their self-signed CA certificate

TODO

  • Port forwarding through PIA VPN.
  • Consider possibilities for configuring PIA DNS in router.

Design

The script is setup to ensure that the specified WireGuard interface exists, i.e., it is created if it does not exist, and otherwise uses the existing one with that name. It does not modify the interface after creation, and only extracts the public key.

The program will ensure that only one peer exist on the interface, and that the peer is setup correctly for communicating with PIA. If no peer exist, one is created and any excess peers not needed for the connection is removed.

An address is setup for the WireGuard interface, which is updated whenever PIA assigns a new address to the WireGuard peer. If no address exist, one is created and any excess address configuration for the interface is removed.

Limitations

  • The program does not currently handle the DNS servers received by PIA. You will have to handle DNS setup yourself.
  • The API used for communicating with PIA is based on pia-foss/manual-connections, as PIA does not have official support for custom WireGuard config.

Getting Started

Note

The following "Getting Started" section is a temporary solution until the script is finished and a more elegant setup is created.

To get started, you need to setup the script vpn.rsc in your router, by going to System > Scripts, and create a new script with the source field set to the contents of vpn.rsc. The script only need the read, write, and test policies, and you can therefore disable the rest.

When inserted, edit the bottom of the file and change the parameters by filling in your PIA username and password, and possibly adjusting the PIA region and the interface name accordingly.

Lastly, setup a schedule to run the script every 15 minutes. This ensures the connection is checked every 15 minutes and reconfigured if the connection is down. Replace vpn-pia-berlin-1 in the following with what you named the above script.

/system/scheduler/add name="vpn-pia-berlin-1" interval=15m start-time=startup on-event="/system/script/run vpn-pia-berlin-1;";

Important

The script automatically creates the specified interface if it does not exist, and ensures a working VPN connection is setup through the WireGuard interface. Hereafter, it is your responsibility to configure the router to actually route any desired traffic through the interface.

Parameters

  • interface The name which the script uses for the WireGuard interface. The interface is created if none exist. Example: vpn-pia-berlin-1.
  • region The PIA server region to connect to. Example: de_berlin.
  • pia-username Your PIA username.
  • pia-password Your PIA password.
  • ping-address The address used for checking connectivity through the VPN connection. The address is pinged once to check connectivity. Default: 1.1.1.1.
  • servers-file-path Specifies a path for where to cache the PIA servers to. Default: pia-servers.txt.
  • pia-servers-ttl Specifies the duration of which the servers-file-path is kept before updated. If encountering problems connecting to PIA servers, try setting this to a lower value. Default: 24h.
  • masquerade Specifies whether to automatically create a src masquerade rule in your firewall. Default: true.
  • verify-pia-certificate Specifies whether to verify the TLS certificate of the PIA servers. Default: true.
  • install-pia-certificate Specifies whether to automatically install the PIA CA certificate for verifying PIA servers. Default: true.

routeros-vpn's People

Contributors

madsbacha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

s0lex l-g-t

routeros-vpn's Issues

SSL Verification -

Script appears to not skip SSL verification:

No existing DNS entry exist for bahamas401
Creating static DNS entry for bahamas401
Added static dns entry bahamas401
DEBUG | Calling method $DoDelay
Delaying 1s seconds
DEBUG | seconds = 1s
failure: SSL: ssl: name verification failed for: "CN=bahamas.privacy.network" (6)

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.