A Comprehensive Guide to WireGuard Routing on MikroTik Routers (as Client)
Routing traffic through a WireGuard VPN using a MikroTik router requires careful configuration of interfaces, peers, IP addresses, and routes.
What is WireGuard?
WireGuard is a modern VPN protocol known for its simplicity, speed, and security. MikroTik routers support WireGuard from RouterOS v7.x, making it easier to set up secure tunnels for routing network traffic.
Let’s jump in.
Prerequisites
- A WireGuard config file (from any WireGuard-enabled server or MikroTik).
- A working internet connection in your MikroTik router.
- RouterOS 7.x or later.
Your Config Should Look Like This:
[Interface]
PrivateKey = oMZz05ZTTxFawluDF6VK86AKpG2WwcZiQKBc4vUbNFU=
Address = 10.7.0.2/24
DNS = 9.9.9.9, 1.1.1.1
[Peer]
PublicKey = L+ZDsJCz9RZ4tYty2gZawz36bIaIgEz2SCT9ohLowgI=
PresharedKey = 355/3KsgpAY6f3frZ2vdbEKMEZUdGqS0hOwxggtbFgzQ=
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = 203.171.53.52:51820
PersistentKeepalive = 25
Configuration Steps
1. Enable WireGuard Interface
- Log in to your MikroTik router via WinBox or WebFig.
- Go to Interfaces > WireGuard.
- Click Add (+) and set the following:
- Name: Assign a name to the WireGuard interface (e.g.,
wg1
). - MTU: Default is
1420
. - Private Key: Your WireGuard server’s private key.
- Public Key: This will be auto-generated.
- Listen Port: Set if required (default:
51820
).
- Name: Assign a name to the WireGuard interface (e.g.,
- Click Apply and OK.
2. Configure WireGuard Peer
- Go to WireGuard > Peers.
- Add a new Peer:
- Public Key: WireGuard server’s public key.
- Allowed Addresses: Specify traffic routing (e.g.,
0.0.0.0/0
for all traffic). - Endpoint: Enter the server IP and port (e.g.,
198.51.100.10:51820
). - Preshared Key: Enter the preshared key (if applicable).
- Persistent Keepalive: Set to
25
seconds for NAT stability.
- Click Apply and OK.
3. Assign IP Address to the WireGuard Interface
- Go to IP > Addresses.
- Add a new IP address:
- Address: Assign the IP provided by the WireGuard server (e.g.,
10.7.0.2/24
). - Interface: Select the WireGuard interface (e.g.,
wg1
).
- Address: Assign the IP provided by the WireGuard server (e.g.,
- Click Apply and OK.
4. Add Routes
To route all traffic through the WireGuard interface:
- Go to IP > Routes > Add.
- Configure:
- Destination:
0.0.0.0/0
(to route all traffic). - Gateway: Enter the WireGuard server’s IP or local gateway (e.g.,
10.7.0.1
). - Interface: Select
wg1
. - Routing Table: Choose a different routing table (recommended). If not created, create one from Routing > Tables > New (+).
- Destination:
- Click Apply and OK.
5. Configure NAT (Optional)
If the router handles LAN traffic:
- Go to IP > Firewall > NAT.
- Add a new rule:
- Chain:
srcnat
. - Out. Interface:
wg1
. - Action:
masquerade
.
- Chain:
Check the Last Handshake timestamp under the WireGuard interface; if it’s not updating, the connection to the WireGuard server isn’t established.
How to Check It’s Working
- Go to Routing Rule, then add your PC’s IP (or a specific IP) to the local address.
- Set
0.0.0.0/0
as the destination. - Use the created WireGuard routing table. Traffic should now pass through the VPN.
Alternatively, you can:
- Add address ranges (e.g.,
192.168.50.192/26
) to route specific IPs through the VPN. - Increase the distance of your primary interface (e.g.,
pppoe
orether1
) and lower the distance for the WireGuard interface to prioritize VPN routing.
Routing Exceptions
To avoid certain local subnets or IPs being routed through the VPN (split-tunneling):
- Add separate routes for those subnets:
- Destination: Your LAN subnet (e.g.,
192.168.1.0/24
). - Gateway: Your router’s LAN gateway (e.g.,
192.168.1.1
). - Interface: Leave blank or set to your main internet interface (e.g.,
ether1
orpppoe
).
- Destination: Your LAN subnet (e.g.,
- Ensure these routes have a higher priority (lower distance value).
By following these steps, you can configure your MikroTik router to securely route traffic through WireGuard while maintaining flexibility for exceptions. Enjoy the enhanced speed and simplicity of WireGuard VPN!