Site-to-site VPN on MikroTik: WireGuard for branch offices and remote staff
How to connect two offices and remote employees with WireGuard on MikroTik running RouterOS 7: the addressing plan, tunnel and route configuration, firewall rules and what to test before handover.
Alexei Sergeev4 min read
When a company opens a second office or a warehouse, or gets remote employees, the same task comes up: they need access to shared resources such as the file server, the accounting system, printers and internal services. All of that must not be exposed to the internet, so a VPN is set up between the sites. RouterOS 7 has WireGuard for this, and in most new projects it is what I choose.
Why WireGuard rather than IPsec or L2TP
IPsec is reliable and supported by almost any equipment, but its configuration is verbose, and troubleshooting negotiation phases takes time. L2TP without IPsec does not encrypt traffic, and with IPsec it inherits IPsec's complexity. WireGuard is simpler: each side has a key pair, the tunnel takes a few lines to describe, and reconnection after the provider changes your address happens by itself.
Criterion
WireGuard
IPsec (IKEv2)
L2TP/IPsec
Configuration complexity
Low
High
Medium
Support in RouterOS
Since version 7
For a long time
For a long time
Clients for PCs and phones
Official apps
Built into the OS
Built into the OS
Compatibility with third-party equipment
Growing, but not everywhere
Almost everywhere
Almost everywhere
IPsec remains the right choice if the equipment on the other end does not support WireGuard.
Layout and addressing
The main rule: the office subnets must not overlap. If both offices run an out-of-the-box router with the 192.168.88.0/24 network, routing between them will not work, and one of the networks will have to be renumbered. That is worth doing before setting up the VPN, not after.
In the example below, the head office uses 10.10.0.0/16, the branch uses 10.20.0.0/16, and a small service network, 10.255.0.0/24, is set aside for the tunnel itself.
Setting up the tunnel between offices
A WireGuard interface is created on each router, and RouterOS generates the keys when it is created. The public key of one side goes into the peer settings on the other. The private key is never shared.
office-a.rsc
# Head office: has a permanent public address; the other sites connect to it
/interface wireguard
add name=wg-sites listen-port=13231
/ip address
add address=10.255.0.1/24 interface=wg-sites
/interface wireguard peers
add interface=wg-sites comment="branch" public-key="<branch public key>" \
allowed-address=10.255.0.2/32,10.20.0.0/16
/ip route
add dst-address=10.20.0.0/16 gateway=wg-sites
/ip firewall filter
add chain=input protocol=udp dst-port=13231 action=accept comment="WireGuard" place-before=0
office-b.rsc
# Branch: connects to the head office on its own
/interface wireguard
add name=wg-sites listen-port=13231
/ip address
add address=10.255.0.2/24 interface=wg-sites
/interface wireguard peers
add interface=wg-sites comment="head office" public-key="<head office public key>" \
endpoint-address=203.0.113.10 endpoint-port=13231 \
allowed-address=10.255.0.1/32,10.10.0.0/16 persistent-keepalive=25s
/ip route
add dst-address=10.10.0.0/16 gateway=wg-sites
If the branch has no permanent public address, or even sits behind the provider's NAT, that is not a problem: the branch initiates the connection, and persistent-keepalive keeps the NAT from forgetting it.
Remote employees
Employees connect to the same router, but I put them on a separate interface and a separate subnet. That makes the rules simpler: a remote accountant needs access to the accounting system and the documents folder, not to the whole server network. Each employee gets their own key: if a laptop is lost or someone leaves, one peer is disabled and everyone else keeps working.
Firewall: what to allow through the tunnel
A VPN connects networks, but it does not have to open everything to everyone. Between offices I allow specific directions: branch workstations to the head office servers on the required ports, and the administrator to the management network. Guest and IoT segments are not let into the tunnel at all. If the offices already have VLAN segmentation, the VPN rules fit naturally on top of it.
What to test before handover
Reboot both routers and make sure the tunnel comes up on its own.
Check that it works after the branch's public address changes (reconnect the provider cable or switch to the backup link).
Test real applications, not just ping: opening files, the accounting system, printing. If large files hang while small ones open, the cause is usually MTU, which is smaller than usual with WireGuard.
Make sure an employee whose key was disabled can no longer connect.
Write the layout, keys and the procedure for adding a new employee into the documentation.
If an office has two providers, the tunnel should be built with the backup link in mind; otherwise, an outage at the main provider will cut the branch off from head office resources.
Need to connect offices or remote employees?
Tell me how many sites there are and which resources people need. I will propose a layout, set up the tunnels and access rights and hand over the documentation.
Why a flat network where every device sees every other one is the main source of trouble in a small office, and how to split it into VLANs on MikroTik with RouterOS 7: the layout, bridge configuration, firewall rules an…
How to set up a second internet connection so the office switches to it automatically and back again when the main provider recovers. Recursive routing on MikroTik, reachability checks and the pitfalls.
Dead zones, drops when walking between rooms and slowness in the meeting room: I go through the common causes of office Wi-Fi problems and how I design a wireless network so that it works reliably.
Read →
This site can use Yandex Metrica for anonymised visit statistics. Allow it?
Learn more