MikroTik IPsec VPN: site-to-site config for RouterOS 7
A complete, copy-pasteable RouterOS 7 example for an IKEv2 site-to-site tunnel to an IPsec VPN server, including the two firewall rules that decide whether traffic actually flows.
The short answer
A MikroTik IPsec VPN on RouterOS 7 is built from five objects: a profile (IKE settings), a peer (the remote address, with exchange-mode=ike2), an identity (the pre-shared key or certificate), a proposal (ESP settings) and a policy (which subnets go into the tunnel). That gives you a policy-based MikroTik IPsec site-to-site tunnel. Two firewall changes make it actually pass traffic: a NAT accept rule placed before masquerade, and an exception so FastTrack doesn't bypass the IPsec policy.
This guide gives a complete example configuration for a branch router at 198.51.100.20 (LAN 192.168.10.0/24) connecting to an IPsec VPN server at 203.0.113.10 (networks 10.10.0.0/16) over IKEv2. Paste it block by block, replacing the addresses and the key with your own.
Values that must match on both sides
Before you touch the router, write down what both ends must agree on. Most tunnels that refuse to come up have a mismatch in this table.
| Setting | MikroTik (branch) | VPN server |
|---|---|---|
| Public IP / IKE identity | 198.51.100.20 | 203.0.113.10 |
| Protected networks | 192.168.10.0/24 | 10.10.0.0/16 |
| IKE version | IKEv2 | IKEv2 |
| IKE proposal | AES-256-CBC, SHA-256, DH group 20 (ECP-384) | AES-256-CBC, SHA-256, DH group 20 (ECP-384) |
| IKE lifetime | 28800 s (8 hours) | 28800 s (8 hours) |
| ESP proposal | AES-256-GCM, PFS group 20 (ECP-384) | AES-256-GCM, PFS group 20 (ECP-384) |
| Child SA lifetime | 3600 s (1 hour) | 3600 s (1 hour) |
| Authentication | Pre-shared key (same on both sides) | Pre-shared key (same on both sides) |
| Dead peer detection | On | On |
One RouterOS detail shapes the proposal: the IKE profile only offers CBC-mode ciphers (aes-128, aes-192, aes-256, plus older ones), while the ESP proposal does offer aes-256-gcm. So use AES-256-CBC with SHA-256 for IKE and AES-256-GCM for ESP, and set the server side to match. If you want to compare the two IKE versions first, see IKEv1 or IKEv2.
Example MikroTik IPsec site-to-site configuration
The blocks below are an example configuration for a MikroTik router running RouterOS 7.x, entered in the terminal. Names such as ty-ike2 are only labels; use your own if you prefer.
1. Profile and proposal
The profile holds the phase 1 (IKE) settings, the proposal holds the phase 2 (ESP) settings.
# Example configuration for a MikroTik router (RouterOS 7.x)
# Branch: WAN 198.51.100.20, LAN 192.168.10.0/24
# VPN server: 203.0.113.10, networks 10.10.0.0/16
# IKE (phase 1): AES-256-CBC, SHA-256, DH group 20, 8 h, DPD on
/ip ipsec profile
add name=ty-ike2 enc-algorithm=aes-256 hash-algorithm=sha256 \
dh-group=ecp384 lifetime=8h dpd-interval=30s dpd-maximum-failures=5
# ESP (phase 2): AES-256-GCM, PFS group 20, 1 h
/ip ipsec proposal
add name=ty-esp enc-algorithms=aes-256-gcm auth-algorithms=sha256 \
pfs-group=ecp384 lifetime=1h
2. Peer and identity
The peer says who to talk to and which IKE version to use. The identity carries the key and the IDs each side presents.
# The remote VPN server, IKEv2
/ip ipsec peer
add name=ty-server address=203.0.113.10/32 exchange-mode=ike2 \
profile=ty-ike2 send-initial-contact=yes
# Pre-shared key and identities (IP addresses as IDs)
/ip ipsec identity
add peer=ty-server auth-method=pre-shared-key secret="" \
my-id=address:198.51.100.20 remote-id=address:203.0.113.10 \
generate-policy=no
Use a long random pre-shared key (32 characters or more) and paste the same value on both sides. Never reuse a key between tunnels.
3. Policy
The policy is what makes this policy-based: traffic from 192.168.10.0/24 to 10.10.0.0/16 is encrypted and sent to the peer. Add one policy per pair of networks if the server side has more than one prefix.
# Which traffic goes into the tunnel
/ip ipsec policy
add peer=ty-server tunnel=yes action=encrypt level=require \
src-address=192.168.10.0/24 dst-address=10.10.0.0/16 proposal=ty-esp
4. NAT exemption, FastTrack exception and input rules
This is the step most guides skip. RouterOS performs source NAT before the IPsec policy lookup, so the default masquerade rule rewrites 192.168.10.x to 198.51.100.20 and the packet no longer matches the policy. The accept rule must sit above masquerade, hence place-before=0.
FastTracked connections also skip the IPsec policy lookup. The RouterOS documentation recommends exempting tunnel traffic from connection tracking in the raw table, which also saves CPU. The default configuration already accepts untracked traffic in the forward chain; check that yours does.
# Do not NAT traffic going into the tunnel (must be above masquerade)
/ip firewall nat
add chain=srcnat action=accept place-before=0 \
src-address=192.168.10.0/24 dst-address=10.10.0.0/16 \
comment="IPsec: no NAT towards VPN server"
# Keep tunnel traffic out of connection tracking, so FastTrack
# cannot bypass the IPsec policy
/ip firewall raw
add chain=prerouting action=notrack \
src-address=192.168.10.0/24 dst-address=10.10.0.0/16
add chain=prerouting action=notrack \
src-address=10.10.0.0/16 dst-address=192.168.10.0/24
# Allow IKE, NAT-T and ESP from the server (only needed if the
# input chain drops new connections from WAN, as the default does)
/ip firewall filter
add chain=input action=accept protocol=udp dst-port=500,4500 \
src-address=203.0.113.10 place-before=0
add chain=input action=accept protocol=ipsec-esp \
src-address=203.0.113.10 place-before=0
An alternative to listing subnets in the NAT rule is matching on the policy itself, ipsec-policy=out,ipsec, which accepts anything that will be encrypted. Both work; the subnet version is easier to read when you have one tunnel.
5. MSS clamping
ESP adds overhead, so full-size TCP segments no longer fit in a 1500-byte path. On RouterOS, clamp the MSS of TCP SYNs crossing the tunnel in the mangle table:
# Clamp TCP MSS for traffic through the tunnel (both directions)
/ip firewall mangle
add chain=forward action=change-mss new-mss=1360 passthrough=yes \
protocol=tcp tcp-flags=syn tcp-mss=1361-65535 \
src-address=192.168.10.0/24 dst-address=10.10.0.0/16
add chain=forward action=change-mss new-mss=1360 passthrough=yes \
protocol=tcp tcp-flags=syn tcp-mss=1361-65535 \
src-address=10.10.0.0/16 dst-address=192.168.10.0/24
1360 leaves room for ESP with AES-GCM, an outer IP header and NAT-T. If the WAN is PPPoE, lower it by another 8 bytes.
Adding a second network or a second site
If the server later protects another prefix, add a second policy with the same peer and proposal and the new dst-address, then add matching NAT, raw and mangle rules. Keep the policy list and the NAT exemption in step; a policy without its NAT exemption gives you a tunnel that negotiates but never carries the new traffic. A second branch (198.51.100.30, LAN 192.168.20.0/24) gets its own copy of this configuration with its own key, and reaches the first branch through the server if the server routes between tunnels.
What about route-based tunnels?
Policy-based is the RouterOS norm, and RouterOS 7 has no VTI-style interface for a plain IPsec tunnel. If you need routing (for example, several prefixes that change often), the usual approach is GRE or IPIP over IPsec, with the IPsec policy protecting the GRE or IPIP packets between the two public addresses. The ipsec-secret shortcut on GRE and IPIP interfaces is designed for MikroTik-to-MikroTik links. For a third-party server, a policy per network pair is simpler to operate. More on that choice in the IPsec configuration examples hub.
Verify the tunnel
Start with phase 1, then phase 2, then traffic. Generate traffic first if the tunnel isn't up yet: by default a policy-based tunnel is negotiated when matching traffic appears.
# Send traffic into the tunnel from a LAN address of the router
/ping 10.10.0.1 src-address=192.168.10.1 count=5
# Phase 1: the peer should be listed with state "established"
/ip ipsec active-peers print
# Phase 2: two SAs (one in each direction), counters increasing
/ip ipsec installed-sa print
# Policy: ph2-state should be "established"
/ip ipsec policy print detail
# Logs, if something is wrong
/system logging add topics=ipsec,!packet
/log print where topics~"ipsec"
What good looks like:
active-peersshows 203.0.113.10 with stateestablishedand an uptime that keeps growing.installed-sashows a pair of ESP SAs between 198.51.100.20 and 203.0.113.10 usingaes-gcm, and the byte counters increase while you ping.- The policy shows
ph2-state=established, notno-phase2. - The ping to 10.10.0.1 gets replies, and the server shows the same SAs from its side.
Common problems
Proposal mismatch
Log lines such as no suitable proposal found mean the two sides don't share an IKE or ESP proposal. Check the cipher, hash and DH group in the profile against the server's IKE settings, and the proposal's cipher and pfs-group against its ESP settings. A frequent cause on MikroTik is asking the server for GCM in IKE, which the profile can't offer, or a PFS group on one side and none on the other.
ID mismatch
If phase 1 fails with an authentication or identity error, compare my-id and remote-id with what the server expects. When the router sits behind NAT, its default ID is its private address, not 198.51.100.20; setting my-id=address:198.51.100.20 explicitly (as above) avoids that. A wrong pre-shared key produces a similar error, so check both.
NAT in the path
Two different NAT problems look alike. The router's own masquerade rule catching tunnel traffic gives you an established tunnel with zero packets in installed-sa: fix the order of the NAT rules. A NAT device in front of the router is handled by NAT-T (UDP 4500), which is on by default in the profile; make sure UDP 500 and 4500 reach the router and the server.
MTU and MSS
Ping works, small requests work, but file transfers, HTTPS pages or RDP sessions hang. That's fragmentation. Confirm the mangle rules are present and counting, and lower new-mss if the WAN has extra encapsulation. For a full checklist across vendors, see IPsec troubleshooting.
Running the other end
The MikroTik side is only half the tunnel. The other half needs a server with a static public IP that matches these proposals and keeps working while you add more sites. TunnelYard gives you a dedicated IPsec server with its own static IP, ready in 10–15 minutes, with presets per remote device and a peer config export for MikroTik, so both sides start from the same values. Several offices can connect to one gateway and share its static IP, up to your plan's limit. See the features or compare the same setup on strongSwan and pfSense.