
WireGuard is a fast, modern, and secure VPN solution, making it an excellent choice for connecting two MikroTik routers, even on lower-power devices like hAP Lite. In this blog post, we’ll guide you through the process of configuring two MikroTik routers using WireGuard to create a secure connection between your home site and a remote site.
Pre-Requisites
- MikroTik routers with RouterOS 7.x or later (WireGuard is only available in RouterOS v7+).
- Ensure both devices (local and remote) are reset to factory settings or have no conflicting configurations.
- Access to both routers’ WinBox or WebFig for configuration.
- Basic knowledge of CIDR addressing and routing.
Step 1: Enable WireGuard on Both Routers
Router 1: Home Site
- Open WinBox or WebFig and connect to the home router.
- Navigate to Interfaces > WireGuard.
- Click the “+” button to add a new WireGuard interface:
- Name:
wg-home
- Listen Port:
51820
(default WireGuard port; ensure it’s open on your firewall/router).
- Name:
- Copy the Public Key (you’ll use this on the remote router later).
- Add an IP address to the WireGuard interface:
- Go to IP > Addresses, click “+”, and assign an IP:
Address: 192.168.100.1/24 Interface: wg-home
- Go to IP > Addresses, click “+”, and assign an IP:
Router 2: Remote Site
Repeat the above steps for the remote router with the following differences:
- Interface Name:
wg-remote
- Listen Port: Use a different port if required (e.g.,
51821
), but51820
is acceptable. - IP Address: Assign
192.168.100.2/24
towg-remote
.
Step 2: Add WireGuard Peers
Router 1 (Home Site):
- Go to Interfaces > WireGuard > Peers and click “+”.
- Configure the peer:
- Public Key: Enter the remote router’s public key (from
wg-remote
). - Allowed Address:
192.168.100.2/32
(the remote WireGuard IP). - Endpoint Address: Enter the WAN IP of the remote router (e.g.,
203.0.113.2
). - Endpoint Port: Enter the remote router’s WireGuard port (e.g.,
51820
).
- Public Key: Enter the remote router’s public key (from
Router 2 (Remote Site):
- Go to Interfaces > WireGuard > Peers and click “+”.
- Configure the peer:
- Public Key: Enter the home router’s public key (from
wg-home
). - Allowed Address:
192.168.100.1/32
. - Endpoint Address: Enter the WAN IP of the home router (e.g.,
203.0.113.1
). - Endpoint Port: Enter the home router’s WireGuard port (e.g.,
51820
).
- Public Key: Enter the home router’s public key (from
Step 3: Configure Firewall Rules
- Go to IP > Firewall > Filter Rules and add the following rules:
- Allow WireGuard traffic (UDP):
- Chain:
input
- Protocol:
udp
- Dst Port:
51820
(or the configured WireGuard port). - Action:
accept
- Chain:
- Allow WireGuard IPs:
- Chain:
input
- Src Address:
192.168.100.0/24
- Action:
accept
.
- Chain:
- Allow WireGuard traffic (UDP):
- Move these rules above any drop/reject rules.
Step 4: Configure Routing
- Route Traffic Through WireGuard:
- Go to IP > Routes.
- Add a route to the remote network:
- Destination Address:
192.168.2.0/24
(remote LAN). - Gateway:
192.168.100.2
(remote WireGuard IP).
- Destination Address:
- On the Remote Router, add a similar route:
- Destination Address:
192.168.1.0/24
(home LAN). - Gateway:
192.168.100.1
(home WireGuard IP).
- Destination Address:
Step 5: Test the Connection
- Ping the remote router from the home router to ensure the WireGuard tunnel is up:
- From Router 1: Ping
192.168.100.2
. - From Router 2: Ping
192.168.100.1
.
- From Router 1: Ping
- Verify that devices on the home LAN (
192.168.1.0/24
) can access devices on the remote LAN (192.168.2.0/24
), and vice versa.
Step 6: Optimize for Performance
- MSS Clamping: Add an MSS (Maximum Segment Size) rule to prevent fragmentation:
- Go to IP > Firewall > Mangle and add a new rule:
- Chain:
forward
- Out Interface:
wg-home
orwg-remote
- Action:
change-mss
- New MSS:
1380
.
- Chain:
- Go to IP > Firewall > Mangle and add a new rule:
- Use Fasttrack: Ensure fasttrack is enabled for optimal performance.
- Monitor Resources: hAP Lite is a low-power device, so monitor CPU usage during heavy VPN traffic.
Step 7: Secure the Configuration
- Use strong keys for WireGuard (minimum 256-bit).
- Restrict Allowed Addresses for each peer to only the necessary subnets.
- Keep RouterOS updated for the latest security patches.
Conclusion
You’ve successfully configured two MikroTik hAP Lite routers using WireGuard for secure connections between your home site and a remote site. This setup ensures a fast, modern, and secure VPN connection. Test your configuration thoroughly and fine-tune it for performance and reliability.