i have a mikrotik router with WAN port taking internet from ISP router as DHCP client and then it gives network to the lan ports that half of them are in VLAN1 and half on VLAN2, with separete DHCP servers. I want the WAN port to be connected to VPN connection but also be able to disable the VPN easily. HOw to set it up? The VPN is hide.me
Assistant
MikroTik Router: WAN-to-VPN with VLANs and Easy VPN Toggle
You want your MikroTik router’s WAN port (which gets internet via DHCP from your ISP router) to connect through a VPN (hide.me), while serving two separate VLANs (each with its own DHCP server) to your LAN ports. You also want to be able to easily enable or disable the VPN for all outbound traffic.
Here’s how to set this up:
1. Basic Network and VLAN Setup
WAN port (e.g., ether1): DHCP client, gets internet from ISP router[10].
LAN ports: Split into two VLANs (VLAN1 and VLAN2), each with its own DHCP server[6][7].
Bridge: Used for VLAN management.
VLAN and DHCP Steps:
Create a bridge and add all LAN ports to it.
Define VLAN interfaces on the bridge for VLAN1 and VLAN2.
Assign IP addresses to each VLAN interface.
Set up a DHCP server for each VLAN interface[6][7].
2. VPN Client Configuration (hide.me)
Hide.me supports multiple VPN protocols (OpenVPN, WireGuard, IKEv2, etc.). MikroTik RouterOS v7 supports WireGuard and IKEv2 natively, and OpenVPN with some limitations.
Recommended: WireGuard (if supported by your RouterOS version)
Add a WireGuard interface.
Configure the interface with hide.me’s server public key, endpoint, and allowed IPs.
Add a peer with your private/public key pair.
Alternative: OpenVPN
Import hide.me’s .ovpn configuration.
Set up an OpenVPN client interface with the provided credentials.
General Steps:
Set up the VPN client interface.
Add a new routing table (e.g., “via-vpn”).
Create a default route (0.0.0.0/0) in this table, using the VPN interface as the gateway.
3. Routing and NAT
By default, all LAN traffic routes out via the WAN.
To force all LAN traffic through the VPN, use routing rules (policy routing) to direct traffic from VLAN1 and VLAN2 to the “via-vpn” routing table.
Set up NAT masquerade on the VPN interface for outbound traffic.
4. Easy VPN On/Off Toggle
Method 1: Script/Scheduler
Create two scripts:
Enable VPN: Adds routing rules to send LAN traffic via the VPN.
Disable VPN: Removes those rules, sending traffic directly via WAN.
Assign these scripts to buttons in WinBox or use the scheduler for quick toggling.
Method 2: Routing Mark
Use a routing mark for LAN traffic.
Change the default route for the routing mark to point to either the VPN or WAN.
Run the “enable-vpn” script to route all VLAN traffic through the VPN.
Run the “disable-vpn” script to send traffic directly via the WAN (ISP).
Notes
Adjust interface names and IP ranges to match your actual setup.
If you want only one VLAN to use the VPN, apply the routing rule only to that VLAN’s subnet.
For OpenVPN, configuration is similar but uses /interface ovpn-client instead of WireGuard.
Always test changes in safe mode or with backup access to avoid lockout.
This setup gives you full control: all LAN traffic can be routed through the VPN or directly to the ISP, and you can toggle the VPN on/off with a script or button in WinBox[7][10]. For detailed VPN client setup with hide.me, refer to their official MikroTik guides and ensure your RouterOS version supports the chosen VPN protocol.