This setup is a great way to give your home or office network a static Public IP, especially if you are behind CGNAT. You are essentially creating a "tunnel" where the VPS acts as the gateway to the internet for your MikroTik LAN.
Prerequisites
- A VPS (Ubuntu 22.04 or 24.04 recommended) with a Public IP.
- A MikroTik Router (ROS v7.x is required for WireGuard support).
- IP Forwarding enabled on the VPS.
Step 1: Configure the VPS (Server)
First, install WireGuard and enable packet forwarding so traffic can flow through the VPS.
Install WireGuard:
sudo apt update && sudo apt install wireguard -yEnable IP Forwarding: Edit
/etc/sysctl.confand uncommentnet.ipv4.ip_forward=1, then apply:sudo sysctl -p
Generate Keys:
wg genkey | tee privatekey | wg pubkey > publickeyCreate Config (
/etc/wireguard/wg0.conf): Replace<VPS_PRIVATE_KEY>with the key you just generated.[Interface] PrivateKey = <VPS_PRIVATE_KEY> Address = 10.0.0.1/24 ListenPort = 51820 # Replace 'eth0' with your VPS network interface name PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer] PublicKey = <MIKROTIK_PUBLIC_KEY> AllowedIPs = 10.0.0.2/32, 192.168.88.0/24Note:
192.168.88.0/24should be your MikroTik’s LAN subnet.
Step 2: Configure the MikroTik (Client)
Create WireGuard Interface: Navigate to WireGuard in Winbox. Click + to add a new interface.
Name:
wireguard-vpsListen Port:
51820Copy the Public Key (you need to paste this into the VPS config later).
Add IP Address to Interface: Go to IP > Addresses:
Address:
10.0.0.2/24Interface:
wireguard-vps
Add Peer: Under the WireGuard > Peers tab:
Interface:
wireguard-vpsPublic Key: (The Public Key from your VPS)
Endpoint:
VPS_PUBLIC_IPEndpoint Port:
51820Allowed IPs:
0.0.0.0/0(This allows all traffic to pass through the tunnel).Persistent Keepalive:
25s
Step 3: Routing LAN Traffic through the VPN
To make your LAN use the VPS IP, we use Policy Based Routing (PBR) so you don't lose access to the router itself.
Create a Routing Table: Go to Routing > Tables. Add a new table:
Name:
via-vpsFIB: Checked
Add a Route for the Table: Go to IP > Routes. Add a new route:
Dst. Address:
0.0.0.0/0Gateway:
10.0.0.1(The VPS WireGuard IP)Routing Table:
via-vps
Create a Mangle Rule: Go to IP > Firewall > Mangle. This identifies LAN traffic and marks it for the VPS route.
Chain:
preroutingSrc. Address:
192.168.88.0/24(Your LAN)Dst. Address:
!192.168.88.0/24(Important: NOT destination LAN)Action:
mark routingNew Routing Mark:
via-vps
Add NAT (Masquerade): Go to IP > Firewall > NAT:
Chain:
srcnatOut. Interface:
wireguard-vpsAction:
masquerade
Step 4: Finalizing
Start the WireGuard service on the VPS:
sudo wg-quick up wg0.Check the Peers tab in MikroTik. You should see "Rx" and "Tx" traffic increasing.
From a device on your MikroTik LAN, visit
icanhazip.com. It should now display your VPS Public IP.
Quick Troubleshooting Tips:
MTU Issues: If websites load slowly or partially, set the MTU on the WireGuard interface (both sides) to
1420or1320.Firewall: Ensure the VPS has port
51820 UDPopen in its cloud firewall (security groups).

Post a Comment