# MikroTik WireGuard VPN: Dual-Stack IPv4/IPv6 Configuration

> One post from jmrp.io, published as its own document. Index: https://jmrp.io/llms-full.txt

Canonical: https://jmrp.io/blog/007-mikrotik-wireguard-dual-stack-vpn/
Language: en
Alternate: https://jmrp.io/es/blog/007-mikrotik-wireguard-dual-stack-vpn/index.md
License: https://creativecommons.org/licenses/by/4.0/
Type: TechArticle
Published: 2026-02-14
Updated: 2026-11-07
Instructions re-tested: 2026-11-07 · RouterOS 7.25 · RB5009UG+S+
Author: José Manuel Requena Plens
Summary: Configure WireGuard VPN on MikroTik RouterOS with full IPv4/IPv6 dual-stack. Access your home network with native IPv6 from any connection.
Tags: MikroTik, Networking, IPv6, Security
Topics: WireGuard (Q28975568), MikroTik (Q913580), RouterOS (Q12036888), Virtual private network (Q170963), IPv6 (Q2551624), Network address translation (Q11182)
Build-Date: 2026-11-14

Questions answered:

**What RouterOS version do I need for WireGuard on MikroTik?**

WireGuard has been built into RouterOS since version 7. For what this guide uses: the client-* peer properties behind the QR code exist since RouterOS 7.12 (client-allowed-address since 7.21), peer names since 7.15 and client-mtu since 7.25, so 7.15 is the practical minimum, and client-allowed-address and client-mtu are optional. The guide is tested on RouterOS 7.25 on an RB5009 and applies to any MikroTik router running 7.15 or later.

**Why use a ULA prefix and NAT66 for IPv6 instead of global addresses?**

VPN clients get private Unique Local Addresses (ULA) in the fd00::/8 range, which are guaranteed not to conflict with public IPv6 addresses. The router then NAT66-translates them to your ISP-assigned global IPv6 prefix when clients access the internet.

**Why use a non-standard WireGuard port like 53537 instead of 51820?**

Using a non-standard port instead of the default 51820 helps avoid automated scans targeting common VPN ports. Some networks also block standard VPN ports, so a high random port may offer better connectivity.

**What is the difference between full tunnel and split tunnel?**

Full tunnel (AllowedIPs = 0.0.0.0/0, ::/0) routes all traffic through the VPN, hiding your location but adding latency. Split tunnel routes only specific networks (like your home LAN) through the VPN, giving better performance for general internet use.

**What MTU should a WireGuard tunnel on MikroTik use?**

Your WAN's actual-mtu minus 60 if the endpoint is IPv4-only and no client roams, or minus 80 if clients can reach it over IPv6: an IPv6 or dual-stack endpoint, or a phone on an IPv6-only mobile network, which reaches even an IPv4 endpoint over IPv6 through 464XLAT. With an IPv6 or dual-stack endpoint, a 1500 WAN gives 1420, standard PPPoE at 1492 gives 1412, and DIGI's PPPoE at 1480 gives 1400. Then add one MSS clamp per inner family, MTU minus 40 for IPv4 and MTU minus 60 for IPv6, and set MTU = in every client configuration, because the iOS and Android apps fall back to 1280 without it.

**Should persistent-keepalive go on the WireGuard client or on the router?**

On the side behind NAT, which is the client: PersistentKeepalive = 25 in its configuration, which the router can publish with client-keepalive=25. On the router, leave persistent-keepalive off for roaming clients, because otherwise the router keeps retrying handshakes against the client's last known endpoint long after the client has moved or powered off. RouterOS also has responder=yes, which stops the router initiating handshakes at all; I tried it and reverted it because it made my iPhone's tunnel drop on network changes.

**Does IPv6 over the VPN work if my ISP doesn't provide IPv6?**

No global IPv6 internet access. NAT66 translates the client's ULA address to your ISP's global IPv6 prefix, so without an ISP prefix there is nothing to translate to. The tunnel itself still carries IPv6 between client and router, but no further.


Steps (Configure a dual-stack WireGuard VPN on MikroTik RouterOS):
1. Create the WireGuard interface
2. Assign IPv4 and IPv6 addresses
3. Add the interface to interface lists
4. Configure firewall rules
5. Configure NAT/masquerade
6. Calculate the MTU and clamp MSS
7. Add WireGuard peers (clients)
8. Configure the client and verify the connection

---

