MikroTik: per-device ProtonVPN WireGuard routing with ON/OFF toggle
RouterOS policy routing of one LAN device through ProtonVPN WireGuard, toggle script, troubleshooting and exports.
This runbook shows how to send the Internet traffic of a single LAN device (here a TV) through a ProtonVPN WireGuard tunnel on a MikroTik router, with a script-based ON/OFF toggle. Policy routing relies on a dedicated routing table and routing rule entries, with no mangle rule. Addresses are fictitious.
Overview
| Item | Value |
|---|---|
| Client device | 192.0.2.10 (static DHCP lease) |
| WireGuard interface | proton-tv |
| MTU | 1420 |
| Listen port | 13231 |
| Proton endpoint | 198.51.100.11:51820 |
| Allowed address | 0.0.0.0/0 |
| Persistent keepalive | 25s |
| Routing table | proton-tv-route |
| VPN table gateway | 192.0.2.12 |
The RouterOS objects are identified by their comment:
- route:
Client via ProtonVPN - LAN rule:
Client -> local LAN(src192.0.2.10/32, dst192.0.2.0/24,lookup-only-in-table, tablemain) - VPN rule:
Client -> ProtonVPN(src192.0.2.10/32,lookup-only-in-table, tableproton-tv-route)
The private key and the peer public key must never appear in documentation.
How it works
- VPN ON: LAN traffic of the client follows the
maintable; everything else (Internet) is sent by the VPN rule toproton-tv-route, then gateway192.0.2.12, theproton-tvinterface and the Proton server. - VPN OFF: rules, route and interface are disabled; the client uses the router's normal routing.
Toggle script
/system/script/add name=TV-VPN-TOGGLE policy=read,write,test source={
:local wg [/interface/wireguard/find where name="proton-tv"]
:local route [/ip/route/find where comment="Client via ProtonVPN"]
:local lanRule [/routing/rule/find where comment="Client -> local LAN"]
:local vpnRule [/routing/rule/find where comment="Client -> ProtonVPN"]
:if ([/interface/wireguard/get $wg disabled]) do={
/interface/wireguard/set $wg disabled=no
/ip/route/set $route disabled=no
/routing/rule/set $lanRule disabled=no
/routing/rule/set $vpnRule disabled=no
:put "TV VPN ON"
} else={
/routing/rule/set $vpnRule disabled=yes
/routing/rule/set $lanRule disabled=yes
/ip/route/set $route disabled=yes
/interface/wireguard/set $wg disabled=yes
:put "TV VPN OFF"
}
}
Run it:
/system/script/run TV-VPN-TOGGLE
Display the script:
/system/script/print where name="TV-VPN-TOGGLE"
In the output, the Flags: I - INVALID line is only the legend. The script is invalid only if the I appears in front of its own line (2 I name="TV-VPN-TOGGLE").
Checks
WireGuard interface (R = running, X = disabled):
/interface/wireguard/print detail where name="proton-tv"
Peer and handshake (useful fields: current-endpoint-address, current-endpoint-port, rx, tx, last-handshake). A recent handshake confirms Proton is answering:
/interface/wireguard/peers/print detail where interface=proton-tv
Route (As = active static, Xs = disabled static):
/ip/route/print detail where routing-table=proton-tv-route
Routing rules of the client (with VPN ON, both must be active):
/routing/rule/print detail where src-address=192.0.2.10/32
Boolean state of a rule (true = disabled, false = active):
:put [/routing/rule/get [find where comment="Client -> ProtonVPN"] disabled]
Confirm there is no mangle rule for the client:
/ip/firewall/mangle/print detail where src-address=192.0.2.10
Use comments rather than internal IDs (*1, *2): IDs can change and must not be hard-coded.
Manual commands
/interface/wireguard/enable [find where name="proton-tv"]
/interface/wireguard/disable [find where name="proton-tv"]
/ip/route/enable [find where comment="Client via ProtonVPN"]
/ip/route/disable [find where comment="Client via ProtonVPN"]
/routing/rule/set [find where comment="Client -> local LAN"] disabled=no
/routing/rule/set [find where comment="Client -> ProtonVPN"] disabled=no
To disable the rules, reverse the order (VPN then LAN) with disabled=yes. For normal use, prefer the script.
Live traffic
/interface/monitor-traffic proton-tv
/tool/torch interface=proton-tv
monitor-traffic shows the interface throughput; torch details addresses, protocols, ports and connections. Quit with Ctrl+C.
SSH access and Android / Termux shortcut
With an SSH alias mikrotik configured:
ssh mikrotik '/system/script/run TV-VPN-TOGGLE'
ssh mikrotik '/interface/wireguard/peers/print detail where interface=proton-tv'
ssh -t mikrotik '/interface/monitor-traffic proton-tv'
The -t option is required for interactive commands.
Termux script (~/.shortcuts/tasks/tv-vpn, make it executable with chmod +x):
#!/data/data/com.termux/files/usr/bin/bash
STATUS=$(ssh -o BatchMode=yes mikrotik '/system/script/run TV-VPN-TOGGLE')
termux-notification \
--id tv-vpn \
--title "TV VPN" \
--content "$STATUS"
Reusing the same --id replaces the previous notification instead of stacking them.
Troubleshooting: no Internet in VPN mode
Go in this order:
- Interface: if marked
X, run/interface/wireguard/enable [find where name="proton-tv"]. - Handshake:
last-handshakeshould be recent. - Route: if marked
Xs, run/ip/route/enable [find where comment="Client via ProtonVPN"]. - Rules: both must be active.
- Traffic:
monitor-trafficortorchonproton-tv.
Case seen: rules were active but Internet was gone. The last handshake was over 2 hours old because the interface and the route were disabled (X). Once enabled, traffic resumed. This is why the script toggles interface, route and rules together.
Export and backup
/export show-sensitive=no file=router-config
/interface/wireguard/export show-sensitive=no file=tv-proton-wireguard
/routing/export file=tv-proton-routing
/ip/route/export file=tv-proton-routes
/system/script/export show-sensitive=no file=tv-proton-scripts
/ip/firewall/export file=tv-proton-firewall
/file/print
Exporting before and after each VPN change makes it easy to compare configurations. The binary backup (/system/backup/save name=router-backup) may contain sensitive data: use a password and store it safely. It restores the same router; the .rsc export is better for documentation.
To complete a snapshot: /ip/address/print detail where interface=proton-tv, /ip/firewall/nat/print detail, /routing/table/print detail, /ip/dns/print.
Notes
- Some streaming services (Disney+ for example) may load their UI but refuse playback through a VPN; this does not mean the WireGuard tunnel is broken. Validate the tunnel with the handshake,
monitor-trafficand an unrelated service. - Never add a private key, password or private SSH key to the documentation.
Reference: RouterOS documentation.