A VPN that keeps routing explicit
A remote user needs an internal service, or two branches need secure access between specific networks. When you control both endpoints, WireGuard provides an encrypted path between peers with separate keys. This guide explains client access and a separate branch example together with routes and firewall policy. A laptop represents itself; a branch router can also represent the LAN behind it.
WireGuard, IPsec or OpenVPN?
| VPN | Authentication and encryption | Routing and NAT | Operational fit |
|---|---|---|---|
| WireGuard | Peer public keys; fixed modern cryptographic suite | Routed IP; UDP; keepalive preserves NAT state; no built-in relay | Small key inventory and explicit routes; no built-in user/MFA directory |
| IPsec / IKEv2 | Certificates or configured IKE authentication; negotiated ESP suites | RouterOS policies/selectors; UDP 500/4500 NAT-T and ESP where applicable | Multi-vendor gateways and existing PKI; more policy/SA diagnostics |
| OpenVPN | TLS certificates plus supported account authentication | RouterOS IP tunnel; TCP or UDP depends on version/configuration | Existing OpenVPN clients/PKI; verify RouterOS feature and cipher parity |
None of these solves overlapping LAN addresses automatically. WireGuard authenticates possession of a private key, not the person using the device. Where access requires identity-provider policy or MFA, design that control separately or select a service that supplies it.
Follow the encrypted packet and its reply
The outer UDP packet must first pass WAN input policy. After decryption, traffic for 10.77.0.1 reaches the router's input path, while traffic for an office host traverses forward. Replies must return to the router so its route and allowed-address selection send them to the peer. A successful handshake therefore establishes only one stage of application access.
Before you start
WireGuard is built into RouterOS 7. Use an updated stable release supported by your router. This guide configures IPv4 remote access first, then a separate two-site example. Run RouterOS commands in WinBox New Terminal. Export your current configuration and enter Safe Mode with Ctrl+X.
/export file=before-wireguardThe office LAN is 192.168.88.0/24, VPN is 10.77.0.0/24, router VPN address is 10.77.0.1 and one client uses 10.77.0.2. These networks must not overlap with the client LAN. Replace vpn.example.com with your public IP or DNS name. The router must be reachable on UDP 51820; forward this UDP port on an upstream modem if needed. CGNAT requires a reachable hub or an ISP public address; DDNS alone does not bypass it.
Create the interface and read its public key
/interface wireguard add name=wg-remote listen-port=51820 mtu=1420
/ip address add address=10.77.0.1/24 interface=wg-remote
:put [/interface wireguard get [find name=wg-remote] public-key]RouterOS generates the key pair automatically. Copy only the public key to the client. Keep private keys and client QR codes secret. In WinBox the same settings are under WireGuard and IP → Addresses. MTU 1420 is a starting point; paths with extra overhead may require a smaller value.
Purpose: Create the local encrypted interface and connected VPN subnet.
Expected result: wg-remote has 10.77.0.1/24 and a generated public key.
Verification: Use /interface wireguard print detail and /ip address print. Read only the public key.
Failure analysis: A duplicate name or address indicates an existing configuration; inspect it instead of rerunning add.
Rollback: Disable wg-remote first; remove it only after its dependent peers/address are reviewed.
Configure the phone or laptop
Create an empty tunnel in the official WireGuard app so the client generates its keys locally. Keep its private key on that device. The client's public key is needed when registering the router peer; fill the two key placeholders below with values from the correct endpoints.
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.77.0.2/32
MTU = 1420
[Peer]
PublicKey = <ROUTER_PUBLIC_KEY>
Endpoint = vpn.example.com:51820
AllowedIPs = 10.77.0.0/24, 192.168.88.0/24
PersistentKeepalive = 25This split tunnel routes only the office and VPN networks through WireGuard. Internet traffic uses the normal client connection. No DNS override is needed for access by IP. For internal names, configure your internal DNS address, include its network in AllowedIPs and permit its DNS traffic explicitly.
Purpose: Route only office destinations through this client identity.
Expected result: The client has 10.77.0.2/32 and the router public key.
Verification: Activate from an external network; inspect client routes and ping the VPN router.
Failure analysis: Check that keys were not swapped and the local LAN does not overlap.
Rollback: Deactivate the client tunnel and restore its prior DNS/route settings.
Register the client on MikroTik
/interface wireguard peers add interface=wg-remote public-key="<CLIENT_PUBLIC_KEY>" allowed-address=10.77.0.2/32 comment="Laptop"Give each device a separate peer, key and /32 address, such as 10.77.0.3/32. The peer field needs the client's public key, not the router's. Router allowed-address identifies addresses on the peer side; client AllowedIPs selects destinations sent towards the office. Avoid overlapping peer addresses on one interface. These fields do not replace routing or firewall policy.
Purpose: bind this device key to its /32 source and return destination. Expected result: one non-overlapping peer. Verification: print peers detail, then generate client traffic. Failure analysis: a wrong public key prevents a handshake; a wrong allowed-address can allow the handshake while rejecting payloads. Rollback: disable only the Laptop peer; never rotate the router key to revoke one device.
Permit the required traffic
First confirm the WAN interface list contains the actual internet interface, including PPPoE when applicable. Add these rules, then move each above the relevant drop in WinBox. Keep an established,related accept rule before forward drops so LAN replies can return. The example grants this client access to the whole office LAN; narrow destinations and ports for your environment.
/interface list member print
/ip firewall filter add chain=input action=accept in-interface-list=WAN protocol=udp dst-port=51820 comment="WG handshake"
/ip firewall filter add chain=input action=accept in-interface=wg-remote src-address=10.77.0.2 protocol=icmp comment="WG ping router"
/ip firewall filter add chain=forward action=accept in-interface=wg-remote src-address=10.77.0.2 dst-address=192.168.88.0/24 comment="WG client to office"Do not add WireGuard to the trusted LAN list just to make it work. Router management needs its own restricted input permission, for example TCP 8291 from your administrator peer only. Keep WinBox off the public WAN. The office hosts must use this MikroTik as gateway, or their gateway needs a return route for 10.77.0.0/24. A WAN-only masquerade requires no extra NAT for office access; broad source NAT rules may need a scoped exemption before them.
Purpose: separate tunnel admission, router diagnostics and LAN authorization. Expected result: only these flows are admitted. Verification: watch counters during a new connection; check RAW rules too if input counters stay at zero. Failure analysis: a rule below the default non-LAN drop never matches. Rollback: disable the rules by their WG comments and retest your original management path.
Connect and verify
Test from mobile Internet or another network outside the office to exercise the external path. Send traffic to 10.77.0.1 and then to a real office host; an idle peer need not have a recent handshake. A fresh last-handshake and rising rx/tx establish encrypted exchange, while application access still needs its own routing and firewall checks.
/interface wireguard peers print detail
/ip firewall filter print stats
/ip route printWithout a handshake, inspect endpoint DNS, the public IP, UDP forwarding, rule order and public keys. With a handshake but no LAN access, inspect AllowedIPs, return routes, forward policy and the host firewall. If only large transfers fail, examine MTU and path-MTU discovery. Disabling the firewall does not identify the failed layer and is not part of this test.
Optional: route client internet through the office
For an IPv4 full tunnel, change client AllowedIPs to 0.0.0.0/0 and choose a reachable DNS resolver. Add the following forward rule above relevant drops. Add the NAT rule only if your existing WAN masquerade does not already cover the VPN source. Do not add ::/0 without an IPv6 addressing, routing and firewall design: native client IPv6 can still use its local connection in this IPv4-only example.
/ip firewall filter add chain=forward action=accept in-interface=wg-remote src-address=10.77.0.2 out-interface-list=WAN comment="WG client internet"
/ip firewall nat add chain=srcnat action=masquerade src-address=10.77.0.0/24 out-interface-list=WAN comment="WG internet NAT"Purpose: Send IPv4 internet through the office only when required.
Expected result: IPv4 default traffic exits office WAN with working DNS.
Verification: Check the observed public IPv4 and test DNS plus native IPv6 separately.
Failure analysis: Check WAN forwarding/NAT counters; unresolved DNS is not necessarily a tunnel fault.
Rollback: Restore split AllowedIPs and remove only the new internet/NAT rules.
Separate example: connect two offices
Use a separate wg-site interface. A has public endpoint vpn.example.com and LAN 192.168.10.0/24; B has LAN 192.168.20.0/24 and initiates the tunnel, even behind NAT. Run the shared command on both routers, exchange their public keys, then run each side’s block. This is routed Layer 3 connectivity; WireGuard does not extend Ethernet broadcasts.
/interface wireguard add name=wg-site listen-port=51821 mtu=1420
:put [/interface wireguard get [find name=wg-site] public-key]# Router A
/ip address add address=10.78.0.1/30 interface=wg-site
/interface wireguard peers add interface=wg-site public-key="<B_PUBLIC_KEY>" allowed-address=10.78.0.2/32,192.168.20.0/24
/ip route add dst-address=192.168.20.0/24 gateway=wg-site
/ip firewall filter add chain=input action=accept in-interface-list=WAN protocol=udp dst-port=51821 comment="WG site handshake"
# Router B
/ip address add address=10.78.0.2/30 interface=wg-site
/interface wireguard peers add interface=wg-site public-key="<A_PUBLIC_KEY>" allowed-address=10.78.0.1/32,192.168.10.0/24 endpoint-address=vpn.example.com endpoint-port=51821 persistent-keepalive=25
/ip route add dst-address=192.168.10.0/24 gateway=wg-siteForward UDP 51821 to A if it has an upstream modem, and move A’s input rule above the drop. On BOTH routers add the two forward rules below before relevant drops. Each LAN must use its own MikroTik as gateway or have explicit return routes. Keep source NAT out of inter-site traffic; a masquerade scoped to WAN normally already does this. Test real hosts in both directions.
/ip firewall filter add chain=forward action=accept in-interface=wg-site src-address=192.168.10.0/24 dst-address=192.168.20.0/24 comment="WG A to B"
/ip firewall filter add chain=forward action=accept in-interface=wg-site src-address=192.168.20.0/24 dst-address=192.168.10.0/24 comment="WG B to A"These two rules are applied on each receiving router: they authorize traffic arriving on wg-site. Local LAN traffic heading into the tunnel must also be allowed by the existing outbound policy. If that policy denies it, add a matching LAN-to-wg-site rule on A for 192.168.10.0/24 to 192.168.20.0/24 and on B for the reverse. A direct LAN host test, followed by /ip firewall filter print stats, verifies both halves.
# Router A: only if outbound forward policy otherwise denies this flow
/ip firewall filter add chain=forward action=accept out-interface=wg-site src-address=192.168.10.0/24 dst-address=192.168.20.0/24 comment="WG LAN A outbound"
# Router B: same condition
/ip firewall filter add chain=forward action=accept out-interface=wg-site src-address=192.168.20.0/24 dst-address=192.168.10.0/24 comment="WG LAN B outbound"Purpose: Route distinct office prefixes through the correct peer.
Expected result: Both LAN gateways reach remote hosts without changing source addresses.
Verification: Test real hosts in both directions and inspect peer/forward counters.
Failure analysis: Check remote LAN in allowed-address, explicit route and host return gateway.
Rollback: Disable wg-site and review its remote routes before removing only new objects.
Measure MTU and monitor useful signals
For a 1500-byte IP underlay, WireGuard adds at least 60 bytes with outer IPv4 or 80 with outer IPv6. Encryption padding and additional encapsulation can reduce usable size further; 1420 is a conservative starting point. From a Linux client at MTU 1420, the following IPv4 probe totals 1420 bytes. Reduce payload in small steps if it fails, compare with ordinary ping, and permit ICMP fragmentation-needed/IPv6 Packet Too Big along the path.
ping -M do -s 1392 -c 4 10.77.0.1
ip route get 192.168.88.10Monitor application reachability, packet loss, peer transfer deltas and router CPU under a representative transfer. An idle peer may have an old handshake without a fault. MTU is a path property; a blanket TCP MSS change cannot fix UDP applications. Roll back a trial MTU to its recorded value on both endpoints.
Maintenance and rollback
Revoke a lost device by removing its peer. Protect configuration backups, use separate keys per device and review firewall counters. To undo the new setup, first disable its peers and interfaces, confirm the original management path, then remove only the rules and routes recorded for this change. Rehearse that sequence on the target RouterOS release before deployment.
/interface wireguard peers print detail
# Immediate revocation of this named device
/interface wireguard peers disable [find where interface=wg-remote comment="Laptop"]
# Disable the independent examples only after confirming management access
/interface wireguard disable [find where name=wg-remote]
/interface wireguard disable [find where name=wg-site]An ordinary export omits private keys. Keep an encrypted binary backup for same-device recovery, using an interactive password entry in WinBox Files/Backup; treat it as sensitive and check version/device recovery requirements. A new router key requires redistributing its new public key to clients. For rollback remove only the exact WG rules/routes listed in your change record after disabling the interface.
Questions from deployment reviews
Does AllowedIPs install RouterOS routes?
No. RouterOS allowed-address selects peer destinations and validates sources. Add remote LAN routes separately; wg-quick on Linux normally installs routes from AllowedIPs.
Will DDNS make a CGNAT router reachable?
No. Use a reachable hub, usable public IPv6 with matching policy, or an ISP public address. DDNS only updates a name.
Official references
MikroTik WireGuard configuration examples
RouterOS IPsec policies and authentication