MikroTik WireGuard Setup: Server, Windows and Android
MikroTik WireGuard setup on RouterOS 7: one key per device, Windows and Android clients via QR code, access only to the networks you need, and revocation.
On this page
The owner wants to watch the cameras and log in to the office computer from home — and the most common "way" to do it is forwarding the recorder's ports and RDP to the internet. After these steps, the office exposes no services to the outside except WireGuard, which stays silent to anyone without a key; every device has its own key and reaches only the networks it needs; a lost phone is cut off with a single command.
Plan
| Step | What we do | Time |
|---|---|---|
| 1 | Check the public address and set up a permanent name | 10 min |
| 2 | Create a WireGuard server on the router | 10 min |
| 3 | Open the WireGuard port and restrict where VPN users can go | 10 min |
| 4 | Add a device: key, address, configuration | 10 min per device |
| 5 | Connect Windows | 10 min |
| 6 | Connect Android | 5 min |
| 7 | Prepare access revocation | 5 min |
| 8 | Test from outside and inside | 15 min |
Why a VPN, not port forwarding or the cloud
- Hikvision and Dahua recorders and cameras with forwarded ports are found by scanning: the CISA KEV catalog lists vulnerabilities that bypass the password (video surveillance under NBG requirements).
- RDP exposed to the internet is one of the most common entry points for ransomware.
- The manufacturer's cloud access is one more account; if it is hacked, all your cameras are open.
What follows from this:
- Neither the recorder nor RDP should be reachable from outside → only WireGuard (step 3).
- A leak of one key must not open everything → one key per device (step 4).
- A VPN client must not see the cash desk → access only to the camera and admin networks (step 3).
- A lost phone is a key to the office → revocation in a minute (step 7).
Step 1. Check the public address and set up a permanent name
How to do it.
- The address on the router's WAN interface:
/ip address print where interface=ether1. If it is a private address (192.168.x.x, 10.x.x.x, 100.64–127.x.x), compare it with the public address websites see:/tool fetch url="https://api.ipify.org" output=user.- They match, or the ISP's router is in bridge mode — you have a public address, all good.
- They don't match — the ISP's router sits in front: forward only the WireGuard UDP port to the MikroTik on it, or ask the ISP to switch it to bridge mode.
- The public address is in the 100.64.0.0/10 range — you are behind the ISP's NAT (CGNAT): ask the ISP for a public (preferably static) address; terms differ between ISPs, so check your contract or ask support.
- A permanent name in case the address changes:
/ip cloud set ddns-enabled=yes
/ip cloud print
Write down dns-name — this is the server address for the clients.
Done when: the address is public or only the WireGuard UDP port is forwarded, and you have a permanent name.
Step 2. Create a WireGuard server on the router
/interface wireguard add name=wg-staff listen-port=13231 comment="VPN for owner and admin"
/ip address add address=10.99.0.1/24 interface=wg-staff
/interface wireguard print
Save the interface's public-key — the clients will need it. Port 13231 is an example; any UDP port works.
Done when: the wg-staff interface exists and has a public key.
Step 3. Open the WireGuard port and restrict where VPN users can go
How to do it. The rules go before "everything else", as in the article on exchange office network segmentation, step 5:
/ip firewall filter
add chain=input protocol=udp dst-port=13231 action=accept comment="WireGuard" place-before=[find comment="I6 everything else to router"]
add chain=forward in-interface=wg-staff out-interface=vlan20-cams action=accept comment="VPN -> cameras" place-before=[find comment="F6 everything else"]
add chain=forward in-interface=wg-staff out-interface=vlan30-staff dst-address=10.10.30.10 protocol=tcp dst-port=3389 action=accept comment="VPN -> office PC RDP" place-before=[find comment="F6 everything else"]
- From the VPN — only the camera network and one office computer over RDP; the cash desk network is not allowed.
- Router management from the VPN (Winbox, SSH) — only from the admin's address:
add chain=input in-interface=wg-staff src-address=10.99.0.10 protocol=tcp dst-port=8291,22 action=accept place-before=[find comment="I6 everything else to router"].
Done when: only UDP 13231 is open to the outside, and only the required addresses are allowed from the VPN.
Step 4. Add a device: key, address, configuration
Rule: one peer — one device. The owner's phone, the owner's laptop and the admin's laptop are three peers with different keys.
Option A (RouterOS 7.15 and newer) — the router generates the key and a ready-made configuration itself:
/interface wireguard peers
add interface=wg-staff name=owner-phone private-key=auto allowed-address=10.99.0.2/32 \
client-address=10.99.0.2/32 client-dns=10.10.30.1 \
client-endpoint=<dns-name from step 1>:13231 \
client-allowed-address=10.10.20.0/24,10.10.30.10/32 \
persistent-keepalive=25s comment="Owner phone"
/interface wireguard peers show-client-config [find name=owner-phone]
The last command shows the configuration text and a QR code. It contains the client's private key — show the QR code only on screen next to the phone, and don't send the configuration through a messenger.
Option B (any RouterOS 7 version) — the client generates the key (steps 5–6), and only its public key is added to the router:
/interface wireguard peers
add interface=wg-staff public-key="<public key from the app>" allowed-address=10.99.0.3/32 comment="Owner laptop"
Done when: every device has its own peer with a clear comment.
Step 5. Connect Windows
How to do it.
- Install WireGuard from the official site wireguard.com → Install.
- Option A: Add Tunnel → Import tunnel(s) from file — the configuration file from step 4 (carry it over on a USB stick, not by email). Option B: Add Tunnel → Add empty tunnel… — the app generates the keys; add the rest:
[Interface]
PrivateKey = <generated by the app>
Address = 10.99.0.3/32
DNS = 10.10.30.1
[Peer]
PublicKey = <public-key of the wg-staff interface from step 2>
Endpoint = <dns-name from step 1>:13231
AllowedIPs = 10.10.20.0/24, 10.10.30.10/32
PersistentKeepalive = 25
Put the public key from the tunnel window on the router (step 4, option B).
3. AllowedIPs — only the office networks: the rest of the laptop's internet traffic goes as usual, and only office traffic goes through the VPN.
4. Activate.
Check: in the tunnel window, "Latest handshake" keeps updating, and ping 10.10.20.10 (the recorder) replies.
Done when: the laptop sees the recorder and the office computer, but not the cash desk.
Step 6. Connect Android
How to do it.
- WireGuard from Google Play (developer — WireGuard Development Team).
- Option A: + → Scan from QR code — the QR code from the Winbox or terminal screen in step 4.
- Option B: + → Create from scratch — fill it in as in step 5, and put the phone's public key on the router.
- In the camera app (Hik-Connect, DMSS), add the recorder by its local address
10.10.20.10, not through the cloud (video surveillance under NBG requirements, step 4).
Done when: with the VPN on, the cameras are visible; with it off, they are not.
Step 7. Prepare access revocation
When: a phone or laptop is lost or stolen; an employee has left; a key may have fallen into the wrong hands.
/interface wireguard peers disable [find comment="Owner phone"]
# or permanently
/interface wireguard peers remove [find comment="Owner phone"]
A new device gets a new peer with a new key (step 4); the old key is never reused. Record the revocation in the log. Add this item to card 1 of the business continuity plan ("phone stolen").
Check: after disable, the phone doesn't connect, and "Latest handshake" stops updating.
Done when: the revocation procedure is written down and tested on a test peer.
Step 8. Test from outside and inside
| From | What | Expected |
|---|---|---|
| Mobile internet, VPN off | nmap -Pn -p 80,443,554,3389,8000,8291,37777 <dns-name> |
all filtered |
| Mobile internet, VPN off | nmap -Pn -sU -p 13231 <dns-name> |
open|filtered — WireGuard stays silent without a key |
| Phone, VPN on | cameras | visible |
| Phone, VPN on | cash desk address 10.10.10.10 |
doesn't open |
| Router | /interface wireguard peers print detail |
a recent last-handshake only for peers connected right now |
| Revoked peer | connection | no handshake |
Done when: every row matches.
Checklist
| # | What to check | How to verify | ☐ |
|---|---|---|---|
| 1.1 | The public address is public, or only WireGuard is forwarded | The address from /ip address print where interface=ether1 matches the output of /tool fetch url="https://api.ipify.org" output=user — or only the WireGuard UDP port is forwarded on the ISP's router |
☐ |
| 1.2 | The address is not behind the ISP's NAT | The public address is not in the 100.64.0.0/10 range (100.64.x.x–100.127.x.x) |
☐ |
| 1.3 | A permanent name exists | /ip cloud print — dns-name is written down, public-address equals the current public address |
☐ |
| 2.1 | The WireGuard interface is created | /interface wireguard print — wg-staff, listen-port=13231, public-key present |
☐ |
| 2.2 | The interface has its own address | /ip address print where interface=wg-staff — 10.99.0.1/24 |
☐ |
| 3.1 | The WireGuard port rule sits before the deny rule | /ip firewall filter print where chain=input — the WireGuard rule is above I6 everything else to router |
☐ |
| 3.2 | The cash desk network is closed to the VPN | /ip firewall filter print where in-interface=wg-staff — only cameras and RDP to one computer are allowed, no rule to the cash desk network |
☐ |
| 3.3 | Router management from the VPN — only from the admin's address | There is one rule for Winbox and SSH from wg-staff, with src-address=10.99.0.10 |
☐ |
| 4.1 | One peer — one device | /interface wireguard peers print — every peer has its own comment with the device name, public keys don't repeat |
☐ |
| 4.2 | Peer addresses don't overlap | Every peer has its own allowed-address with a /32 mask |
☐ |
| 4.3 | Private keys were never sent over | Ask the owner and the admin: configurations were transferred only by on-screen QR code or USB stick; there are no .conf files in messengers or email |
☐ |
| 5.1 | The laptop connects | "Latest handshake" keeps updating in the WireGuard tunnel window | ☐ |
| 5.2 | The laptop sees the recorder but not the cash desk | ping 10.10.20.10 replies, ping 10.10.10.10 doesn't |
☐ |
| 5.3 | Only office traffic goes through the VPN | In the tunnel configuration, AllowedIPs contains only office networks, no 0.0.0.0/0 |
☐ |
| 6.1 | The app is the official one | In Google Play, the developer is WireGuard Development Team | ☐ |
| 6.2 | Cameras are visible only with the VPN | VPN on — cameras open; VPN off — they don't | ☐ |
| 6.3 | The recorder is added by its local address | In Hik-Connect or DMSS, the recorder is added as 10.10.20.10, not through a cloud account |
☐ |
| 7.1 | Access revocation is tested | disable on a test peer — the device doesn't connect, "Latest handshake" stops updating |
☐ |
| 7.2 | The revocation procedure is written down | Card 1 of the business continuity plan contains the revocation command and who runs it | ☐ |
| 8.1 | Everything except WireGuard is closed from outside | From mobile internet, nmap -Pn -p 80,443,554,3389,8000,8291,37777 <dns-name> — all ports filtered |
☐ |
| 8.2 | WireGuard stays silent without a key | nmap -Pn -sU -p 13231 <dns-name> — open|filtered |
☐ |
| 8.3 | Handshakes only for connected peers | /interface wireguard peers print detail — a recent last-handshake only for those currently on the VPN |
☐ |
Questions
Do I need WireGuard if the recorder has a cloud app?
The cloud means a permanent connection from the recorder to someone else's server and an account that shows all your cameras. WireGuard is set up once, and nothing of the office is exposed to the outside.
The MikroTik is behind the ISP's router without a public address — what now?
Run WireGuard on an inexpensive cloud server: both the office router and the phones connect to it as clients. This is a separate setup with its own access rules.
No handshake: the client doesn't connect. What should I check?
In order: the client has the correct Endpoint (the name from step 1) and port; the UDP port rule sits above the deny rule (step 3); if the ISP's router is in front, this UDP port is forwarded on it. And the keys aren't mixed up: the router holds the client's public key, the client holds the public key of the wg-staff interface.
There is a handshake, but the cameras don't open. Why?
The tunnel works — routes or rules are blocking the traffic. Check that the camera network is in the client's AllowedIPs, that the VPN -> cameras rule sits above "everything else" (step 3), and that the recorder's default gateway is the MikroTik: otherwise replies won't return into the tunnel.
Can I send all of the phone's internet traffic through the office?
Yes: set AllowedIPs = 0.0.0.0/0 in the client, and on the router allow traffic from wg-staff to the internet and add NAT for 10.99.0.0/24. You don't need this to reach the cameras and the computer: all of the phone's traffic would go through the office connection and load it.
WireGuard, OpenVPN, L2TP or PPTP — which one to choose?
For owner and admin access — WireGuard: it is built into RouterOS 7, takes one interface and one key per device, and doesn't respond at all without a key — a scanner can't tell the port is open (step 8). PPTP is outdated and insecure — don't use it.
Does this work on iPhone and Mac?
Yes: WireGuard has official apps in the App Store and the Mac App Store. Connecting works as in steps 5–6: a QR code or a configuration file, with a separate peer for each device.
Which port should I use — does it have to be 13231?
No: 13231 is the RouterOS default port; any free UDP port works as long as it is the same in the step 3 rule, in the clients and in the forwarding on the ISP's router. WireGuard runs over UDP only: if it doesn't connect from someone else's Wi-Fi but does from mobile internet, the port is blocked by that network, not by your router.
Can I add a password or a second factor to WireGuard?
WireGuard has no built-in second factor: access is granted by the key on the device. So the protection is the screen lock on the phone and laptop (Android phone protection, step 2), a separate key for every device (step 4) and fast revocation (step 7).
How can I tell that someone else is using a key?
/interface wireguard peers print detail shows last-handshake and current-endpoint-address for each peer — the address it connected from. A recent handshake from a device whose owner didn't turn the VPN on, or an unfamiliar connection address — revoke the peer (step 7) and issue a new key.
The VPN doesn't connect after failover to the backup ISP. What should I do?
Check that the clients connect by the name from step 1, not by IP: the name moves to the office's new address on its own, an address in the configuration doesn't. If the backup is LTE or an ISP whose address is behind NAT, inbound VPN won't work through it (MikroTik dual WAN failover, step 7).
Note: the client-* parameters and show-client-config are available in newer RouterOS 7 versions — on older ones, use option B.