How igorkha/wireguard-mikrotik works
Purpose and execution
This repository is a single-host Bash CLI generator for configuring a WireGuard VPN server on MikroTik. Its only application entry point is wireguard-mikrotik.sh, run interactively as superuser. It generates MikroTik RouterOS import scripts plus per-client WireGuard configurations and QR codes; it does not configure MikroTik directly.
Runtime and dependencies
The runtime is Bash on Ubuntu, Debian, Fedora, CentOS, Arch, Oracle Linux, and experimentally macOS via Homebrew. Core external executables are wireguard-tools for key/config operations and qrencode for client QR artifacts. The generated VPN design tunnels client traffic through the MikroTik server, whose NAT exposes the server’s public IP. Implementation: wireguard-mikrotik.sh.
Interactive orchestration
wireguard-mikrotik.sh owns the full control flow: environment/privilege validation, interactive collection of interface/server parameters, and selection between creating a server or adding clients to an existing interface. Re-running the script is the intended lifecycle mechanism for extending an existing server’s client set.
Server configuration generation
For each named WireGuard interface, the script creates persistent local state under a generated wireguard/<interface>/ tree. It emits:
• a server WireGuard configuration (wg0.conf-style),
• retained parameter/state data (params),
• a RouterOS script under mikrotik/<interface>.rsc.
The RouterOS output is a deployment boundary: operators paste/import it into MikroTik rather than invoking a router API. Source generator: wireguard-mikrotik.sh.
Client provisioning
Client creation is a subordinate stage of the same script. Each client receives an isolated directory beneath wireguard/<interface>/client/<user>/, containing:
• a standard client .conf,
• a QR-encoded .png,
• a MikroTik peer .rsc for server-side peer registration.
This separates endpoint onboarding material from the base interface script while retaining all generated credentials/configuration locally. Generator: wireguard-mikrotik.sh.
Network and protocol boundaries
WireGuard is the cryptographic tunnel protocol; generated configs support IPv4 and IPv6. MikroTik RouterOS is the server-side target and applies NAT for tunneled client egress. Client config files and QR images are endpoint-facing outputs, while RouterOS .rsc files cross the administrator-to-router operational boundary. Primary implementation: wireguard-mikrotik.sh.
Repository shape
The repository deliberately concentrates product behavior in wireguard-mikrotik.sh; GitHub workflows and pre-commit files govern contribution hygiene rather than runtime architecture. Generated wireguard/ state is created beside the script at execution time and is not represented as checked-in source.
Main entry points: wireguard-mikrotik.sh Bash CLI generator
Components 15
Local generator
- Administrator · Runs the generator interactively as superuser.
- Bash CLI generator · Owns validation, prompts, server creation, and client extension.
wireguard-mikrotik.sh - wireguard-tools · Generates WireGuard keys and configuration material.
- qrencode · Produces client QR PNG artifacts.
- Client provisioning · Adds clients when creating or extending an interface.
wireguard-mikrotik.sh
Generated local artifacts
- Interface state · Retained parameters and credentials for a named interface.
- Server WireGuard config
- Base RouterOS script · Operator imports this to create the server interface and base rules.
- Client onboarding bundle · Isolated per-user endpoint and peer-registration material.
- Client WireGuard config · IPv4/IPv6 tunnel configuration for an endpoint.
- Client QR image
- Peer RouterOS script · Registers an individual client peer on the router.
VPN deployment
- MikroTik RouterOS · Applies imported scripts and NAT for tunneled client egress.
- WireGuard tunnel · Cryptographic IPv4/IPv6 tunnel between clients and MikroTik.
- Public IP egress · Client traffic exits through MikroTik NAT.
Connections 17
- Administrator → Bash CLI generator: runs interactively
- Bash CLI generator → wireguard-tools: uses
- Bash CLI generator → qrencode: uses
- Bash CLI generator → Interface state: creates and reuses
- Bash CLI generator → Server WireGuard config: emits
- Bash CLI generator → Base RouterOS script: emits
- Bash CLI generator → Client provisioning: invokes
- Client provisioning → Client onboarding bundle: creates
- Client provisioning → Client WireGuard config: emits
- Client provisioning → Client QR image: encodes
- Client provisioning → Peer RouterOS script: emits
- Base RouterOS script → MikroTik RouterOS: paste or import
- Peer RouterOS script → MikroTik RouterOS: paste or import
- Server WireGuard config → WireGuard tunnel: defines server side
- Client WireGuard config → WireGuard tunnel: defines endpoint side
- MikroTik RouterOS → WireGuard tunnel: terminates
- WireGuard tunnel → Public IP egress: routes through NAT