[WireGuard](https://www.wireguard.com/) has revolutionized VPN technology with its simplicity, speed, and modern cryptography. Unlike traditional VPN protocols like [OpenVPN](https://openvpn.net/) or [IPSec](https://datatracker.ietf.org/doc/html/rfc7296), WireGuard uses a minimal codebase (~4,000 lines vs 100,000+) and state-of-the-art cryptographic primitives as described in the [WireGuard whitepaper](https://www.wireguard.com/papers/wireguard.pdf), resulting in faster connections and lower latency.

This guide demonstrates how to configure a **production-ready WireGuard VPN** on MikroTik RouterOS with **dual-stack IPv4/IPv6 support**. The result? You can connect from any network, even one without IPv6, and enjoy full IPv6 connectivity through your home router.

## TL;DR: dual-stack WireGuard on RouterOS

- **WireGuard is built into RouterOS 7**, so a dual-stack VPN server needs no container and no extra package. The interface listens on a high non-standard UDP port (**53537** here, not the default 51820, to sidestep automated scans) and each peer gets one IPv4 and one IPv6 address.
- **IPv6 goes through ULA plus NAT66, not a delegated prefix.** Clients receive `fd00::/8` addresses that the router translates to your ISP's global prefix, so the tunnel survives the prefix changing underneath it.
- **Size the tunnel from the WAN, then clamp MSS per family.** The tunnel MTU is your WAN's `actual-mtu` minus 60 (IPv4-only endpoint, clients that never roam) or minus 80 (IPv6 or dual-stack endpoint): 1400 on my 1480 PPPoE link, 1420 on a 1500 one. Then two clamps, `/ip` at the MTU − 40 and `/ipv6` at the MTU − 60, and `MTU =` in every client config, because iOS and Android fall back to 1280 without it.
- **The keepalive goes on the client, not on the router.** `PersistentKeepalive = 25` on the client keeps its NAT mapping open; a `persistent-keepalive` on the router's peers makes it retry handshakes forever against a roaming client's dead endpoint. I also tried `responder=yes` and reverted it: it made my iPhone's tunnel drop on network changes.
- **Each device gets its own key pair and address pair.** Revoking one client is deleting one peer; nothing else has to be reissued.
- **Split tunnel is an `AllowedIPs` decision on the client**, not a server setting: list only the home prefixes to route home traffic, or `0.0.0.0/0, ::/0` to route everything.
- **Tested on RouterOS 7.25 on an RB5009.** The minimum is 7.15, which added peer names; `client-allowed-address` needs 7.21 and `client-mtu` 7.25, and both are optional.

**Important: Values You Must Customize**

Throughout this guide, values that **you must replace** with your own are clearly marked. Look for:

- **`wg_devices`**: WireGuard interface name (customize if you prefer a different name)
- **`53537`**: WireGuard listen port (choose any unused UDP port)
- **`mtu=1400`**: tunnel MTU, your WAN's `actual-mtu` minus 80 (1400 is for my 1480 PPPoE link; [Step 7](#step-7-calculate-the-mtu-and-clamp-mss) shows how to calculate yours). The values derived from it change with it: the MSS clamps `1360` (IPv4) and `1340` (IPv6), and `MTU = 1400` in the client configs
- **`192.168.100.0/24`**: VPN IPv4 subnet (change if it conflicts with your network)
- **`fd00:1111:2222:100::/64`**: VPN IPv6 ULA prefix (generate your own at [unique-local-ipv6.com](https://www.unique-local-ipv6.com/))
- **`192.168.0.0/24`**: Your home LAN subnet (adjust to match your network)
- **Client keys**: Always generate unique keypairs per device
- **`your-domain.com`**: Your public IP or DDNS hostname

---

## Does RouterOS WireGuard support IPv6?

Yes. WireGuard ships in RouterOS 7 as a built-in interface type and carries IPv6
natively: you assign an IPv6 address to the WireGuard interface and give each peer
its own IPv6 `allowed-address`. The catch is addressing: this guide uses a ULA
prefix plus NAT66 instead of a delegated prefix, so the tunnel survives your ISP
renumbering underneath it.

---

## How I run this on my own infrastructure

The configuration in this guide isn't a lab exercise: it's the WireGuard setup I run on my own RB5009UG+S+ with RouterOS 7.25, using the same interface layout as this guide. My WAN is DIGI's PPPoE, which negotiates `actual-mtu=1480` (the [DIGI PPPoE guide](https://jmrp.io/blog/008-mikrotik-pppoe-dualstack-digi/) explains why it is 1480 and not 1500), so every MTU and MSS value in this guide is the one for that link: tunnel MTU 1400, MSS 1360 for IPv4 and 1340 for IPv6. The RouterOS version each guide was last checked against is stamped at the top of its own page, which is why the same router shows a different version here and in [the honeypot guide](https://jmrp.io/blog/006-implementing-mikrotik-honeypot/).

Getting to those values was not a straight line. On 8 September 2026 I lowered the tunnel to MTU 1400 and the IPv4 clamp to `new-mss=1340`, and added no IPv6 clamp. At 03:10 the next morning I put the MTU back to 1500 from my phone, because I noticed problems I never pinned down, and on 11 September 2026 I reverted the clamp too. My best explanation, which I have not proven, is IPv6: the only IPv6 clamp on the router was a generic rule at 1348, and an IPv6 TCP packet carrying a 1348-byte segment is 1408 bytes (1348 + 40 + 20), which does not fit a 1400 tunnel. It gets through only if the ICMPv6 "Packet Too Big" reaches the origin server and the server acts on it; otherwise the download hangs. That would hit the clients whose own MTU is above 1400 (the Macs, at 1420 in automatic mode, and a router that works as a VPN client, giving the devices behind it a tunneled connection with nothing to configure on them), and not the iPhone, which sits at 1280. On 7 November 2026 I applied the values again, this time with the IPv6 rule from Step 7, and measured them: the numbers are in [What I measured on my router](#what-i-measured-on-my-router).

The keepalive advice has its own story. On 27 October 2026 I found the router retrying handshakes every ~5 seconds towards addresses that no longer answered: that VPN-client router, powered off since 19 September, and a MacBook. That came to around 1,140 log lines an hour in Loki, and both peers had `persistent-keepalive` set on the router side. I removed it there and left the keepalive on the clients, and those retries stopped.

Not all of them, though. Without a keepalive the router still starts a handshake when it has traffic for a peer whose session has lapsed, and in the week up to 7 November that added up to 622 failed retries towards my iPhone. In the burst I traced, the router kept knocking for a minute and a half on the port the phone had last used, until the phone reconnected by itself from the same mobile address and a new port. So on 7 November 2026 I set `responder=yes` on every peer, the property RouterOS documents for routers that only serve clients, so that the router would never start a handshake. It did what it promised: the clients renewed their sessions on their own and the router started none. But my iPhone's tunnel dropped with every small change of network, and I reverted it the same afternoon. The router's logs don't show why: the network switches looked the same with and without it. My best guess is the one case they cannot show, the router reopening a session towards a phone that has gone quiet, which is exactly what `responder=yes` forbids. So the router keeps no keepalive and no `responder`, and a few hundred failed retries a week are the price of a tunnel that holds.

---

## Why WireGuard on MikroTik?

**VPN Protocol Comparison**

| Feature | WireGuard | OpenVPN | IPSec/IKEv2 |
| --- | --- | --- | --- |
| Code complexity | ~4,000 lines | ~100,000 lines | ~400,000 lines |
| Connection time | 100ms | 3-10 seconds | 1-3 seconds |
| CPU overhead | Very low | High (userspace) | Medium |
| Cryptography | ChaCha20, Curve25519 | Configurable (varies) | AES, RSA/ECDH |
| Roaming support | Seamless | Reconnection needed | Limited (MOBIKE) |

**Tip: Mobile-Friendly Design**

WireGuard excels on mobile devices. When you switch from Wi-Fi to cellular or change networks, WireGuard reconnects instantly without dropping your session. This "roaming" capability makes it ideal for smartphones and laptops.

---

## How do the IPv4 and IPv6 halves fit together?

Our configuration creates a dual-stack VPN where connected clients receive both IPv4 and IPv6 addresses. Traffic from clients is NAT'd (masqueraded) to access the internet through your home connection. For detailed [MikroTik WireGuard documentation](https://help.mikrotik.com/docs/spaces/ROS/pages/69664792/WireGuard), refer to the official wiki.

**WireGuard Dual-Stack Architecture**

```mermaid
flowchart TB
    subgraph Internet
        WAN[ISP Connection<br/>IPv4 + IPv6]:::info
    end
    
    subgraph MikroTik["MikroTik Router"]
        WG[WireGuard Interface<br/>wg_devices]:::highlight
        FW[Firewall + NAT]:::warning
    end
    
    subgraph VPN_Clients["VPN Clients"]
        Client1[Client 1<br/>192.168.100.2<br/>fd00:...:100::2]:::secondary
        Client2[Client 2<br/>192.168.100.3<br/>fd00:...:100::3]:::secondary
        ClientN[Client N<br/>192.168.100.x<br/>fd00:...:100::x]:::secondary
    end
    
    subgraph Home["Home Network"]
        LAN[LAN Devices<br/>192.168.0.0/24]:::success
    end
    
    Client1 & Client2 & ClientN -->|Encrypted Tunnel| WG
    WG --> FW
    FW -->|Masquerade| WAN
    FW <-->|Access| LAN
```

### Network addressing scheme

**IP Address Assignment**

| Component | IPv4 Address | IPv6 Address |
| --- | --- | --- |
| WireGuard Interface (Router) | `192.168.100.1/24` | `fd00:1111:2222:100::1/64` |
| VPN Client Range | `192.168.100.2-254` | `fd00:1111:2222:100::2-ffff` |
| Home LAN | `192.168.0.0/24` | ISP-assigned prefix |

**Info: Why ULA for IPv6?**

We use [Unique Local Addresses (ULA)](https://datatracker.ietf.org/doc/html/rfc4193) in the `fd00::/8` range for the VPN. These addresses are private (like RFC1918 for IPv4) and guaranteed not to conflict with public IPv6 addresses. The router then NAT66 translates them to your ISP-assigned global IPv6 prefix.

---

## Prerequisites

**Before You Start**

- **MikroTik RouterOS 7.15** or later (WireGuard is built in since RouterOS 7; the `client-*` peer properties behind the QR code arrived in 7.12 and peer names in 7.15. `client-allowed-address` needs 7.21 and `client-mtu` 7.25, both optional)
- **Public IP address** (static) or **Dynamic DNS** (DDNS) configured on your router
- **IPv6 connectivity** from your ISP (optional but recommended for dual-stack)
- **UDP port forwarding** capability if your MikroTik is behind another router/NAT
- **Administrative access** to your MikroTik router (via WinBox, WebFig, or SSH)
- **Interface lists** already created: `WAN` (for internet-facing interfaces) and `LAN` (for local network interfaces). These are part of the default MikroTik configuration

---

## Step 1: create the WireGuard interface

First, we create the WireGuard interface on the MikroTik router. The router will generate a keypair automatically.

**Create WireGuard Interface**

```routeros
/interface wireguard add \
    name=wg_devices \
    mtu=1400 \
    listen-port=53537 \
    comment="VPN for Mobile Devices"
```

`mtu=1400` is for my WAN, a DIGI PPPoE link that negotiates `actual-mtu=1480`. [Step 7](#step-7-calculate-the-mtu-and-clamp-mss) shows how to calculate yours: your WAN's `actual-mtu` minus 80, which gives 1420 on a 1500 WAN, the same value RouterOS uses by default.

**Tip: Port Selection**

Using a non-standard port like `53537` instead of the default `51820` helps avoid automated scans targeting common VPN ports. Some networks also block standard VPN ports, so a high random port may have better connectivity.

### Retrieve the server's public key

After creating the interface, retrieve the public key to configure clients:

**Terminal session — Retrieve Server Public Key**

```routeros
/interface wireguard print
```

**Output**

```text
Flags: X - disabled; R - running
 0  R name="wg_devices" mtu=1400 listen-port=53537
      private-key="[REDACTED]"
      public-key="YourServerPublicKeyHere123456789ABCDEFGHIJ="
```

Save the `public-key` value: you'll need it when configuring client devices.

---

## Step 2: assign IP addresses to the interface

The WireGuard interface needs both IPv4 and IPv6 addresses to serve as the gateway for VPN clients.

**Assign IP Addresses**

```routeros
# IPv4 address for WireGuard interface
/ip address add \
    address=192.168.100.1/24 \
    interface=wg_devices \
    network=192.168.100.0 \
    comment="VPN Devices Network"

# IPv6 ULA address for WireGuard interface
/ipv6 address add \
    address=fd00:1111:2222:100::1/64 \
    interface=wg_devices \
    advertise=no \
    comment="VPN Devices IPv6 ULA"
```

**Warning: IPv6 Advertise Setting**

Set `advertise=no` for the WireGuard IPv6 address. We don't want Router Advertisements on the VPN tunnel: clients receive their static addresses through the WireGuard configuration, not SLAAC.

---

## Step 3: create IPv6 pool (optional)

If you want to manage IPv6 address allocation centrally, create a pool:

**Create IPv6 Pool**

```routeros
/ipv6 pool add \
    name=wg_devices_pool_global \
    prefix=fd00:1111:2222:100::/64 \
    prefix-length=64 \
    comment="WireGuard Devices Global IPv6 Pool"
```

---

## Step 4: add the interface to interface lists

MikroTik uses interface lists for firewall rules. Adding WireGuard to the appropriate lists ensures proper traffic handling.

**Add to Interface Lists**

```routeros
# Add to VPN list for VPN-specific rules
/interface list member add \
    interface=wg_devices \
    list=VPN \
    comment="VPN Devices"

# Add to LAN list to allow access to local resources
/interface list member add \
    interface=wg_devices \
    list=LAN \
    comment="VPN Devices - LAN Access"
```

---

## Step 5: configure firewall rules

The firewall configuration is critical for security and connectivity. We need rules for:

1. **Accepting WireGuard traffic** on the listening port
2. **Allowing VPN clients** to access the internet
3. **Allowing VPN clients** to access local networks
4. **NAT/Masquerade** for outbound traffic

**Warning: Firewall Rule Placement**

MikroTik processes firewall rules **top to bottom**. The rules below must be placed **before** any `drop` rules in their respective chains. Use the `place-before` parameter or reorder rules in WinBox after adding them.

If you use the default MikroTik firewall, add these rules near the top of each chain, after the `established,related` accept rules.

### Input chain: accept WireGuard connections

**Firewall Input Rules**

```routeros
# Allow WireGuard UDP port (IPv4)
/ip firewall filter add \
    chain=input \
    action=accept \
    protocol=udp \
    dst-port=53537 \
    comment="WireGuard - Accept incoming connections"

# Allow WireGuard UDP port (IPv6)
/ipv6 firewall filter add \
    chain=input \
    action=accept \
    protocol=udp \
    port=53537 \
    comment="Allow WireGuard"
```

### Forward chain: allow VPN traffic

**Firewall Forward Rules - IPv4**

```routeros
# FastTrack for established WireGuard connections (performance)
/ip firewall filter add \
    chain=forward \
    action=fasttrack-connection \
    connection-state=established,related \
    src-address-list=WireGuard \
    comment="FastTrack for WireGuard Networks"

# Allow VPN clients to internet
/ip firewall filter add \
    chain=forward \
    action=accept \
    src-address=192.168.100.0/24 \
    out-interface-list=WAN \
    comment="Allow WireGuard Devices to Internet"

# Allow return traffic from internet to VPN
/ip firewall filter add \
    chain=forward \
    action=accept \
    connection-state=established,related \
    dst-address=192.168.100.0/24 \
    in-interface-list=WAN \
    comment="Allow Internet to WireGuard Devices (replies)"

# Allow VPN clients to Home LAN
/ip firewall filter add \
    chain=forward \
    action=accept \
    src-address=192.168.100.0/24 \
    dst-address=192.168.0.0/24 \
    comment="Allow WireGuard Devices to Home LAN"
```

**Firewall Forward Rules - IPv6**

```routeros
# Allow VPN clients all outbound IPv6 traffic
/ipv6 firewall filter add \
    chain=forward \
    action=accept \
    in-interface=wg_devices \
    comment="WireGuard Devices: Allow all outbound"

# Allow return IPv6 traffic to VPN clients
/ipv6 firewall filter add \
    chain=forward \
    action=accept \
    connection-state=established,related \
    out-interface=wg_devices \
    comment="WireGuard Devices: Allow replies"
```

### Create address list for WireGuard networks

**Address Lists**

```routeros
/ip firewall address-list add \
    list=WireGuard \
    address=192.168.100.0/24 \
    comment="WireGuard Devices Network"
```

---

## Step 6: configure NAT/Masquerade

For VPN clients to access the internet, their private addresses must be translated (NAT) to your public IP.

**NAT Configuration**

```routeros
# IPv4 Masquerade for WireGuard
/ip firewall nat add \
    chain=srcnat \
    action=masquerade \
    src-address=192.168.100.0/24 \
    out-interface-list=WAN \
    comment="WireGuard Devices - Internet Access"

# IPv6 NAT66 for WireGuard (ULA to Global)
/ipv6 firewall nat add \
    chain=srcnat \
    action=masquerade \
    src-address=fd00:1111:2222:100::/64 \
    out-interface-list=WAN \
    comment="WireGuard Devices - IPv6 Internet Access"
```

**Info: NAT66 Explained**

Traditional IPv6 philosophy discourages NAT, preferring end-to-end connectivity. However, NAT66 (masquerade for IPv6) is practical for VPNs using ULA addresses. Your VPN clients use private ULA addresses, which are translated to your [ISP-assigned global IPv6 prefix](https://jmrp.io/blog/008-mikrotik-pppoe-dualstack-digi/) when accessing the internet.

---

## Step 7: calculate the MTU and clamp MSS

WireGuard wraps every packet a client sends or receives in a new, encrypted outer packet, and it is the outer packet that has to fit through your WAN. So the tunnel MTU comes from the WAN, not the other way round, and RouterOS will not work it out for you: the interface uses whatever `mtu` you give it, even one whose outer packets cannot fit. An outer packet that is too large is fragmented at the IP layer, which costs CPU at both ends and breaks on paths that drop fragments. TCP MSS clamping then keeps TCP segments inside that MTU.

### What WireGuard adds to every packet

Each WireGuard data packet is the encrypted inner packet between a fixed header (outer IP, UDP and the WireGuard data header) and a fixed trailer (the Poly1305 tag). Everything except the inner packet is overhead, and the tunnel MTU is the size of the largest inner packet:

**WireGuard overhead in bytes, by outer family**

| Part | Outer IPv4 | Outer IPv6 |
| --- | --- | --- |
| Outer IP header | 20 | 40 |
| UDP header | 8 | 8 |
| WireGuard data header (type, receiver index, counter) | 16 | 16 |
| Poly1305 authentication tag | 16 | 16 |
| **Total overhead** | **60** | **80** |

### Outer family sets the MTU, inner family sets the MSS

**Tunnel MTU and MSS**

```text
path MTU    = min(server WAN MTU, client-side path MTU)
tunnel MTU  = path MTU - overhead(outer family)   # 60 for IPv4, 80 for IPv6
MSS (IPv4)  = tunnel MTU - 40                     # 20 IPv4 + 20 TCP
MSS (IPv6)  = tunnel MTU - 60                     # 40 IPv6 + 20 TCP
```

Two address families are in play here, and they decide different things:

- **The outer family** is the family of the encrypted packet that crosses the internet between the client and your WAN. It decides the overhead (60 or 80) and therefore the **MTU**.
- **The inner family** is the family of your traffic inside the tunnel. It decides **which MSS** applies (MTU − 40 for IPv4, MTU − 60 for IPv6) and **which table the clamp goes in**: `/ip firewall mangle` for IPv4, `/ipv6 firewall mangle` for IPv6. `/ip firewall mangle` never sees an IPv6 packet, so a dual-stack tunnel needs both rules.

### Reference values for common WAN links

**Tunnel MTU and MSS by WAN MTU and outer family**

| WAN MTU | Outer family | Tunnel MTU | MSS, inner IPv4 | MSS, inner IPv6 |
| --- | --- | --- | --- | --- |
| 1500 (Ethernet, fiber) | IPv4 | 1440 | 1400 | 1380 |
| 1500 (Ethernet, fiber) | IPv6 | **1420** | 1380 | 1360 |
| 1492 (standard PPPoE) | IPv4 | 1432 | 1392 | 1372 |
| 1492 (standard PPPoE) | IPv6 | **1412** | 1372 | 1352 |
| 1480 (DIGI's PPPoE, mine) | IPv4 | 1420 | 1380 | 1360 |
| 1480 (DIGI's PPPoE, mine) | IPv6 | **1400** | **1360** | **1340** |

The bold MTUs are the IPv6 rows, the ones to use when any client can reach your endpoint over IPv6, which in a dual-stack setup is the normal case. The last row is the one this guide uses.

### Find your WAN's actual MTU

**Read the WAN's negotiated MTU**

```routeros
/interface print detail where name=<your-wan>
# Read actual-mtu, not the max-mtu you configured
```

Go by `actual-mtu`, not by the `max-mtu` you configured: mine says `max-mtu=1500` and negotiates 1480. PPPoE puts an 8-byte header inside the 1500-byte Ethernet payload, which leaves 1492 on a standard PPPoE link; 1480 is what DIGI's server negotiates, as the [DIGI PPPoE guide](https://jmrp.io/blog/008-mikrotik-pppoe-dualstack-digi/) explains.

### Which outer family to assume

The outer family is decided by the `Endpoint` each client dials, not by what the tunnel carries inside:

**Outer family by client endpoint**

| Client `Endpoint` | Possible outer family | Overhead to assume |
| --- | --- | --- |
| A name with only an A record, or an IPv4 literal | Always IPv4 | 60 |
| A name with A and AAAA records, a name with only AAAA, or an IPv6 literal | IPv4 or IPv6, depending on the network the client is on | 80 |

Devices that roam need one more caveat. On IPv6-only mobile networks with 464XLAT (CLAT), a connection to an IPv4 endpoint travels as IPv6 over the radio leg, 20 bytes larger, and some mobile networks have an MTU below 1500 to begin with. For phones and laptops the prudent choice is the 80-byte row even when the endpoint is IPv4-only; a fixed client with an A-only endpoint can use 60.

### What each end of the tunnel controls

**What the MTU on each end controls**

| Setting | Controls | Value to use |
| --- | --- | --- |
| Server interface MTU (`mtu=` on `/interface wireguard`) | Everything the router sends to clients: TCP, UDP and QUIC, DNS, VoIP | One value for every peer on the interface, while each peer can use a different outer family and switch when it roams. Take the worst case: WAN − 80 if any peer can arrive over IPv6, WAN − 60 only if every endpoint is A-only and no client roams. To give fixed clients with A-only endpoints the 60-byte value anyway, put them on a second interface. |
| Client MTU (`MTU =` in the `.conf`, or `client-mtu` on the RouterOS peer) | Everything the client sends, plus the MSS it advertises in its SYNs, which caps what TCP sends to it | min(server WAN, client link) − the overhead of the family of *its* endpoint. With my 1480 WAN: my iPhone, on a name with A and AAAA records, uses 1400; a Mac on an A-only name works at 1420 (what macOS picks on its own on a 1500 link), and at 1400 too. |
| MSS clamp on the router (two rules, `/ip` and `/ipv6`) | TCP only. It covers clients whose MTU is larger than the server's | The reference table's values for the server's row |

A few rules follow from this:

- **The two ends don't have to share an MTU.** Each one limits what it sends. What must not happen is either end going above its path MTU minus the overhead.
- **`change-mss` only lowers, never raises.** It is a cap, so the rule should match only SYNs above the new value: `tcp-mss=<new-mss + 1>-65535`. With `new-mss=1360` the range is `1361-65535`, and a SYN that already advertises 1240 passes untouched.
- **The clamp does not fix UDP.** QUIC (HTTP/3), DNS and VoIP depend on the interface MTU and on path MTU discovery, which is why the server MTU has to be right even with a clamp in place.
- **IPv6 needs at least 1280.** [RFC 8200](https://datatracker.ietf.org/doc/html/rfc8200#section-5) requires every link to carry 1280-byte packets, so if the formula gives less than 1280 and the tunnel carries IPv6 inside, IPv6 will not work over it.
- **With `in-interface=wg_devices`, the clamp catches the SYN and the SYN-ACK that come from the client**: connections the client opens, and connections opened towards it from the LAN. That is all the router needs, because it only has to limit what it sends into the tunnel; the client's own MTU limits what the client sends.

### Add the two clamp rules

**MSS clamping for IPv4 and IPv6**

```routeros
/ip firewall mangle add \
    chain=forward \
    action=change-mss \
    protocol=tcp \
    tcp-flags=syn \
    tcp-mss=1361-65535 \
    new-mss=1360 \
    in-interface=wg_devices \
    comment="WireGuard MSS clamping - Devices"

/ipv6 firewall mangle add \
    chain=forward \
    action=change-mss \
    protocol=tcp \
    tcp-flags=syn \
    tcp-mss=1341-65535 \
    new-mss=1340 \
    in-interface=wg_devices \
    comment="WireGuard MSS clamping IPv6 - Devices"
```

The values are the MTU − 40 and the MTU − 60 for my 1400 tunnel; take yours from the reference table, and keep each `tcp-mss` range starting one above its `new-mss`. Mangle rules default to `passthrough=yes`, so neither rule stops the rest of the chain.

### What I measured on my router

On 7 November 2026 I measured three configurations from an iPhone 12 Pro Max running the official WireGuard app, on Wi-Fi behind another DIGI line, reaching the router over IPv4. Each row is one speed test run from the phone. Alongside it, the router's sniffer on `wg_devices` (headers only) recorded packet sizes, and [mikroscope](https://docs.jmrp.io/mikroscope/), my sub-second kernel telemetry for RouterOS that runs in a container on the router, recorded softirq time and `time_squeeze` from the kernel's own counters. Its figures only count the seconds with more than 50 Mbps on `wg_devices`.

**Same phone, same router, three MTU settings**

| Scenario | Router: tunnel MTU / clamps | iPhone MTU | Speed test ↓ / ↑ (Mbps) | softirq ticks/s | time_squeeze/s |
| --- | --- | --- | --- | --- | --- |
| A | 1500 / IPv4 `new-mss=1420`, IPv6 only the generic rule at 1348 | 1280 (automatic) | 301 / 365 | 111 | 108 |
| B | 1400 / IPv4 1360 + IPv6 1340 | 1280 (automatic) | 387 / 384 | 129 | 126 |
| C | 1400 / IPv4 1360 + IPv6 1340 | **1400** (`MTU = 1400`) | **602 / 407** | **106** | **103** |

`time_squeeze` counts the times the kernel's receive softirq ran out of budget with packets still waiting: it climbs when the CPU cannot keep up with the packet rate.

**A to B changed nothing measurable, and that was expected.** Without an `MTU =` line the iPhone uses 1280 and advertises an MSS of 1240. The sniffer shows that in A and in B no packet towards the iPhone went above 1280, and the counters of the MSS rules stayed at 0, because 1240 is below both match ranges. Lowering the server's MTU does nothing for TCP towards a client whose own MTU, and so the MSS it advertises, is already lower; the speed difference between A and B is variation between tests.

**B to C is where it moved.** With the iPhone at 1400 the download went from 387 to 602 Mbps, and mikroscope saw less softirq time (129 to 106 ticks a second) and fewer squeezes (126 to 103 a second) while moving more traffic. The mechanism: at around 400 Mbps the RB5009 has all four cores at 100% encrypting, so it is bound by packets per second, not by bytes, and packets about 9% larger carry about 9% more bytes for the same CPU work. That fits the [iperf3 measurement under Slow performance](#slow-performance), around 15% median `cpu-load` at 70 Mbps: the cost grows with the traffic until the cores run out.

**C did not fragment.** The largest packet towards the iPhone was exactly 1400 bytes, and none had `fragment-offset>0`. A 1401-byte ping with DF set is rejected by the router itself ("packet too large"); without DF, a 1500-byte ping gets through because the router fragments the inner packet. In no scenario did the kernel drop packets from its receive backlog, and the interface showed no new errors.

**What this does not prove.** There is one test per scenario, and the speed test can pick a different server each time. The mechanism explains the direction, not the size: at a fixed packet rate it accounts for about 9% more bytes, not the 56% between 387 and 602 Mbps, and A and B already differed by 29% with no change that mattered. So 602 against 387 Mbps is one sample, not a guaranteed gain: how much a larger client MTU buys depends on the server being CPU-bound, as this one is at that rate.

**Warning: Reading packet sizes from the RouterOS sniffer**

In the rx direction the sniffer shows packets of up to 64 KB. That is the kernel's GRO merging packets after decryption, not the real MTU, so read packet sizes in the tx direction. Also, `filter-ip-address` only captures IPv4.

---

## Step 8: configure RAW table for performance

Skip flood protection for WireGuard traffic to ensure smooth connectivity:

**RAW Table Rules**

```routeros
# IPv4: Skip flood protection for WireGuard
/ip firewall raw add \
    chain=prerouting \
    action=accept \
    protocol=udp \
    dst-port=53537 \
    comment="WireGuard - Skip flood protection"

# IPv6: Skip flood protection for WireGuard
/ipv6 firewall raw add \
    chain=prerouting \
    action=accept \
    protocol=udp \
    dst-port=53537 \
    comment="WireGuard - Skip flood protection"
```

---

## Step 9: add WireGuard peers (clients)

Now we add client devices. Each client needs:

- **Unique IP addresses**: A dedicated IPv4 and IPv6 address within the WireGuard subnet
- **Keypair**: Private and public keys for authentication
- **Preshared key**: Optional but recommended additional encryption layer

### Create a peer

Choose how to generate the cryptographic keys. The **recommended** approach lets RouterOS generate everything automatically, but you can also pre-generate keys on the client device.

**Option 1/3 — RouterOS (recommended)**

Since RouterOS 7.x, the router can generate all cryptographic keys automatically. This is the **simplest approach**: the router creates the private key, computes the public key, and generates the preshared key in a single command.

#### Create the peer with auto-generated keys

**Add Peer with Auto-Generated Keys**

```routeros
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_client1 \
    private-key=auto \
    preshared-key=auto \
    allowed-address=192.168.100.2/32,fd00:1111:2222:100::2/128 \
    comment="Client 1 - Mobile"
```

**Tip: What auto Does**

`private-key=auto` generates a private key and automatically computes the corresponding public key. `preshared-key=auto` generates a random preshared key. Both values are stored on the peer and can be retrieved later.

#### Set client configuration properties (optional)

These properties define the client-side configuration and enable the **QR code** feature in WinBox/WebFig:

**Set Client Configuration Properties**

```routeros
/interface wireguard peers set [find name=wg_client1] \
    client-address=192.168.100.2/32,fd00:1111:2222:100::2/128 \
    client-dns=192.168.0.1,fd00:1111:2222:100::1 \
    client-endpoint=your-domain.com:53537 \
    client-allowed-address=0.0.0.0/0,::/0 \
    client-keepalive=25 \
    client-mtu=1400
```

**Warning: client-mtu needs RouterOS 7.25 or later**

`client-mtu` arrived in RouterOS 7.25, so the 7.24 long-term branch does not have it. On an older version RouterOS rejects the whole `set` command because of the unknown parameter: drop the `client-mtu=1400` line there and write `MTU = 1400` in the client's `.conf` by hand ([Step 10](#step-10-client-configuration)). Before 7.21 the same goes for `client-allowed-address`: drop that line too, and the exported configuration carries `0.0.0.0/0, ::/0`, the value it sets here anyway. `client-keepalive=25` sets the client's `PersistentKeepalive`: the keepalive belongs on the client.

**Tip: QR Code in WinBox / WebFig**

With these client properties set, open the peer in **WinBox** or **WebFig** and use `show-client-config` to display the complete client configuration and a QR code. This is the **easiest way** to configure iOS/Android clients: just scan the code from the WireGuard app.

#### Retrieve keys for manual client configuration

If you need to configure the client manually instead of scanning the QR code, retrieve the generated keys from the router:

**Retrieve Generated Keys**

```routeros
# Client's private key → goes into client's [Interface] section
:put [/interface wireguard peers get [find name=wg_client1] private-key]

# Preshared key → goes into client's [Peer] section
:put [/interface wireguard peers get [find name=wg_client1] preshared-key]

# Server's public key → goes into client's [Peer] section
:put [/interface wireguard get [find name=wg_devices] public-key]
```

Use these values to fill in the client configuration file in [Step 10](#step-10-client-configuration).

**Option 2/3 — Linux / macOS**

Generate keys on the client device first, then add the peer on the router using the client's **public** key.

#### Generate keys on the client

**Generate Client Keys**

```bash
# Generate private key
wg genkey > privatekey

# Generate public key from private key
cat privatekey | wg pubkey > publickey

# Generate preshared key (optional but recommended)
wg genpsk > presharedkey

# Display keys
cat privatekey publickey presharedkey
```

#### Add peer on MikroTik (Linux / macOS)

Use the client's **public** key (not the private key) and the preshared key:

**Add WireGuard Peer (Linux/macOS)**

```routeros
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_client1 \
    public-key="<CLIENT_PUBLIC_KEY>" \
    preshared-key="<PRESHARED_KEY>" \
    allowed-address=192.168.100.2/32,fd00:1111:2222:100::2/128 \
    comment="Client 1 - Mobile"
```

**Important: Keep the Private Key Secure**

The private key stays on the client device and goes into the client's `[Interface]` section. Only the **public** key is shared with the router. **Never** transfer the private key over an insecure channel.

**Option 3/3 — Windows**

The WireGuard Windows app generates keys automatically when creating a new tunnel.

1. Download and install [WireGuard for Windows](https://www.wireguard.com/install/)
2. Open the app and click **Add Tunnel** → **Add empty tunnel**
3. The app generates a keypair; copy the **Public Key** shown at the top
4. Generate a preshared key from the command line:

**Generate Preshared Key**

```powershell
# If WireGuard is installed, wg.exe is available in PATH
wg genpsk
```

#### Add peer on MikroTik (Windows)

**Add WireGuard Peer (Windows)**

```routeros
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_client1 \
    public-key="<CLIENT_PUBLIC_KEY>" \
    preshared-key="<PRESHARED_KEY>" \
    allowed-address=192.168.100.2/32,fd00:1111:2222:100::2/128 \
    comment="Client 1 - Mobile"
```

**Peer Configuration Parameters**

| Parameter | Value | Purpose |
| --- | --- | --- |
| `private-key` | `auto` / none | Auto-generates keypair on the router (recommended method) |
| `public-key` | Client's public key | Identifies and authenticates the client |
| `preshared-key` | `auto` / shared secret | Additional symmetric encryption layer (post-quantum security) |
| `allowed-address` | Client IP(s) | IPs the client can use; also acts as routing table |
| `persistent-keepalive` | Unset (0) | Leave it off for roaming clients: with it the router keeps retrying handshakes against their last endpoint. The keepalive goes on the client (`PersistentKeepalive = 25`) |

**Warning: Persistent Keepalive**

The keepalive belongs on the side that sits behind NAT, which is the client: `PersistentKeepalive = 25` in its `.conf`, or `client-keepalive=25` on the router's peer so the QR code carries it. Every 25 seconds the client refreshes its NAT mapping, which is what lets the router reach it between the client's own packets.

On the router, leave `persistent-keepalive` off for those peers. With it the router sends on its own, so once a phone or laptop moves or is switched off, it keeps retrying handshakes against the last endpoint it knew. RouterOS also has [`responder=yes`](https://help.mikrotik.com/docs/spaces/ROS/pages/69664792/WireGuard), which stops the router initiating handshakes at all (from 7.17), but on my iPhone it made the tunnel drop with every small change of network, so this guide does not use it ([How I run this](#how-i-run-this-on-my-own-infrastructure) has the story).

If **this** router has to call the other end (a site-to-site link where it initiates, with `endpoint-address` set on the peer), set `persistent-keepalive` on whichever side is behind NAT.

### Example: multiple peers

Each peer must have a **unique keypair** and **unique IP addresses**. Never reuse keys between devices.

**Multiple Peer Configuration (RouterOS auto-keys)**

```routeros
# Client 1 - Mobile Device (e.g., iPhone)
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_phone \
    private-key=auto \
    preshared-key=auto \
    allowed-address=192.168.100.2/32,fd00:1111:2222:100::2/128 \
    comment="Phone - Mobile VPN"

# Client 2 - Laptop (e.g., MacBook)
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_laptop \
    private-key=auto \
    preshared-key=auto \
    allowed-address=192.168.100.3/32,fd00:1111:2222:100::3/128 \
    comment="Laptop - Mobile VPN"

# Client 3 - Remote Site (Site-to-Site VPN that dials in to this router)
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_remote_site \
    private-key=auto \
    preshared-key=auto \
    allowed-address=192.168.100.10/32,fd00:1111:2222:100::a/128 \
    comment="Remote Site - Site-to-Site"
```

**Warning: Security: Never Share Private Keys**

Whether keys are auto-generated on the router or pre-generated on the client, the private key must **only** exist on the client device. When using RouterOS auto-generation, retrieve the private key once for client configuration and avoid logging or storing it elsewhere. **Never** commit real keys to documentation or version control.

---

## Step 10: client configuration

Now configure the client device. If you used the **RouterOS auto-keys** method and set the client properties in Step 9, you can simply scan the **QR code** from WinBox/WebFig, with no manual configuration needed.

For manual setup, the configuration file format is the same across all platforms, but the setup method varies.

**Important: Replace These Values**

In every client configuration below, you **must** replace:

- **`<CLIENT_PRIVATE_KEY>`**: the client's private key (auto-generated on router or generated locally in Step 9)
- **`<SERVER_PUBLIC_KEY>`**: the server's public key (from Step 1, or retrieved with `:put` in Step 9)
- **`<PRESHARED_KEY>`**: the preshared key (must match server peer config)
- **`your-domain.com:53537`**: your router's public IP/domain and WireGuard port
- **IP addresses**: must match the `allowed-address` configured on the server peer
- **`MTU = 1400`**: the smaller of your server's WAN `actual-mtu` and the client's own link MTU, minus 80 ([Step 7](#step-7-calculate-the-mtu-and-clamp-mss))

**Option 1/3 — iOS / Android**

Download the **WireGuard** app from the [App Store](https://apps.apple.com/app/wireguard/id1441195209) or [Google Play](https://play.google.com/store/apps/details?id=com.wireguard.android). You can either:

- **Import a .conf file** or scan a **QR code**
- **Create manually** in the app

**File: `wg_home.conf` (iOS/Android) — Mobile Client Configuration**

```ini
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 192.168.100.2/32, fd00:1111:2222:100::2/128
DNS = 192.168.0.1, fd00:1111:2222:100::1
MTU = 1400

[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
PresharedKey = <PRESHARED_KEY>
Endpoint = your-domain.com:53537
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
```

**Tip: QR Code from RouterOS**

If you set the client properties in Step 9 (`client-address`, `client-dns`, `client-endpoint`, etc.), open the peer in **WinBox** or **WebFig** and use `show-client-config` to display a QR code. Scan it with the WireGuard app; no manual configuration is needed.

**Option 2/3 — macOS / Linux**

Install WireGuard:

**Install WireGuard**

```bash
# macOS (Homebrew)
brew install wireguard-tools

# Ubuntu/Debian
sudo apt install wireguard

# Fedora
sudo dnf install wireguard-tools
```

Create the configuration file:

**File: `/etc/wireguard/wg_home.conf` — Linux/macOS Client Configuration**

```ini
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 192.168.100.2/32, fd00:1111:2222:100::2/128
DNS = 192.168.0.1, fd00:1111:2222:100::1
MTU = 1400

[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
PresharedKey = <PRESHARED_KEY>
Endpoint = your-domain.com:53537
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
```

Activate the tunnel:

**Activate WireGuard**

```bash
# Start the tunnel
sudo wg-quick up wg_home

# Check status
sudo wg show

# Stop the tunnel
sudo wg-quick down wg_home

# Enable on boot (Linux only)
sudo systemctl enable wg-quick@wg_home
```

**Option 3/3 — Windows**

1. Download and install [WireGuard for Windows](https://www.wireguard.com/install/)
2. Open the app and click **Add Tunnel** → **Import tunnel(s) from file** (if you have a `.conf` file) or **Add empty tunnel** to paste the configuration
3. If creating from scratch, replace the configuration with:

**File: `wg_home.conf` (Windows) — Windows Client Configuration**

```ini
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 192.168.100.2/32, fd00:1111:2222:100::2/128
DNS = 192.168.0.1, fd00:1111:2222:100::1
MTU = 1400

[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
PresharedKey = <PRESHARED_KEY>
Endpoint = your-domain.com:53537
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
```

5. Click **Save** then **Activate**

### Configuration options explained

**Client Configuration Parameters**

| Parameter | Description |
| --- | --- |
| `Address` | The IP addresses assigned to this client (both IPv4 and IPv6) |
| `DNS` | DNS servers to use. Can be your router or any DNS server accessible via VPN |
| `MTU` | The tunnel MTU on the client. Always set it: the smaller of your server's WAN `actual-mtu` and the client's own link MTU, minus 80 (minus 60 only for an IPv4-only endpoint and a client that never roams). 1400 here |
| `Endpoint` | Your router's public IP or domain name with the WireGuard port |
| `AllowedIPs` | `0.0.0.0/0, ::/0` routes ALL traffic through VPN. Use specific subnets for split-tunnel |
| `PersistentKeepalive` | Seconds between the keepalive packets the client sends to hold its NAT mapping open, so the router can reach it. The keepalive lives here, on the client; the router's peer has none |

### Why every client config sets MTU

Leave `MTU =` out and each official app picks its own value, and none of them knows anything about your server's WAN:

**What each WireGuard app does without MTU =**

| Platform | Tunnel MTU it picks | Source |
| --- | --- | --- |
| iOS, iPadOS | Fixed at **1280** | [`PacketTunnelSettingsGenerator.swift`](https://github.com/WireGuard/wireguard-apple/blob/master/Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift) in wireguard-apple |
| macOS | MTU of the physical interface **minus 80** (1420 on a 1500 Wi-Fi network) | The same file, macOS branch (`tunnelOverheadBytes = 80`) |
| Android | Fixed at **1280** | [`GoBackend.java`](https://github.com/WireGuard/wireguard-android/blob/master/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java) in wireguard-android |
| Linux (`wg-quick`) | MTU of the route to the endpoint (failing that, of the default route; failing that, 1500) **minus 80** | `set_mtu_up()` in [`linux.bash`](https://github.com/WireGuard/wireguard-tools/blob/master/src/wg-quick/linux.bash), wireguard-tools |
| Windows | Follows the MTU of the default route's interface **minus 80**, never below 1280 for IPv6 | [`mtumonitor.go`](https://github.com/WireGuard/wireguard-windows/blob/master/tunnel/mtumonitor.go) in wireguard-windows |
| RouterOS (as a client) | The interface default, **1420** | [MikroTik WireGuard documentation](https://help.mikrotik.com/docs/spaces/ROS/pages/69664792/WireGuard) |

The desktop apps subtract 80 from the MTU of the **client's** local link and know nothing about the **server's** WAN. With my server on a 1480 PPPoE link and the tunnel running over IPv6, a Mac in automatic mode uses 1420, and 1420 + 80 = 1500 does not fit in 1480, so it fragments; over IPv4 it fits exactly (1420 + 60 = 1480). The mobile apps go to the other extreme: 1280 always works, but it wastes throughput on a server bound by packets per second, as [the measurements in Step 7](#what-i-measured-on-my-router) show. So write `MTU =` in every client config, with the value from [Step 7](#step-7-calculate-the-mtu-and-clamp-mss).

### Split tunnel vs full tunnel

**Traffic Routing Modes**

```mermaid
flowchart TB
    subgraph Full_Tunnel["Full Tunnel"]
        direction LR
        FT_Client[Client]:::secondary --> FT_VPN[VPN Tunnel]:::highlight
        FT_VPN --> FT_Router[Home Router]:::info
        FT_Router --> FT_Internet[Internet]:::success
    end
    
    subgraph Split_Tunnel["Split Tunnel"]
        direction LR
        ST_Client[Client]:::secondary --> ST_Decision{Destination?}:::warning
        ST_Decision -->|Home Network| ST_VPN[VPN Tunnel]:::highlight
        ST_VPN --> ST_Router[Home Router]:::info
        ST_Decision -->|Internet| ST_Direct[Direct Connection]:::success
    end

    Full_Tunnel ~~~ Split_Tunnel
```

**Full tunnel** sends all traffic through the VPN:

- Hides your location from all websites
- Higher latency for general browsing
- Full IPv6 access through home connection

**Full Tunnel Example**

```ini
# Route ALL traffic through VPN
AllowedIPs = 0.0.0.0/0, ::/0
```

**Split tunnel** sends only traffic for the specified networks through the VPN:

- Better performance for general internet use
- Home network access without routing everything

**Split Tunnel Example**

```ini
# Only route home network traffic through VPN
AllowedIPs = 192.168.0.0/24, 192.168.100.0/24, fd00:1111:2222::/48
```

---

## Step 11: verify the connection

After configuring both sides, test the connection.

### On the client

**Terminal session — Check WireGuard Status (Client)**

```bash
# macOS/Linux
sudo wg show

# Or use the WireGuard app on iOS/Android
```

**Output: Successful Connection**

```text
interface: wg_home
  public key: ClientPublicKeyHere123456789ABCDEFGHIJKLMNO=
  private key: (hidden)
  listening port: 51820

peer: YourServerPublicKeyHere123456789ABCDEFGHIJ=
  preshared key: (hidden)
  endpoint: 203.0.113.50:53537
  allowed ips: 0.0.0.0/0, ::/0
  latest handshake: 5 seconds ago
  transfer: 1.24 MiB received, 456.78 KiB sent
```

### On the MikroTik router

**Terminal session — Check Peer Status (Router)**

```routeros
/interface wireguard peers print
```

**Output: Connected Peer**

```text
Flags: X - disabled
 0   name="wg_client1" interface=wg_devices
     public-key="<CLIENT_PUBLIC_KEY>"
     preshared-key="(present)" allowed-address=192.168.100.2/32,fd00:1111:2222:100::2/128
     current-endpoint-address=198.51.100.75 current-endpoint-port=51820
     last-handshake=5s rx=1302528 tx=467352
```

**Tip: Drop the router-side keepalive**

If you created a peer earlier with `persistent-keepalive` on the router side, set it to 0 and leave the keepalive on the client:

```routeros
/interface wireguard peers set [find name=wg_client1] persistent-keepalive=0
```

RouterOS also offers `responder=yes` (since 7.15, honoured from 7.17) to stop the router initiating handshakes at all. I tried it on every peer and reverted it the same day, because my iPhone's tunnel dropped with every small change of network.

### Test IPv6 connectivity

**Test IPv6 Through VPN**

```bash
# Check your IPv6 address
curl -6 ifconfig.co

# Test IPv6 connectivity
ping6 google.com

# Verify route
traceroute6 google.com
```

---

## Complete configuration summary

Here's the complete RouterOS configuration for reference. Values marked with `# ← CUSTOMIZE` must be replaced with your own.

**File: `wireguard-complete.rsc` — Complete WireGuard Configuration**

```routeros
# ═══════════════════════════════════════════════════════════════════════════════
# WIREGUARD VPN - COMPLETE DUAL-STACK CONFIGURATION
# ═══════════════════════════════════════════════════════════════════════════════
# MikroTik RouterOS 7.15+ (tested on 7.25)
# IPv4 + IPv6 dual-stack with full internet access
# ═══════════════════════════════════════════════════════════════════════════════

# ───────────────────────────────────────────────────────────────────────────────
# INTERFACE CONFIGURATION
# ───────────────────────────────────────────────────────────────────────────────

# ← CUSTOMIZE mtu: WAN actual-mtu - 80 (1480 - 80 = 1400 here; 1420 on a 1500 WAN)
/interface wireguard add \
    name=wg_devices \
    mtu=1400 \
    listen-port=53537 \
    comment="VPN for Mobile Devices"                              # ← CUSTOMIZE port

# ───────────────────────────────────────────────────────────────────────────────
# IP ADDRESS ASSIGNMENT
# ───────────────────────────────────────────────────────────────────────────────

/ip address add \
    address=192.168.100.1/24 \
    interface=wg_devices \
    network=192.168.100.0 \
    comment="VPN Devices Network"                                 # ← CUSTOMIZE subnet

/ipv6 address add \
    address=fd00:1111:2222:100::1/64 \
    interface=wg_devices \
    advertise=no \
    comment="VPN Devices IPv6 ULA"                                # ← CUSTOMIZE ULA prefix

# ───────────────────────────────────────────────────────────────────────────────
# IPv6 POOL (Optional)
# ───────────────────────────────────────────────────────────────────────────────

/ipv6 pool add \
    name=wg_devices_pool_global \
    prefix=fd00:1111:2222:100::/64 \
    prefix-length=64 \
    comment="WireGuard Devices Global IPv6 Pool"

# ───────────────────────────────────────────────────────────────────────────────
# INTERFACE LISTS (create 'VPN' list if it doesn't exist)
# ───────────────────────────────────────────────────────────────────────────────

/interface list add name=VPN comment="VPN Interfaces" # only if list doesn't exist yet
/interface list member add interface=wg_devices list=VPN comment="VPN Devices"
/interface list member add interface=wg_devices list=LAN comment="VPN Devices - LAN Access"

# ───────────────────────────────────────────────────────────────────────────────
# ADDRESS LISTS
# ───────────────────────────────────────────────────────────────────────────────

/ip firewall address-list add \
    list=WireGuard \
    address=192.168.100.0/24 \
    comment="WireGuard Devices Network"

# ───────────────────────────────────────────────────────────────────────────────
# FIREWALL - INPUT CHAIN
# ───────────────────────────────────────────────────────────────────────────────

/ip firewall filter add \
    chain=input \
    action=accept \
    protocol=udp \
    dst-port=53537 \
    comment="WireGuard - Accept incoming connections"              # ← CUSTOMIZE port

/ipv6 firewall filter add \
    chain=input \
    action=accept \
    protocol=udp \
    port=53537 \
    comment="Allow WireGuard"                                     # ← CUSTOMIZE port

# ───────────────────────────────────────────────────────────────────────────────
# FIREWALL - FORWARD CHAIN (IPv4)
# ───────────────────────────────────────────────────────────────────────────────

/ip firewall filter add \
    chain=forward \
    action=fasttrack-connection \
    connection-state=established,related \
    src-address-list=WireGuard \
    comment="FastTrack for WireGuard Networks"

/ip firewall filter add \
    chain=forward \
    action=accept \
    src-address=192.168.100.0/24 \
    out-interface-list=WAN \
    comment="Allow WireGuard Devices to Internet"                  # ← CUSTOMIZE subnet

/ip firewall filter add \
    chain=forward \
    action=accept \
    connection-state=established,related \
    dst-address=192.168.100.0/24 \
    in-interface-list=WAN \
    comment="Allow Internet to WireGuard Devices (replies)"        # ← CUSTOMIZE subnet

/ip firewall filter add \
    chain=forward \
    action=accept \
    src-address=192.168.100.0/24 \
    dst-address=192.168.0.0/24 \
    comment="Allow WireGuard Devices to Home LAN"                  # ← CUSTOMIZE subnets

# ───────────────────────────────────────────────────────────────────────────────
# FIREWALL - FORWARD CHAIN (IPv6)
# ───────────────────────────────────────────────────────────────────────────────

/ipv6 firewall filter add \
    chain=forward \
    action=accept \
    in-interface=wg_devices \
    comment="WireGuard Devices: Allow all outbound"

/ipv6 firewall filter add \
    chain=forward \
    action=accept \
    connection-state=established,related \
    out-interface=wg_devices \
    comment="WireGuard Devices: Allow replies"

# ───────────────────────────────────────────────────────────────────────────────
# NAT / MASQUERADE
# ───────────────────────────────────────────────────────────────────────────────

/ip firewall nat add \
    chain=srcnat \
    action=masquerade \
    src-address=192.168.100.0/24 \
    out-interface-list=WAN \
    comment="WireGuard Devices - Internet Access"                  # ← CUSTOMIZE subnet

/ipv6 firewall nat add \
    chain=srcnat \
    action=masquerade \
    src-address=fd00:1111:2222:100::/64 \
    out-interface-list=WAN \
    comment="WireGuard Devices - IPv6 Internet Access"             # ← CUSTOMIZE ULA prefix

# ───────────────────────────────────────────────────────────────────────────────
# MANGLE - MSS CLAMPING
# ───────────────────────────────────────────────────────────────────────────────

# ← CUSTOMIZE: new-mss = MTU - 40 (IPv4) and MTU - 60 (IPv6); tcp-mss starts at new-mss + 1
/ip firewall mangle add \
    chain=forward \
    action=change-mss \
    protocol=tcp \
    tcp-flags=syn \
    tcp-mss=1361-65535 \
    new-mss=1360 \
    in-interface=wg_devices \
    comment="WireGuard MSS clamping - Devices"

/ipv6 firewall mangle add \
    chain=forward \
    action=change-mss \
    protocol=tcp \
    tcp-flags=syn \
    tcp-mss=1341-65535 \
    new-mss=1340 \
    in-interface=wg_devices \
    comment="WireGuard MSS clamping IPv6 - Devices"

# ───────────────────────────────────────────────────────────────────────────────
# RAW TABLE - SKIP FLOOD PROTECTION
# ───────────────────────────────────────────────────────────────────────────────

/ip firewall raw add \
    chain=prerouting \
    action=accept \
    protocol=udp \
    dst-port=53537 \
    comment="WireGuard - Skip flood protection"

/ipv6 firewall raw add \
    chain=prerouting \
    action=accept \
    protocol=udp \
    dst-port=53537 \
    comment="WireGuard - Skip flood protection"

# ───────────────────────────────────────────────────────────────────────────────
# PEERS: using auto-generated keys (recommended); no keepalive on the router side
# Retrieve keys with: :put [/interface wireguard peers get [find name=X] private-key]
# ───────────────────────────────────────────────────────────────────────────────

# ← CUSTOMIZE the IPs in allowed-address
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_phone \
    private-key=auto \
    preshared-key=auto \
    allowed-address=192.168.100.2/32,fd00:1111:2222:100::2/128 \
    comment="Phone - Mobile VPN"                                   # ← CUSTOMIZE

# ← CUSTOMIZE the IPs in allowed-address
/interface wireguard peers add \
    interface=wg_devices \
    name=wg_laptop \
    private-key=auto \
    preshared-key=auto \
    allowed-address=192.168.100.3/32,fd00:1111:2222:100::3/128 \
    comment="Laptop - Mobile VPN"                                  # ← CUSTOMIZE
```

---

## Troubleshooting

### Connection won't establish

The most common issue. If `last-handshake` never appears on either side, the initial handshake isn't completing.

**Check the WireGuard interface is running.** A disabled or stopped interface won't accept connections:

**Verify Interface Status**

```routeros
/interface wireguard print
# Look for the "R" (running) flag. If you see "X" (disabled), enable it:
/interface wireguard enable wg_devices
```

**Verify the UDP port is reachable.** The firewall must accept incoming WireGuard packets. Check the input chain has an accept rule for your port:

**Check Firewall Input Rules**

```routeros
# List input rules that match your WireGuard port
/ip firewall filter print where chain=input and dst-port~"53537"
# If empty, add the rule:
/ip firewall filter add chain=input action=accept protocol=udp dst-port=53537 \
    comment="WireGuard - Accept incoming connections" place-before=0
```

**Verify the peer's public key matches.** This is the most subtle error. The server must have the client's public key, and the client must have the server's public key. Any mismatch silently drops all packets:

**Verify Keys**

```routeros
# Show the server's public key (this goes into the client's [Peer] section)
:put [/interface wireguard get wg_devices public-key]

# Show the client's public key stored on this peer
:put [/interface wireguard peers get [find name=wg_client1] public-key]
```

**Check if the peer shows a handshake.** If `last-handshake` shows a time, the tunnel is established even if traffic isn't flowing:

**Check Peer Handshake**

```routeros
/interface wireguard peers print detail where interface=wg_devices
# Look for: last-handshake=Xs (seconds since last handshake)
# If empty or very old, the tunnel is not established
```

**Tip: Port Forwarding**

If your MikroTik is behind another router or NAT gateway, you must forward the WireGuard UDP port (e.g., `53537`) to your MikroTik's internal IP. WireGuard uses **only UDP**; TCP forwarding will not work.

### Can connect but no internet access

The tunnel is up (handshake succeeds) but the client can't browse the web or reach external hosts.

**Check NAT/masquerade rules.** Without masquerade, the VPN client's private IP reaches the internet but return packets have nowhere to go:

**Verify NAT Rules**

```routeros
# Check IPv4 masquerade
/ip firewall nat print where chain=srcnat and src-address~"192.168.100"
# Should show: action=masquerade out-interface-list=WAN

# Check IPv6 masquerade
/ipv6 firewall nat print where chain=srcnat and src-address~"fd00"
```

**Check forward chain rules.** Even with NAT, the firewall's forward chain must allow VPN traffic toward the WAN:

**Verify Forward Rules**

```routeros
/ip firewall filter print where chain=forward and src-address~"192.168.100"
# You need at least:
#   accept src=192.168.100.0/24 out-interface-list=WAN
#   accept connection-state=established,related dst=192.168.100.0/24 in-interface-list=WAN
```

**Test DNS resolution.** A common cause of "no internet" is that DNS queries fail. From the client, try reaching an IP directly to isolate the issue:

**Isolate DNS vs Routing Issue**

```bash
# Test direct IP connectivity (bypasses DNS)
ping 1.1.1.1

# If ping works but browsing doesn't, DNS is the problem.
# Try a different DNS in the client config:
# DNS = 1.1.1.1, 2606:4700:4700::1111
```

**Tip: Router as DNS Server**

If you use your MikroTik as the DNS server for VPN clients (`DNS = 192.168.0.1`), ensure `allow-remote-requests=yes` is set under `/ip dns`. Also verify the WireGuard interface or its address is in the `LAN` interface list, so input rules allow DNS queries from VPN clients.

### IPv6 not working

IPv4 works through the tunnel but IPv6 traffic doesn't flow.

**Verify the IPv6 address is assigned** to the WireGuard interface:

**Check IPv6 Address**

```routeros
/ipv6 address print where interface=wg_devices
# Should show your ULA address, e.g., fd00:1111:2222:100::1/64
```

**Check IPv6 NAT66 rule.** Unlike IPv4, the IPv6 masquerade is often forgotten:

**Verify IPv6 NAT66**

```routeros
/ipv6 firewall nat print where chain=srcnat
# Must include: action=masquerade src-address=fd00:1111:2222:100::/64 out-interface-list=WAN
```

**Check IPv6 forward rules.** The IPv6 firewall is independent from IPv4. You need explicit forward rules:

**Verify IPv6 Forward Rules**

```routeros
/ipv6 firewall filter print where chain=forward and interface~"wg_devices"
# Need at minimum:
#   accept in-interface=wg_devices (outbound)
#   accept connection-state=established,related out-interface=wg_devices (return)
```

**Test from the client.** Run these commands while connected to the VPN:

**Diagnose IPv6**

```bash
# Verify your IPv6 address is from the ULA range
ip -6 addr show wg_home

# Test connectivity to a known IPv6 address (Google DNS)
ping6 2001:4860:4860::8888

# If the ping works, test DNS resolution over IPv6
curl -6 ifconfig.co
```

**Warning: ISP IPv6 Required**

NAT66 translates your VPN client's ULA address to your ISP's global IPv6 prefix. If your ISP doesn't provide IPv6, there's no global prefix to translate to, and IPv6 internet access won't work. The tunnel itself will still carry IPv6 between client and router, but no further.

### Slow performance

WireGuard is extremely efficient, but several factors can limit throughput on MikroTik devices.

**Enable FastTrack.** This is the single largest performance improvement. FastTrack bypasses most firewall processing for established connections:

**Check FastTrack**

```routeros
# Verify FastTrack rule exists and has packet counters increasing
/ip firewall filter print stats where action=fasttrack-connection and comment~"WireGuard"
# If missing:
/ip firewall filter add chain=forward action=fasttrack-connection \
    connection-state=established,related src-address-list=WireGuard \
    comment="FastTrack for WireGuard Networks"
```

**Check MSS clamping.** Symptoms of a missing clamp include pages partially loading, HTTPS sites timing out, and large file downloads failing while small requests work fine. Check both rules: without the `/ipv6` one, the trouble shows up only on IPv6 connections:

**Verify MSS Clamping**

```routeros
/ip firewall mangle print where action=change-mss and in-interface=wg_devices
# Should show: new-mss=1360 tcp-flags=syn tcp-mss=1361-65535

/ipv6 firewall mangle print where action=change-mss and in-interface=wg_devices
# Should show: new-mss=1340 tcp-flags=syn tcp-mss=1341-65535
```

**Check MTU.** The clamp only covers TCP, so loss or stalls in QUIC, DNS or VoIP point at an interface MTU too large for your WAN. [Step 7](#step-7-calculate-the-mtu-and-clamp-mss) shows how to calculate the right value; these two commands show what you have now:

**Check MTU**

```routeros
# Current tunnel MTU
/interface wireguard print proplist=name,mtu

# Your WAN's negotiated MTU (actual-mtu), where the calculation starts
/interface print detail where name=<your-wan>
```

**Monitor CPU load.** WireGuard encryption is not hardware-offloaded on MikroTik. High CPU usage limits throughput:

**Monitor CPU**

```routeros
/system resource print
# Look for the cpu-load percentage.
```

An idle tunnel tells you nothing, so I measured this one under load: `iperf3` between a
phone on the VPN and a host on the LAN side, with the router doing the crypto in between.
Downstream (the direction where the router encrypts), the tunnel sustained roughly 70 Mbps
for 30 seconds, and `cpu-load` went from a median of 3% at rest to a median of 15% while it
ran. Memory barely moved: about 22 MiB of the router's 1 GiB, and it came straight back. So
the cost of WireGuard on an RB5009 at that rate is around twelve points of aggregate CPU
(RouterOS reports `cpu-load` averaged across the board's four cores, not per core), and
nothing else.

Two caveats, because both of them would have made this number a lie. The first is that my
router runs some periodic task every two minutes that takes CPU to 30% on its own; it is
visible in the samples at 0, 120, 240 and 360 seconds, has nothing to do with the tunnel,
and averaging it in would have produced a "peak 31% under VPN load" that is simply false.
Sample long enough to see your own background, and exclude it. The second is that 70 Mbps
was my client's ceiling, not the router's: this says what WireGuard costs at that rate, not
where it stops. [The measurements in Step 7](#what-i-measured-on-my-router) later found where
the CPU runs out on this router: at around 400 Mbps all four cores sit at 100% encrypting,
and past that point, in those one-sample tests, what moved more bytes was a larger client MTU.

One result did surprise me. Five parallel streams moved **less** than a single stream,
about 58 Mbps against roughly 70, and did it with thirty times the retransmissions. On a
mobile link the parallel flows compete for the same buffer and manufacture the loss that TCP
then reads as congestion. If you benchmark your own tunnel, start with one stream; reach for
`-P` only after you have confirmed a single flow cannot fill the pipe.

### Useful diagnostic commands

A quick-reference for common RouterOS diagnostic commands related to WireGuard:

**WireGuard Diagnostic Commands**

```routeros
# Show all peers with connection status and traffic stats
/interface wireguard peers print detail

# Show only connected peers (those with a recent handshake)
/interface wireguard peers print where last-handshake<1m

# Monitor WireGuard traffic in real-time
/interface monitor-traffic wg_devices once

# Check interface packet counters
/interface print stats where name=wg_devices

# View firewall rule hit counters (useful to find rules that never match)
/ip firewall filter print stats where comment~"WireGuard"

# Check if the port is listening
/tool netwatch print where host=127.0.0.1 and port=53537
```

---

## Security best practices

- Always use preshared keys for post-quantum security
- Use unique keypairs for each device (never share private keys)
- Keep RouterOS updated for security patches
- Use a non-standard port to reduce scan exposure
- Consider automatic IP whitelisting for connected peers
- Monitor connection logs for unauthorized access attempts

---

## Conclusion

You now have a fully functional [WireGuard](https://www.wireguard.com/) VPN with dual-stack IPv4/IPv6 support on your [MikroTik](https://mikrotik.com/) router. This configuration provides:

- **Secure remote access** to your home network from anywhere
- **Full IPv6 connectivity** even from IPv4-only networks
- **Fast, modern encryption** with minimal overhead
- **Seamless roaming** between Wi-Fi and cellular networks

WireGuard's simplicity makes it easy to maintain, and MikroTik's implementation is robust enough for production use. Whether you're accessing your NAS, home automation, or simply want to browse securely on public Wi-Fi, this setup has you covered.

