Running Gateway on MikroTik routers

By leveraging the ability of some MikroTik routers to run Docker containers, it is possible to deploy the gateway directly on your router.

Prerequisites

  • RouterOS device with ARM or ARM64 architecture (popular home lab choices include RB4011 or RB5009)

  • Container package installed and enabled

  • Running Defguard core instance with a WireGuard location configured

  • (optional) Self-signed certificate generated by following gRPC SSL setup guide

Setup

For brevity we'll be using RouterOS terminal commands, but everything can also be accomplished through WinBox GUI.

Prepare network to install Docker container

  • First create a bridge interface for Docker containers and assign it an IP address in a dedicated Docker subnet (172.17.0.0/24 in our example):

  • Each container must have a dedicated VETH interface; create a veth1 interface and assign it an IP address in the chosen Docker subnet:

  • Add the virtual interface to the Docker bridge:

Setup firewall rules

  • Set up NAT for outgoing traffic from containers:

  • Add port forwarding rule to send UDP traffic from the public WireGuard port to the gateway container:

  • Add routing for your chosen WireGuard subnet configured in Defguard UI location settings:

Run gateway container

  • Configure environment variables for the gateway container:

  • (optional) To use SSL for communication between the gateway and your Defguard instance copy the root certificate to your router's filesystem and add a following mount and environment variable:

  • Add GitHub container registry to config:

  • Finally, create the actual container:

At this point you should see that the gateway is connected in your Defguard instance's web UI.

Was this helpful?