Modern operating systems support the IKEv2 standard. Internet Key Exchange (IKE or IKEv2) is the protocol used to set up a Security Association (SA) in the IPsec protocol suite. Compared to IKE version 1, IKEv2 contains improvements such as Standard Mobility support through MOBIKE, and improved reliability.
Libreswan can authenticate IKEv2 clients on the basis of X.509 Machine Certificates using RSA signatures. This method does not require an IPsec PSK, username or password. It can be used with Windows, macOS, iOS, Android, Chrome OS, Linux and RouterOS.
Once connected to the VPN, you will have access to all devices on the 26.0.0.0/8
address range.
Once connected to the VPN, you will have access to the entire remote network connected to the device.
!
Windows 8, 10 and 11 users can automatically import IKEv2 configuration:
IMPORT.bat
file to your computer by pressing IMPORT.bat
button.Alternatively, Windows 7, 8, 10 and 11 users can manually import IKEv2 configuration:
.p12
file to your computer by pressing "DOWNLOAD" button, then import it into the certificate store..p12
file, run the following from an elevated command prompt:# Import .p12 file (replace with your own value)
certutil -f -importpfx "\path\to\your\file.p12" NoExport
Note: If there is no password for client config files, press Enter to continue, or if manually importing the
.p12
file, leave the password field blank.
Alternatively, you can manually import the .p12 file. Make sure that the client cert is placed in "Personal -> Certificates", and the CA cert is placed in "Trusted Root Certification Authorities -> Certificates".
On the Windows computer, add a new IKEv2 VPN connection.
For Windows 8, 10 and 11, it is recommended to create the VPN connection using the following commands from a command prompt, for improved security and performance.
# Create VPN connection (replace server address with your own value)
powershell -command ^"Add-VpnConnection -ServerAddress 'Your VPN Server IP (or DNS name)' ^
-Name 'My IKEv2 VPN' -TunnelType IKEv2 -AuthenticationMethod MachineCertificate ^
-EncryptionLevel Required -PassThru^"
# Set IPsec configuration
powershell -command ^"Set-VpnConnectionIPsecConfiguration -ConnectionName 'My IKEv2 VPN' ^
-AuthenticationTransformConstants GCMAES128 -CipherTransformConstants GCMAES128 ^
-EncryptionMethod AES256 -IntegrityCheckMethod SHA256 -PfsGroup None ^
-DHGroup Group14 -PassThru -Force^"
Windows 7 does not support these commands, you can manually create the VPN connection.
Note: The server address you specify must exactly match the server address in the output of the IKEv2 helper script. For example, if you specified the server's DNS name during IKEv2 setup, you must enter the DNS name in the Internet address field.
This step is required if you manually created the VPN connection.
Enable stronger ciphers for IKEv2 with a one-time registry change. Download and import the .reg
file below, or run the following from an elevated command prompt. Read more here.
For Windows 7, 8, 10 and 11 (download .reg file)
REG ADD HKLM\SYSTEM\CurrentControlSet\Services\RasMan\Parameters /v NegotiateDH2048_AES256 /t REG_DWORD /d 0x1 /f
To connect to the VPN: Click on the wireless/network icon in your system tray, select the new VPN entry, and click Connect. Once connected, you can verify that your traffic is being routed properly by looking up your IP address on Google. It should say "Your public IP address is Your VPN Server IP
".
If you get an error when trying to connect, see Troubleshooting.
Using the following steps, you can remove the VPN connection and optionally restore the computer to the status before IKEv2 configuration import.
Remove the added VPN connection in Windows Settings - Network - VPN. Windows 7 users can remove the VPN connection in Network and Sharing Center - Change adapter settings.
(Optional) Remove IKEv2 certificates.
Press Win+R, or search for mmc
in the Start Menu. Open Microsoft Management Console.
Open File - Add/Remove Snap-In
. Select to add Certificates
and in the window that opens, select Computer account -> Local Computer
. Click on Finish -> OK
to save the settings.
Go to Certificates - Personal - Certificates
and delete the IKEv2 client certificate. The name of the certificate is the same as the IKEv2 client name you specified (default: vpnclient
). The certificate was issued by IKEv2 VPN CA
.
Go to Certificates - Trusted Root Certification Authorities - Certificates
and delete the IKEv2 VPN CA certificate. The certificate was issued to IKEv2 VPN CA
by IKEv2 VPN CA
. Before deleting, make sure that there are no other certificate(s) issued by IKEv2 VPN CA
in Certificates - Personal - Certificates
.
(Optional. For users who manually created the VPN connection) Restore registry settings. Note that you should backup the registry before editing.
Press Win+R, or search for regedit
in the Start Menu. Open Registry Editor.
Go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Rasman\Parameters
and delete the item with name NegotiateDH2048_AES256
, if it exists.
First, securely transfer the generated .mobileconfig
file to your Mac, then double-click and follow the prompts to import as a macOS profile. If your Mac runs macOS Big Sur or newer, open System Preferences and go to the Profiles section to finish importing. For macOS Ventura and newer, open System Settings and search for Profiles. When finished, check to make sure "IKEv2 VPN" is listed under System Preferences -> Profiles.
To connect to the VPN:
Your VPN Server IP
(or DNS name).(Optional feature) Enable VPN On Demand to automatically start a VPN connection when your Mac is on Wi-Fi. To enable, check the Connect on demand checkbox for the VPN connection, and click Apply. To find this setting on macOS Ventura and newer, click on the "i" icon on the right of the VPN connection.
You can customize VPN On Demand rules to exclude certain Wi-Fi network(s) such as your home network. See "Guide: Customize IKEv2 VPN On Demand rules for macOS and iOS" in Book: Set Up Your Own IPsec VPN, OpenVPN and WireGuard Server.
First, securely transfer the generated .p12
file to your Mac, then double-click to import into the login keychain in Keychain Access. Next, double-click on the imported IKEv2 VPN CA
certificate, expand Trust and select Always Trust from the IP Security (IPsec) drop-down menu. Close the dialog using the red "X" on the top-left corner. When prompted, use Touch ID or enter your password and click "Update Settings".
When finished, check to make sure both the new client certificate and IKEv2 VPN CA
are listed under the Certificates category of login keychain.
Your VPN Server IP
(or DNS name) for the Server Address.Your VPN Server IP
(or DNS name) for the Remote ID.Your VPN client name
in the Local ID field..p12
filename.Once connected, you can verify that your traffic is being routed properly by looking up your IP address on Google. It should say "Your public IP address is Your VPN Server IP
".
If you get an error when trying to connect, see Troubleshooting.
macOS 14 (Sonoma) has a minor issue that may cause IKEv2 VPN to disconnect and reconnect once every 24-48 minutes. Other macOS versions are not affected. For more details and a workaround, see [macOS Sonoma clients reconnect](#macos-sonoma-clients-reconnect
First, securely transfer the generated .mobileconfig
file to your iOS device, then import it as an iOS profile. To transfer the file, you may use:
Or you can download it directly from the cloud
When finished, check to make sure "IKEv2 VPN" is listed under Settings -> General -> VPN & Device Management or Profile(s).
To connect to the VPN:
Your VPN Server IP
(or DNS name).(Optional feature) Enable VPN On Demand to automatically start a VPN connection when your iOS device is on Wi-Fi. To enable, tap the "i" icon on the right of the VPN connection, and enable Connect On Demand.
You can customize VPN On Demand rules to exclude certain Wi-Fi network(s) such as your home network, or to start the VPN connection both on Wi-Fi and cellular. See "Guide: Customize IKEv2 VPN On Demand rules for macOS and iOS" in Book: Set Up Your Own IPsec VPN, OpenVPN and WireGuard Server.
First, securely transfer the generated ca.cer
and .p12
files to your iOS device, then import them one by one as iOS profiles. To transfer the files, you may use:
When finished, check to make sure both the new client certificate and IKEv2 VPN CA
are listed under Settings -> General -> VPN & Device Management or Profile(s).
Your VPN Server IP
(or DNS name).Your VPN Server IP
(or DNS name).Your VPN client name
in the Local ID field..p12
filename.To remove the IKEv2 VPN connection, open Settings -> General -> VPN & Device Management or Profile(s) and remove the IKEv2 VPN profile you added.
Android users can connect using strongSwan VPN client.
.sswan
file to your Android device..sswan
file you transferred from the VPN server..sswan
file, tap the three-line menu button, then browse to the location you saved the file.(Optional feature) You can choose to enable the "Always-on VPN" feature on Android. Launch the Settings app, go to Network & internet -> Advanced -> VPN, click the gear icon on the right of "strongSwan VPN Client", then enable the Always-on VPN and Block connections without VPN options.
.p12
file to your Android device..p12
file you transferred from the VPN server, and follow the prompts..p12
file, tap the three-line menu button, then browse to the location you saved the file.Your VPN Server IP
(or DNS name) in the Server field..p12
file to your Android device.Your VPN Server IP
(or DNS name) in the Server field..p12
file you transferred from the VPN server, and follow the prompts..p12
file, tap the three-line menu button, then browse to the location you saved the file.Android 11+ users can also connect using the native IKEv2 client.
.p12
file to your Android device..p12
file you transferred from the VPN server..p12
file, tap the three-line menu button, then browse to the location you saved the file.Your VPN Server IP
(or DNS name) in the Server address field.empty
) in the IPSec identifier field.First, on your VPN server, export the CA certificate as ca.cer
:
sudo certutil -L -d sql:/etc/ipsec.d -n "IKEv2 VPN CA" -a -o ca.cer
Securely transfer the generated .p12
and ca.cer
files to your Chrome OS device.
Install user and CA certificates:
.p12
file you transferred from the VPN server and select Open.ca.cer
file you transferred from the VPN server and select Open.Add a new VPN connection:
Your VPN Server IP
(or DNS name) for the Server hostname.(Optional feature) You can choose to enable the "Always-on VPN" feature on Chrome OS. To manage this setting, go to Settings -> Network, then click VPN.
Before configuring Linux VPN clients, you must make the following change on the VPN server: Edit /etc/ipsec.d/ikev2.conf
on the server. Append authby=rsa-sha1
to the end of the conn ikev2-cp
section, indented by two spaces. Save the file and run service ipsec restart
.
To configure your Linux computer to connect to IKEv2 as a VPN client, first install the strongSwan plugin for NetworkManager:
# Ubuntu and Debian
sudo apt-get update
sudo apt-get install network-manager-strongswan
# Arch Linux
sudo pacman -Syu # upgrade all packages
sudo pacman -S networkmanager-strongswan
# Fedora
sudo yum install NetworkManager-strongswan-gnome
# CentOS
sudo yum install epel-release
sudo yum --enablerepo=epel install NetworkManager-strongswan-gnome
Next, securely transfer the generated .p12
file from the VPN server to your Linux computer. After that, extract the CA certificate, client certificate and private key. Replace vpnclient.p12
in the example below with the name of your .p12
file.
# Example: Extract CA certificate, client certificate and private key.
# You may delete the .p12 file when finished.
# Note: You may need to enter the import password, which can be found
# in the output of the IKEv2 helper script. If the output does not
# contain an import password, press Enter to continue.
# Note: If using OpenSSL 3.x (run "openssl version" to check),
# append "-legacy" to the 3 commands below.
openssl pkcs12 -in vpnclient.p12 -cacerts -nokeys -out ca.cer
openssl pkcs12 -in vpnclient.p12 -clcerts -nokeys -out client.cer
openssl pkcs12 -in vpnclient.p12 -nocerts -nodes -out client.key
rm vpnclient.p12
# (Important) Protect certificate and private key files
# Note: This step is optional, but strongly recommended.
sudo chown root:root ca.cer client.cer client.key
sudo chmod 600 ca.cer client.cer client.key
You can then set up and enable the VPN connection:
Your VPN Server IP
(or DNS name) for the Address.ca.cer
file for the Certificate.client.cer
file for the Certificate (file).client.key
file for the Private key.aes128gcm16
in the ESP field.Alternatively, you may connect using the command line. See #1399 and #1007 for example steps. If you encounter error Could not find source connection
, edit /etc/netplan/01-netcfg.yaml
and replace renderer: networkd
with renderer: NetworkManager
, then run sudo netplan apply
. To connect to the VPN, run sudo nmcli c up VPN
. To disconnect: sudo nmcli c down VPN
.
Once connected, you can verify that your traffic is being routed properly by looking up your IP address on Google. It should say "Your public IP address is Your VPN Server IP
".
If you get an error when trying to connect, see Troubleshooting.
Note: These steps were contributed by @Unix-User. It is recommended to run terminal commands via an SSH connection, e.g. via Putty.
Securely transfer the generated .p12
file to your computer.
In WinBox, go to System > certificates > import. Import the .p12
certificate file twice (yes, import the same file two times!). Verify in your certificates panel. You will see 2 files, the one that is marked KT is the key.
Or you can use terminal instead (empty passphrase):
[admin@MikroTik] > /certificate/import file-name=mikrotik.p12
passphrase:
certificates-imported: 2
private-keys-imported: 0
files-imported: 1
decryption-failures: 0
keys-with-no-certificate: 0
[admin@MikroTik] > /certificate/import file-name=mikrotik.p12
passphrase:
certificates-imported: 0
private-keys-imported: 1
files-imported: 1
decryption-failures: 0
keys-with-no-certificate: 0
Run these commands in terminal. Replace the following with your own values.
YOUR_VPN_SERVER_IP_OR_DNS_NAME
is your VPN server IP or DNS name.
IMPORTED_CERTIFICATE
is the name of the certificate from step 2 above, e.g. vpnclient.p12_0
(the one flagged with KT - Priv. Key Trusted - if not flagged as KT, import certificate again).
THESE_ADDRESSES_GO_THROUGH_VPN
are the local network addresses that you want to browse through the VPN.
Assuming that your local network behind RouterOS is 192.168.0.0/24
, you can use 192.168.0.0/24
for the entire network, or use 192.168.0.10
for just one device, and so on.
/ip firewall address-list add address=THESE_ADDRESSES_GO_THROUGH_VPN list=local
/ip ipsec mode-config add name=ike2-rw responder=no src-address-list=local
/ip ipsec policy group add name=ike2-rw
/ip ipsec profile add name=ike2-rw
/ip ipsec peer add address=YOUR_VPN_SERVER_IP_OR_DNS_NAME exchange-mode=ike2 \
name=ike2-rw-client profile=ike2-rw
/ip ipsec proposal add name=ike2-rw pfs-group=none
/ip ipsec identity add auth-method=digital-signature certificate=IMPORTED_CERTIFICATE \
generate-policy=port-strict mode-config=ike2-rw \
peer=ike2-rw-client policy-template-group=ike2-rw
/ip ipsec policy add group=ike2-rw proposal=ike2-rw template=yes
For more information, see #1112.
tested on
mar/02/2022 12:52:57 by RouterOS 6.48
RouterBOARD 941-2nD