1
0
mirror of synced 2024-11-22 21:16:02 +03:00
setup-ipsec-vpn/docs/ikev2-howto.md

249 lines
9.5 KiB
Markdown
Raw Normal View History

2016-10-12 23:02:15 +03:00
# How-To: IKEv2 VPN for Windows 7 and newer
2016-08-28 08:41:46 +03:00
*Read this in other languages: [English](ikev2-howto.md), [简体中文](ikev2-howto-zh.md).*
2016-09-10 00:45:39 +03:00
---
2016-10-12 23:02:15 +03:00
**IMPORTANT:** This guide is for **Advanced Users** ONLY. Other users please use <a href="clients.md" target="_blank">IPsec/L2TP</a> or <a href="clients-xauth.md" target="_blank">IPsec/XAuth</a>.
2016-08-28 08:41:46 +03:00
2016-09-10 00:45:39 +03:00
---
2016-10-12 23:02:15 +03:00
Windows 7 and newer releases support the IKEv2 standard through Microsoft's Agile VPN functionality. 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 has <a href="https://en.wikipedia.org/wiki/Internet_Key_Exchange#Improvements_with_IKEv2" target="_blank">multiple improvements</a> such as Standard Mobility support through MOBIKE, and improved reliability.
2016-08-28 08:41:46 +03:00
2016-10-12 23:02:15 +03:00
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 7, 8.x and 10
- Windows Phone 8.1 and above
- strongSwan Android VPN client
2017-01-18 09:54:53 +03:00
- <a href="https://github.com/gaomd/docker-ikev2-vpn-server" target="_blank">iOS (iPhone/iPad) and OS X (macOS)</a> <-- See link
2016-10-12 23:02:15 +03:00
2016-11-10 22:04:47 +03:00
The following example shows how to configure IKEv2 with Libreswan. Commands below must be run as `root`.
2016-08-28 08:41:46 +03:00
2016-11-10 22:04:47 +03:00
Before continuing, make sure you have successfully <a href="https://github.com/hwdsl2/setup-ipsec-vpn" target="_blank">set up your VPN server</a>.
2016-09-10 00:45:39 +03:00
2016-08-28 08:41:46 +03:00
1. Find the public and private IP of your server, and make sure they are not empty. It is OK if they are the same.
```bash
2016-11-10 22:04:47 +03:00
$ PUBLIC_IP=$(wget -t 3 -T 15 -qO- http://ipv4.icanhazip.com)
2016-08-28 08:41:46 +03:00
$ PRIVATE_IP=$(ip -4 route get 1 | awk '{print $NF;exit}')
$ echo "$PUBLIC_IP"
2017-01-19 01:10:34 +03:00
(Check the displayed public IP)
2016-08-28 08:41:46 +03:00
$ echo "$PRIVATE_IP"
2017-01-19 01:10:34 +03:00
(Check the displayed private IP)
2016-08-28 08:41:46 +03:00
```
1. Add a new IKEv2 connection to `/etc/ipsec.conf`:
```bash
$ cat >> /etc/ipsec.conf <<EOF
conn ikev2-cp
left=$PRIVATE_IP
leftcert=$PUBLIC_IP
leftid=@$PUBLIC_IP
leftsendcert=always
leftsubnet=0.0.0.0/0
leftrsasigkey=%cert
right=%any
rightaddresspool=192.168.43.10-192.168.43.250
rightca=%same
rightrsasigkey=%cert
modecfgdns1=8.8.8.8
modecfgdns2=8.8.4.4
narrowing=yes
dpddelay=30
dpdtimeout=120
dpdaction=clear
auto=add
ikev2=insist
rekey=no
fragmentation=yes
ike=3des-sha1,aes-sha1,aes256-sha2_256;modp1024,aes256-sha2_256;modp2048
phase2alg=3des-sha1,aes-sha1,aes256-sha2_256
2016-08-28 08:41:46 +03:00
EOF
```
2017-01-17 02:27:08 +03:00
We need to add one more line to that file, based on your Libreswan version. Please run command:
```bash
$ if /usr/local/sbin/ipsec --version | grep -qs -F "3.19"; then
echo " encapsulation=yes" >> /etc/ipsec.conf
else
echo " forceencaps=yes" >> /etc/ipsec.conf
fi
```
2016-09-28 22:50:49 +03:00
1. Generate Certificate Authority (CA) and VPN server certificates:
Note: Specify the certificate validity period (in months) using "-v". e.g. "-v 36".
2016-08-28 08:41:46 +03:00
```bash
2016-09-28 22:50:49 +03:00
$ certutil -S -x -n "Example CA" -s "O=Example,CN=Example CA" -k rsa -g 4096 -v 36 -d sql:/etc/ipsec.d -t "CT,," -2
2016-08-28 08:41:46 +03:00
A random seed must be generated that will be used in the
creation of your key. One of the easiest ways to create a
random seed is to use the timing of keystrokes on a keyboard.
To begin, type keys on the keyboard until this progress meter
is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD!
Continue typing until the progress meter is full:
|************************************************************|
Finished. Press enter to continue:
Generating key. This may take a few moments...
Is this a CA certificate [y/N]?
y
Enter the path length constraint, enter to skip [<0 for unlimited path]: >
Is this a critical extension [y/N]?
N
2016-09-28 22:50:49 +03:00
$ certutil -S -c "Example CA" -n "$PUBLIC_IP" -s "O=Example,CN=$PUBLIC_IP" -k rsa -g 4096 -v 36 -d sql:/etc/ipsec.d -t ",," -1 -6 -8 "$PUBLIC_IP"
2016-08-28 08:41:46 +03:00
A random seed must be generated that will be used in the
creation of your key. One of the easiest ways to create a
random seed is to use the timing of keystrokes on a keyboard.
To begin, type keys on the keyboard until this progress meter
is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD!
Continue typing until the progress meter is full:
|************************************************************|
Finished. Press enter to continue:
Generating key. This may take a few moments...
0 - Digital Signature
1 - Non-repudiation
2 - Key encipherment
3 - Data encipherment
4 - Key agreement
5 - Cert signing key
6 - CRL signing key
Other to finish
> 0
0 - Digital Signature
1 - Non-repudiation
2 - Key encipherment
3 - Data encipherment
4 - Key agreement
5 - Cert signing key
6 - CRL signing key
Other to finish
> 2
0 - Digital Signature
1 - Non-repudiation
2 - Key encipherment
3 - Data encipherment
4 - Key agreement
5 - Cert signing key
6 - CRL signing key
Other to finish
> 8
Is this a critical extension [y/N]?
N
0 - Server Auth
1 - Client Auth
2 - Code Signing
3 - Email Protection
4 - Timestamp
5 - OCSP Responder
6 - Step-up
7 - Microsoft Trust List Signing
Other to finish
> 0
0 - Server Auth
1 - Client Auth
2 - Code Signing
3 - Email Protection
4 - Timestamp
5 - OCSP Responder
6 - Step-up
7 - Microsoft Trust List Signing
Other to finish
> 8
Is this a critical extension [y/N]?
N
```
2016-09-30 19:53:33 +03:00
1. Generate client certificate(s), and export the `.p12` file that contains the client certificate, private key, and CA certificate:
2016-08-28 08:41:46 +03:00
```bash
2016-09-28 22:50:49 +03:00
$ certutil -S -c "Example CA" -n "vpnclient" -s "O=Example,CN=vpnclient" -k rsa -g 4096 -v 36 -d sql:/etc/ipsec.d -t ",," -1 -6 -8 "vpnclient"
2016-08-28 08:41:46 +03:00
-- repeat same extensions as above --
2016-09-28 22:50:49 +03:00
$ pk12util -o vpnclient.p12 -n "vpnclient" -d sql:/etc/ipsec.d
2016-08-28 08:41:46 +03:00
Enter password for PKCS12 file:
Re-enter password:
pk12util: PKCS12 EXPORT SUCCESSFUL
```
2016-09-28 22:50:49 +03:00
Repeat this step for additional VPN clients, but replace every `vpnclient` with `vpnclient2`, etc.
2016-08-28 08:41:46 +03:00
1. The database should now contain:
```bash
$ certutil -L -d sql:/etc/ipsec.d
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
Example CA CTu,u,u
($PUBLIC_IP) u,u,u
2016-09-28 22:50:49 +03:00
vpnclient u,u,u
2016-08-28 08:41:46 +03:00
```
Note: To delete a certificate, use `certutil -D -d sql:/etc/ipsec.d -n "Certificate Nickname"`.
1. Restart IPsec service:
```bash
$ service ipsec restart
```
2016-10-12 23:02:15 +03:00
1. The `vpnclient.p12` file should then be securely transferred to the VPN client device. Next steps:
2016-08-28 08:41:46 +03:00
2016-10-12 23:02:15 +03:00
#### Windows 7, 8.x and 10
2016-08-28 08:41:46 +03:00
2016-10-12 23:02:15 +03:00
Import the `.p12` file to the Computer certificate store. The CA cert once imported must be placed into the "Certificates" sub-folder under "Trusted Root Certification Authorities".
2016-09-30 19:53:33 +03:00
2016-10-12 23:02:15 +03:00
Detailed instructions:
https://wiki.strongswan.org/projects/strongswan/wiki/Win7Certs
2016-09-28 22:50:49 +03:00
2016-10-12 23:02:15 +03:00
On the Windows computer, add a new IKEv2 VPN connection
2016-08-28 08:41:46 +03:00
https://wiki.strongswan.org/projects/strongswan/wiki/Win7Config
2016-10-12 23:02:15 +03:00
Start the new IKEv2 VPN connection, and enjoy your own VPN!
2016-08-28 08:41:46 +03:00
https://wiki.strongswan.org/projects/strongswan/wiki/Win7Connect
2017-01-19 01:10:34 +03:00
(Optional) You may enable stronger ciphers by adding <a href="https://wiki.strongswan.org/projects/strongswan/wiki/Windows7#AES-256-CBC-and-MODP2048" target="_blank">this registry key</a> and reboot.
2017-01-18 09:54:53 +03:00
2016-10-12 23:02:15 +03:00
#### Windows Phone 8.1 and above
First import the `.p12` file, then follow <a href="https://technet.microsoft.com/en-us/windows/dn673608.aspx" target="_blank">these instructions</a> to configure a certificate-based IKEv2 VPN.
#### Android 4.x and newer
Please refer to: https://wiki.strongswan.org/projects/strongswan/wiki/AndroidVpnClient
2016-08-28 08:41:46 +03:00
Once successfully connected, you can verify that your traffic is being routed properly by <a href="https://encrypted.google.com/search?q=my+ip" target="_blank">looking up your IP address on Google</a>. It should say "Your public IP address is `Your VPN Server IP`".
## Known Issues
2017-01-19 01:10:34 +03:00
The built-in VPN client in Windows 7 and newer does not support IKEv2 fragmentation. On some networks, this can cause the connection to fail, or you may be unable to open any website after connecting. If this happens, first try <a href="clients.md#troubleshooting" target="_blank">this workaround</a>. If it doesn't work, please connect using <a href="clients.md" target="_blank">IPsec/L2TP</a> or <a href="clients-xauth.md" target="_blank">IPsec/XAuth</a> mode instead.
2016-08-28 08:41:46 +03:00
2016-09-10 00:45:39 +03:00
## References
2016-08-28 08:41:46 +03:00
* https://libreswan.org/wiki/VPN_server_for_remote_clients_using_IKEv2
* https://libreswan.org/wiki/HOWTO:_Using_NSS_with_libreswan
* https://libreswan.org/man/ipsec.conf.5.html
* https://wiki.strongswan.org/projects/strongswan/wiki/Windows7