How to configure a MikroTik IKEv2 VPN & connect iOS devices (iPhone/iPad)

How to configure a MikroTik IKEv2 VPN & connect iOS devices (iPhone/iPad)

So you want a better Remote Access VPN option for MikroTik?

Lets look at what it takes to setup a IKEv2 VPN that works with iOS Devices. For the record, the configuration should also support Mac OSX VPN clients but I have not tested it. Oh, & I tested this configuration on an iPhone X running iOS 11.

Create Self-Signed Certificates in RouterOS

This procedure is really easier to do from the cli so open a terminal window in winbox and follow along.

Generate a Self-Signed CA certificate

Generate a certificate for the vpn server (the router), sign it and trust it.

Generate a certificate for the vpn client (your phone) and sign it.

Export the CA certificate to a file

Your exported CA certificate is now in Files with the filename cert_export_my.ca.crt

Export the Client to a file w/ a Passphrase (required for iOS import)

Your exported client key pair is now in Files with the filename cert_export_vpn.client.p12

Note: If you were curious, pkcs12 is a bundle that contains the private key and signed certificate. This is a file format that iOS understands.


Configure IKEv2 in RouterOS

Create an IP Pool

Check first you may already have one if you have an existing PPTP, LT2P, or SSTP VPN setup. You can reuse the existing pool or create a new one just for IKEv2 VPN clients.

Here is the IP pool I added…

Create a new IPSec Mode Config

This is the glue that tells the IPSec Peer what IP pool to use.

Create an IPSec Proposal

Create an IPSec Peer

Wow, that’s one big nasty RoS command, here are some screenshots to compare.


Install Certificates on the phone

We need to install both the Client certificate and the CA certificate on your device.

For this process we are going to need a little helper(python) to get the certifications on the iPhone. You see, iOS will let you use Safari to install certificates from a website. We can copy down the two required certificate files and use python to run a quick and fast webserver.

  1. Copy the .crt,.p12 files to a directory on your pc.In winbox, just click Files and drag them out to a folder on your PC. You can also grab the files via FTP.
  2. Open a command prompt and CD to the directory.
  3. Issue the following command to start serving the files over http
  4. From your phone navigate to http://{PCsIPADDR}:8000/
  5. Click on and install each certificate entering the CA passphrase when prompted.

    Note: Upon installation of each certificate you will first be asked to enter your phone’s unlock code.

Alternative Certificate Installation Method

Don’t have or want to install python? You can also email these certificates to yourself as attachments and install them from the mail client on your phone.


Create a new VPN profile in iOS

  1. Open Setting | VPN
  2. Tap Add VPN Configuration…
  3. Choose type IKEv2
  4. Enter the remaining settings as followsDescription: IKEv2 MikroTikServer: {external ip of router}Remote ID: vpn.server (cn from server certificate)Local ID: vpn.client (cn from client certificate)User Authentication: None (trust me that’s the right one)

    Use Certificate: On

    Certificate: Choose the vpn.client certificate from the list

  5. Tap Done

The steps are almost identical on an iPad, I’m sure you will figure it out ;).


Testing out your shiny new IKEv2 VPN

  1. Tap the Back arrow from the VPN settings screen.
  2. Tap on the newly created VPN profile and toggle the VPN on.

If all your stars align, you should see Connected

Browse over to http://whatsmyip.org to see that you are now coming from the IP of your VPN router.

That’s it, I how you enjoyed this step-to-step guide on configuring a MikroTik IKEv2 VPN that iOS devices can connect to and use.  If you have questions or comments please take a moment to leave me a comment below.


Troubleshooting IKEv2 Connection Issues

If you are still reading this… then your VPN probably didn’t connect. First, take a deep breath and go over the steps above to verify your MikroTik config is correct. Don’t give up, I promise we will get through this!

I’ll throw out some common pitfalls and if that doesn’t help, we will look at some of the IPSec debug logging

Issue: VPN status just says Connecting… and then finally times out.

Resolution: Make sure you don’t have a blocking firewall rule on the input chain. If your input filewall ruleset is rather restrictive make sure you add these rules towards the top of your IP | Firewall | Filter Rules

