What do we get?

Your phone, from any Wi-Fi or mobile network, gets into your home or office network as if it were right there: you open the camera’s page, the NAS, WinBox on the router, and everything travels encrypted. With WireGuard and RouterOS 7 the router does most of the work: at the end it shows you a QR code, you point the WireGuard app at it and you’re done.

It’s the “road warrior”: a user roaming the world who connects back to base. It really does take just a few minutes, but first you need one thing: the router has to be reachable from the internet.

Diagram: a phone with the WireGuard app connected over the internet and the modem to the MikroTik, wg-casa interface, and from there to the LAN 192.168.88.0/24
The phone connects from any network to the home MikroTik with WireGuard and from there reaches the LAN.

Step 1: is the router reachable?

The phone needs to know where to knock. Two cases:

  • the line has a fixed public address: you use that;
  • the address changes: turn on IP Cloud and use the fixed name it gives you, as explained in the howto on MikroTik IP Cloud. In the examples it’s hx12345abcd.sn.mynetname.net.

⚠️ Warning: if the operator’s modem sits in front of the MikroTik, on the modem you have to forward UDP port 13231 to the MikroTik. Without that forward the phone knocks on the modem, and the modem doesn’t open.

Step 2: how do I create the WireGuard interface?

/interface wireguard add name=wg-casa listen-port=13231
/ip address add address=10.10.10.1/24 interface=wg-casa comment="Phone VPN"

The VPN network, 10.10.10.0/24, must be different from all the ones you already use, including the LAN’s. Check it with the Dojo’s IP calculator. The router creates its own key pair by itself.

Step 3: how do I open the firewall?

Two rules: one lets the VPN in from the internet, the other treats whoever comes from the VPN as if they were on the LAN.

/ip firewall filter add chain=input protocol=udp dst-port=13231 in-interface-list=WAN action=accept \
    comment="Phone WireGuard" place-before=0
/interface list member add list=LAN interface=wg-casa

With wg-casa in the LAN list, the connected phone can use the router’s DNS and reach WinBox, exactly like a PC on the network. If your firewall is the one from the Basic hardening of a MikroTik router, the WAN and LAN lists are already there.

Step 4: how do I add the phone?

One peer per phone. The trick that saves time: private-key=auto makes the router generate the phone’s key too, so the configuration is then already complete.

/interface wireguard peers add interface=wg-casa name=telefono-gianni private-key=auto \
    allowed-address=10.10.10.2/32 client-address=10.10.10.2/32 client-dns=10.10.10.1 \
    client-endpoint=hx12345abcd.sn.mynetname.net responder=yes
  • allowed-address and client-address: the phone’s address inside the VPN; each phone has a different one (.2, .3…);
  • client-dns: the phone will use the router as DNS, so it also resolves the home network’s names;
  • client-endpoint: the name or address from step 1, the one the phone connects to;
  • responder=yes: the router waits for the phone to call, without trying to reach out to it itself.

Step 5: how do I get the configuration onto the phone?

The router prepares it by itself, from the peer’s client-* fields:

/interface wireguard peers show-client-config [find name=telefono-gianni]

The command shows the configuration text and the QR code to scan; you do the same from WinBox, opening the phone’s peer in WireGuard → Peers. The text looks like this (the real one from my lab, without the keys):

[Interface]
ListenPort = 51820
PrivateKey = (the phone's key)
Address = 10.10.10.2/32
DNS = 10.10.10.1
[Peer]
PublicKey = (the router's key)
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = hx12345abcd.sn.mynetname.net:13231

On the phone install the official WireGuard app, tap +, choose creation from a QR code and scan it. Give the tunnel a name, turn it on, and that’s it.

⚠️ Warning: that QR code contains the phone’s private key. Don’t send it over chat and don’t leave it in a photo: whoever has it gets into your network. Show it on screen, have it scanned and close it.

Step 6: how do I check it works?

With the tunnel on, look at the peer on the router:

/interface wireguard peers print where name=telefono-gianni

last-handshake has to be from a few seconds or minutes ago, and rx and tx have to go up. In the lab I connected a Linux PC “from outside” with the configuration generated by the router: ping to the router (10.10.10.1) and to a LAN PC, web pages opened through the tunnel and names resolved by the router’s DNS. All on the first try.

Step 7: what if I only want the home traffic in the tunnel?

By default the configuration sends all the phone’s traffic into the tunnel (AllowedIPs = 0.0.0.0/0, ::/0): browsing goes out through home too. That’s what you want on a public Wi-Fi you don’t trust. If instead you only want the traffic toward the home network in the tunnel, list the networks in the peer:

/interface wireguard peers set [find name=telefono-gianni] \
    client-allowed-address=192.168.88.0/24,10.10.10.0/24

Regenerate the QR code and have it scanned again: now AllowedIPs contains only those networks. The parameter is there since RouterOS 7.21; all the details are in the MikroTik manual: WireGuard.

What do I check before putting it in production?

  • one peer per person and per device: if a phone is lost, you delete its peer and the others keep working;
  • the router keeps the phones’ private keys generated with private-key=auto. The export hides them, but whoever gets into the router can see them: protect it with the Basic hardening of a MikroTik router;
  • port 13231 is the only thing open to the internet: WinBox and SSH stay closed and you reach them from the tunnel.

Tested in the lab on PNETLab with a CHR running RouterOS 7.24.5 (stable) and a Debian 12 client behind another router, with the configuration generated by show-client-config: handshake, ping to the router and to the LAN, browsing and DNS through the tunnel, split tunnel with client-allowed-address, private key hidden in the export. Scanning the QR code with the phone’s WireGuard app was not tested in the lab.

Frequently asked questions

How do I connect the phone to the MikroTik with WireGuard?

Create a WireGuard interface and a peer with private-key=auto and the client-* fields, then generate the configuration with /interface wireguard peers show-client-config and scan the QR code with the WireGuard app.

Does it work if the router has a dynamic address?

Yes: with IP Cloud the router has a fixed name (serial-number.sn.mynetname.net) that follows the address; you use that name as client-endpoint.

Why won’t the phone connect?

The most common causes: UDP port 13231 isn’t accepted in the input firewall, or the modem in front of the MikroTik doesn’t forward it. On the router, in the peer, an empty last-handshake means the packets aren’t arriving.

How do I send only the home traffic through the tunnel?

With client-allowed-address in the peer (since RouterOS 7.21), listing the home and VPN networks; then regenerate the QR code.

Is the QR code sensitive data?

Yes: it contains the device’s private key. Whoever has it can connect to the network, so it should only be shown on screen and never sent or photographed.