Issue: VPN Connects but I cannot pass any traffic or access any web pages

Resolution: Make sure your have NAT rule that masqurades traffic from the IP pool out the WAN interface. My NAT rule looks like this…

Also make sure you are passing your IKEv2 vpn clients a valid DNS server. See IPSec | Mode Configs

Issue: VPN Connects but after a short time it disconnects.

Resolution: This is most likely an issue with rekeying. Apple iOS/OSX require a specific set on algorothms and does not support pfs (unless you use provisoning profiles). Go back over the Configure IKEv2 in RouterOS section above paying close attention to IPSec Peer Encryption and IPSec Proposals.


References


24 Replies to “How to configure a MikroTik IKEv2 VPN & connect iOS devices (iPhone/iPad)”

  1. Hello. Excelente Post.
    But dont work. I have a dude:
    1- What is IPSEC POLICY Definition ?

    I have this: /ip ipsec policy
    set 0 dst-address=0.0.0.0/0 group=Group_VPN proposal=IKev2-Proposal \
    src-address=0.0.0.0/0

    1. you don’t need one, it will be generated automatically, just keep the default template.
      make sure you have Generate Policy = port strict in your peer config

  2. trying to configure on a clean 6.42.1, does not want to connect the long connecting then disconnecting. At the same time, everyone connects

  3. trying to configure on a clean 6.42.1, does not want to connect the long connecting then disconnecting. At the same time, everyone connects via l2tp without a problem

  4. Configured my iPad according to the instructions, connects and disconnects immediately, in the mikrotik logs-RSASIG verification failed, what to do ? Help me please

  5. It acquires an IP from the pool, but how should I connect to the router from device? How to set the router’s IP for this subnet?

  6. Hello ! I have problem the configuration. The phone vpn profile connect to router, but about five second disconnect the vpn tunnel, the router log file say no error. Any idea?

    Regards
    Krisztian

  7. VPN Connects but after a short time it disconnects. Your suggested resolution above, to pay a close attention to IPSec Peer Encryption and IPSec Proposals didn’t worked. I checked again an again all settings, but could not solve that issue.

    log says:
    peer authorized
    12:52:54 acquired 192.168.89.2 adress for …., vpn.client
    12:52:54 releasing address 192.168.89.2
    12:52:54 killing ike2 SA
    12:52:54 KA tree dump (in-use = 1)
    12:52:54 LA removing this one

    for a short moment I can see the vpn-client on remote peers tab (IP->IP sec)
    IOS: 11.3 on IPhone6

    1. Hi I’m having the same problem. If I connect internally via WiFi, the VPN works and I see that authentication succeeded. However if I come externally I get what you see, same messages, but no client authentication success. I checked the firewall rules and they appear correct, I can see the incoming connections.

  8. Hi, thanks for your article – works like a charm! But, only one client can connect?! When a second client connects, the first client get kicked out. Is this right?

    Regards, Michael

  9. In my case vpn connects from iOS, i can access the router through the tunnel, but cannot access any website, like NAT isn’t working. I have the NAT rule.

  10. I can get the VPN to work on my LAN, but not from external IP’s. Do I need a firewall filter rule? I set my VPN LAN pool the same as my DHCP pool.

  11. Hi,

    Did all steps but after I want to connect it say disconnect in 2 seconds. I think I need to do something with FW. Can someone help me what should I write in FW rules that Mikrotik will accept IKEv2 connection?

  12. Hi,
    Can´t connect. I get an “EAP not configured” error in my log, followed by a “killing ike v2 …”. Any help would by appreciated

  13. Thanks for the guide. I’m able to connect fine from the mobile phone (iOS).
    The only issues I’m having are:
    – DNS server settings are not assigned to the client, as a result it cannot resolve hosts to IPs,so I cannot access web pages for example. I can ping both internal and internet ip addresses though,so it does not appear to be a NAT issue.

    – I can access internal network subnet and the internet, but not Mikrotik ip address itself. Does this need an explicit rule?

    Thanks,
    Yannis

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.