Difference between revisions of "Manual:IP/IPsec"

From MikroTik Wiki
Jump to: navigation, search
(IOS Client Notes)
m (Hardware acceleration)
 
(135 intermediate revisions by 4 users not shown)
Line 5: Line 5:
 
<b>Sub-menu:</b> <code>/ip ipsec</code><br />
 
<b>Sub-menu:</b> <code>/ip ipsec</code><br />
 
<b>Package required:</b> <code>security</code><br />
 
<b>Package required:</b> <code>security</code><br />
<b>Standards:</b> <code>RFC 4301</code><br />
 
 
</p>
 
</p>
  
Line 12: Line 11:
  
  
IpSec protocol suite can be divided in following groups:
+
IPsec protocol suite can be divided in following groups:
 +
* <b>Internet Key Exchange (IKE)</b> protocols. Dynamically generates and distributes cryptographic keys for AH and ESP.
 
* <b>Authentication Header (AH)</b> RFC 4302
 
* <b>Authentication Header (AH)</b> RFC 4302
 
* <b>Encapsulating Security Payload (ESP)</b> RFC 4303
 
* <b>Encapsulating Security Payload (ESP)</b> RFC 4303
* <b>Internet Key Exchange (IKE)</b> protocols. Dynamically generates and distributes cryptographic keys for AH and ESP.
 
  
==Authentication Header (AH)==
+
==Internet Key Exchange Protocol (IKE)==
  
AH is a protocol that provides authentication of either all or part of the contents of a datagram through the addition of a header that is calculated based on the values in the datagram. What parts of the datagram are used for the calculation, and the placement of the header, depends whether tunnel or transport mode is used.
+
The Internet Key Exchange (IKE) is a protocol that provides authenticated keying material for Internet Security Association and Key Management Protocol (ISAKMP) framework. There are other key exchange schemes that work with ISAKMP, but IKE is the most widely used one. Together they provide means for authentication of hosts and automatic management of security associations (SA).
  
 +
Most of the time IKE daemon is doing nothing. There are two possible situations when it is activated:
  
The presence of the AH header allows to verify the integrity of the message, but doesn't encrypt it. Thus, AH provides authentication but not privacy. Another protocol (ESP) is considered superior, it provides data privacy and also its own authentication method.
+
There is some traffic caught by a policy rule which needs to become encrypted or authenticated, but the policy doesn't have any SAs. The policy notifies IKE daemon about that, and IKE daemon initiates connection to remote host.
 +
IKE daemon responds to remote connection.
 +
In both cases, peers establish connection and execute 2 phases:
  
 +
*'''Phase 1''' - The peers agree upon algorithms they will use in the following IKE messages and authenticate. The keying material used to derive keys for all SAs and to protect following ISAKMP exchanges between hosts is generated also. This phase should match following settings:
 +
**authentication method
 +
** DH group
 +
** encryption algorithm
 +
** exchange mode
 +
** hash alorithm
 +
** NAT-T
 +
** DPD and lifetime (optional)
  
RouterOS supports the following authentication algorithms for AH:
+
*'''Phase 2''' - The peers establish one or more SAs that will be used by IPsec to encrypt data. All SAs established by IKE daemon will have lifetime values (either limiting time, after which SA will become invalid, or amount of data that can be encrypted by this SA, or both). This phase should match following settings:
<ul>
+
** Ipsec protocol
  <li> SHA2 (256, 512)
+
** mode (tunnel or transport)
  <li> SHA1
+
** authentication method
  <li> MD5
+
** PFS (DH) group
</ul>
+
** lifetime
  
 +
{{Note | There are two lifetime values - soft and hard. When SA reaches it's soft lifetime treshold, the IKE daemon receives a notice and starts another phase 2 exchange to replace this SA with fresh one. If SA reaches hard lifetime, it is discarded. }}
  
===Transport mode===
+
{{Warning | Phase 1 is not re-keyed if DPD is disabled when lifetime expires, only phase 2 is re-keyed. To force phase 1 re-key, enable DPD.}}
  
In transport mode AH header is inserted after IP header. IP data and header is used to calculate authentication value. IP fields that might change during transit, like TTL and hop count, are set to zero values before authentication.
+
{{Warning | PSK authentication was known to be vulnerable against Offline attacks in "aggressive" mode, however recent discoveries indicate that offline attack is possible also in case of "main" and "ike2" exchange modes. General recommendation is to avoid using PSK authentication method.}}
  
 +
IKE can optionally provide a Perfect Forward Secrecy (PFS), which is a property of key exchanges, that, in turn, means for IKE that compromising the long term phase 1 key will not allow to easily gain access to all IPsec data that is protected by SAs established through this phase 1. It means an additional keying material is generated for each phase 2.
  
===Tunnel mode===
+
Generation of keying material is computationally very expensive. Exempli gratia, the use of modp8192 group can take several seconds even on very fast computer. It usually takes place once per phase 1 exchange, which happens only once between any host pair and then is kept for long time. PFS adds this expensive operation also to each phase 2 exchange.
  
In tunnel mode original IP packet is encapsulated within a new IP packet. All of the original IP packet is authenticated.
+
===Diffie-Hellman Groups===
  
==Encapsulating Security Payload==
+
Diffie-Hellman (DH) key exchange protocol allows two parties without any initial shared secret to create one securely. The following Modular Exponential (MODP) and Elliptic Curve (EC2N) Diffie-Hellman (also known as "Oakley") Groups are supported:
  
Encapsulating Security Payload (ESP) uses shared key encryption to provide data privacy. ESP also supports its own authentication scheme like that used in AH.
+
<table border="1">
 +
<tr><th>Diffie-Hellman Group</th><th>Name</th><th>Reference</th></tr>
 +
<tr><td>Group 1</td><td>768 bit MODP group</td><td>RFC 2409</td></tr>
 +
<tr><td>Group 2</td><td>1024 bits MODP group</td><td>RFC 2409</td></tr>
 +
<tr><td>Group 3</td><td>EC2N group on GP(2^155)</td><td>RFC 2409</td></tr>
 +
<tr><td>Group 4</td><td>EC2N group on GP(2^185)</td><td>RFC 2409</td></tr>
 +
<tr><td>Group 5</td><td>1536 bits MODP group</td><td>RFC 3526</td></tr>
 +
<tr><td>Group 14</td><td>2048 bits MODP group</td><td>RFC 3526</td></tr>
 +
<tr><td>Group 15</td><td>3072 bits MODP group</td><td>RFC 3526</td></tr>
 +
<tr><td>Group 16</td><td>4096 bits MODP group</td><td>RFC 3526</td></tr>
 +
<tr><td>Group 17</td><td>6144 bits MODP group</td><td>RFC 3526</td></tr>
 +
<tr><td>Group 18</td><td>8192 bits MODP group</td><td>RFC 3526</td></tr>
 +
<tr><td>Group 19</td><td>256 bits random ECP group</td><td>RFC 5903</td></tr>
 +
<tr><td>Group 20</td><td>384 bits random ECP group</td><td>RFC 5903</td></tr>
 +
<tr><td>Group 21</td><td>521 bits random ECP group</td><td>RFC 5903</td></tr>
 +
</table>
 +
 
 +
More on standards can be found [https://www.iana.org/assignments/ipsec-registry/ipsec-registry.xhtml here].
  
ESP packages its fields in a very different way than AH. Instead of having just a header, it divides its fields into three components:
+
===IKE Traffic===
<ul >
 
  <li><b>ESP Header</b> - Comes before the encrypted data and its placement depends on whether ESP is used in transport mode or tunnel mode.
 
  <li><b>ESP Trailer</b> - This section is placed after the encrypted data. It contains padding that is used to align the encrypted data.
 
  <li><b>ESP Authentication Data</b> - This field contains an Integrity Check Value (ICV), computed in a manner similar to how the AH protocol works, for when ESP's optional authentication feature is used.
 
</ul>
 
  
===Transport mode===
+
To avoid problems with IKE packets hit some SPD rule and require to encrypt it with not yet established SA (that this packet perhaps is trying to establish), locally originated packets with UDP source port 500 are not processed with SPD. The same way packets with UDP destination port 500 that are to be delivered locally are not processed in incoming policy check.
  
In transport mode ESP header is inserted after original IP header. ESP trailer and authentication value is added to the end of the packet. In this mode only IP payload is encrypted and authenticated, IP header is not secured.
 
  
[[File:ESP-transport wiki.png]]
+
=== Setup Procedure ===
  
===Tunnel mode===
+
To get IPsec to work with automatic keying using IKE-ISAKMP you will have to configure policy, peer and proposal (optional) entries.
  
In tunnel mode original IP packet is encapsulated within a new IP packet thus securing IP payload and IP header.  
+
{{Warning | Ipsec is very sensitive to time changes. If both ends of the IpSec tunnel are not synchronizing time equally(for example, different NTP servers not updating time with the same timestamp), tunnels will break and will have to be established again.}}
  
[[File:ESP-tunnel wiki.png]]
 
  
===Encryption algorithms===
+
=== EAP Authentication methods ===
  
RouterOS ESP supports various encryption and authentication algorithms.
+
<table border="1">
 
+
<tr>
Authentication:
+
   <th>Outer Auth</th>
<ul class="bullets">
+
   <th>Inner Auth</th>
  <li><b>MD5</b>
+
</tr>
   <li><b>SHA1</b>
+
<tr>
   <li><b>SHA2 (256-bit, 512-bit)</b>
+
   <td>EAP-GTC</td>
</ul>
+
   <td></td>
 
 
Encryption:
 
<ul class="bullets">
 
   <li><b>AES</b> - 128-bit, 192-bit and 256-bit key AES-CBC, AES-CTR and AES-GCM algorithms;
 
  <li><b>Blowfish</b> - added since v4.5
 
   <li><b>Twofish</b> - added since v4.5
 
  <li><b>Camellia</b> -  128-bit, 192-bit and 256-bit key Camellia encryption algorithm added since v4.5
 
  <li><b>DES</b> - 56-bit DES-CBC encryption algorithm;
 
  <li><b>3DES</b> - 168-bit DES encryption algorithm;
 
</ul>
 
 
 
===Hardware encryption===
 
 
 
Hardware acceleration allows to do faster encryption process by using built-in encryption engine inside CPU.
 
<table class="styled_table">
 
<tr>
 
<th rowspan=2 style="border-right: 2px solid white;">RouterBoard</th>
 
<th colspan=4 style="border-right: 2px solid white;">AES-CBC</th>
 
<th colspan=4 style="border-right: 2px solid white;">AES-CTR</th>
 
<th colspan=4>AES-GCM</th>
 
 
</tr>
 
</tr>
 +
<tr><td>EAP-MD5</td><td></td></tr>
 +
<tr><td>EAP-MSCHAPv2</td><td></td></tr>
 
<tr>
 
<tr>
<th>MD5</th>
+
  <td>EAP-PEAPv0</td>
<th>SHA1</th>
+
  <td>
<th>SHA256</th>
+
EAP-MSCHAPv2<br \>
<th style="border-right: 2px solid white;">SHA512</th>
+
EAP-GPSK<br \>
<th>MD5</th>
+
EAP-GTC<br \>
<th>SHA1</th>
+
EAP-MD5<br \>
<th>SHA256</th>
+
EAP-TLS<br \>
<th style="border-right: 2px solid white;">SHA512</th>
+
  </td>
<th>MD5</th>
 
<th>SHA1</th>
 
<th>SHA256</th>
 
<th>SHA512</th>
 
 
</tr>
 
</tr>
<tr><td>[https://mikrotik.com/product/RB750Gr3 hEX (RB750Gr3)]</td><td>yes</td><td>yes</td><td>yes</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td></tr>
+
<tr><td>EAP-SIM</td><td></td></tr>
<tr><td>[https://mikrotik.com/product/RB850Gx2 RB850Gx2] *</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td></tr>
+
<tr><td>EAP-TLS</td><td></td></tr>
<tr><td>[https://mikrotik.com/product/RB1100AHx2 RB1100AHx2]</td><td>yes</td><td>yes</td><td>yes</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td></tr>
+
<tr>
<tr><td>[https://mikrotik.com/product/rb1100ahx4 RB1100AHx4]</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td></tr>
+
  <td>EAP-TTLS</td>
<tr><td>[https://mikrotik.com/product/RB1200 RB1200] **</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td></tr>
+
  <td>
<tr><td>CCR series</td><td>yes</td><td>yes</td><td>yes</td><td>no</td><td>yes</td><td>yes</td><td>yes</td><td>no</td><td>no</td><td>no</td><td>no</td><td>no</td></tr>
+
PAP <br \>
<tr><td>x86 (AES-NI) **</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td></tr>
+
CHAP <br \>
</table>
+
MS-CHAP <br \>
 
+
MS-CHAPv2 <br \>
<nowiki>*</nowiki> only manufactured since 2016, serial numbers that begin with number 5 and 7
+
EAP-MSCHAPv2<br \>
 
+
EAP-GTC<br \>
<nowiki>**</nowiki> AES-CBC and AES-CTR only encryption is accelerated, hashing done in software
+
EAP-MD5<br \>
 
+
EAP-TLS<br \>
IPsec throughput results of various encryption and hash algorithm combinations are published on [https://mikrotik.com/product/ MikroTik products page]. When testing throughput, please follow the guidelines available in the  [[Manual:Tools/Traffic_Generator#IpSec_tunnel_performance_test|Traffic Generator manual page]]
+
  </td>
 
+
</tr>
==Internet Key Exchange Protocol==
+
</table>
 
+
 
The Internet Key Exchange (IKE) is a protocol that provides authenticated keying material for Internet Security Association and Key Management Protocol (ISAKMP) framework. There are other key exchange schemes that work with ISAKMP, but IKE is the most widely used one. Together they provide means for authentication of hosts and automatic management of security associations (SA).
+
<b>EAP-TLS</b> on Windows is called "Smart Card or other certificate".
  
Most of the time IKE daemon is doing nothing. There are two possible situations when it is activated:
+
==Authentication Header (AH)==
  
There is some traffic caught by a policy rule which needs to become encrypted or authenticated, but the policy doesn't have any SAs. The policy notifies IKE daemon about that, and IKE daemon initiates connection to remote host.
+
AH is a protocol that provides authentication of either all or part of the contents of a datagram through the addition of a header that is calculated based on the values in the datagram. What parts of the datagram are used for the calculation, and the placement of the header, depends whether tunnel or transport mode is used.
IKE daemon responds to remote connection.
 
In both cases, peers establish connection and execute 2 phases:
 
  
*'''Phase 1''' - The peers agree upon algorithms they will use in the following IKE messages and authenticate. The keying material used to derive keys for all SAs and to protect following ISAKMP exchanges between hosts is generated also. This phase should match following settings:
 
**authentication method
 
** DH group
 
** encryption algorithm
 
** exchange mode
 
** hash alorithm
 
** NAT-T
 
** DPD and lifetime (optional)
 
  
*'''Phase 2''' - The peers establish one or more SAs that will be used by IPsec to encrypt data. All SAs established by IKE daemon will have lifetime values (either limiting time, after which SA will become invalid, or amount of data that can be encrypted by this SA, or both). This phase should match following settings:
+
The presence of the AH header allows to verify the integrity of the message, but doesn't encrypt it. Thus, AH provides authentication but not privacy. Another protocol (ESP) is considered superior, it provides data privacy and also its own authentication method.
** Ipsec protocol
+
 
** mode (tunnel or transport)
+
 
** authentication method
+
RouterOS supports the following authentication algorithms for AH:
** PFS (DH) group
+
<ul>
** lifetime
+
  <li> SHA2 (256, 512)
 +
  <li> SHA1
 +
  <li> MD5
 +
</ul>
 +
 
  
{{Note | There are two lifetime values - soft and hard. When SA reaches it's soft lifetime treshold, the IKE daemon receives a notice and starts another phase 2 exchange to replace this SA with fresh one. If SA reaches hard lifetime, it is discarded. }}
+
===Transport mode===
  
{{Warning | Phase 1 is not re-keyed if DPD is disabled when lifetime expires, only phase 2 is re-keyed. To force phase 1 re-key, enable DPD.}}
+
In transport mode AH header is inserted after IP header. IP data and header is used to calculate authentication value. IP fields that might change during transit, like TTL and hop count, are set to zero values before authentication.
  
IKE can optionally provide a Perfect Forward Secrecy (PFS), which is a property of key exchanges, that, in turn, means for IKE that compromising the long term phase 1 key will not allow to easily gain access to all IPsec data that is protected by SAs established through this phase 1. It means an additional keying material is generated for each phase 2.
 
  
Generation of keying material is computationally very expensive. Exempli gratia, the use of modp8192 group can take several seconds even on very fast computer. It usually takes place once per phase 1 exchange, which happens only once between any host pair and then is kept for long time. PFS adds this expensive operation also to each phase 2 exchange.
+
===Tunnel mode===
  
===Diffie-Hellman Groups===
+
In tunnel mode original IP packet is encapsulated within a new IP packet. All of the original IP packet is authenticated.
  
Diffie-Hellman (DH) key exchange protocol allows two parties without any initial shared secret to create one securely. The following Modular Exponential (MODP) and Elliptic Curve (EC2N) Diffie-Hellman (also known as "Oakley") Groups are supported:
+
==Encapsulating Security Payload (ESP)==
  
<table border="1">
+
Encapsulating Security Payload (ESP) uses shared key encryption to provide data privacy. ESP also supports its own authentication scheme like that used in AH.
<tr><th>Diffie-Hellman Group</th><th>Name</th><th>Reference</th></tr>
 
<tr><td>Group 1</td><td>768 bit MODP group</td><td>RFC 2409</td></tr>
 
<tr><td>Group 2</td><td>1024 bits MODP group</td><td>RFC 2409</td></tr>
 
<tr><td>Group 3</td><td>EC2N group on GP(2^155)</td><td>RFC 2409</td></tr>
 
<tr><td>Group 4</td><td>EC2N group on GP(2^185)</td><td>RFC 2409</td></tr>
 
<tr><td>Group 5</td><td>1536 bits MODP group</td><td>RFC 3526</td></tr>
 
<tr><td>Group 14</td><td>2048 bits MODP group</td><td>RFC 3526</td></tr>
 
<tr><td>Group 15</td><td>3072 bits MODP group</td><td>RFC 3526</td></tr>
 
<tr><td>Group 16</td><td>4096 bits MODP group</td><td>RFC 3526</td></tr>
 
<tr><td>Group 17</td><td>6144 bits MODP group</td><td>RFC 3526</td></tr>
 
</table>
 
  
More on standards can be found [https://www.iana.org/assignments/ipsec-registry/ipsec-registry.xhtml here].
+
ESP packages its fields in a very different way than AH. Instead of having just a header, it divides its fields into three components:
 +
<ul >
 +
  <li><b>ESP Header</b> - Comes before the encrypted data and its placement depends on whether ESP is used in transport mode or tunnel mode.
 +
  <li><b>ESP Trailer</b> - This section is placed after the encrypted data. It contains padding that is used to align the encrypted data.
 +
  <li><b>ESP Authentication Data</b> - This field contains an Integrity Check Value (ICV), computed in a manner similar to how the AH protocol works, for when ESP's optional authentication feature is used.
 +
</ul>
  
===IKE Traffic===
+
===Transport mode===
  
To avoid problems with IKE packets hit some SPD rule and require to encrypt it with not yet established SA (that this packet perhaps is trying to establish), locally originated packets with UDP source port 500 are not processed with SPD. The same way packets with UDP destination port 500 that are to be delivered locally are not processed in incoming policy check.
+
In transport mode ESP header is inserted after original IP header. ESP trailer and authentication value is added to the end of the packet. In this mode only IP payload is encrypted and authenticated, IP header is not secured.
  
 +
[[File:ESP-transport wiki.png]]
  
=== Setup Procedure ===
+
===Tunnel mode===
  
To get IPsec to work with automatic keying using IKE-ISAKMP you will have to configure policy, peer and proposal (optional) entries.
+
In tunnel mode original IP packet is encapsulated within a new IP packet thus securing IP payload and IP header.  
  
{{Warning | Ipsec is very sensitive to time changes. If both ends of the IpSec tunnel are not synchronizing time equally(for example, different NTP servers not updating time with the same timestamp), tunnels will break and will have to be established again.}}
+
[[File:ESP-tunnel wiki.png]]
  
 +
===Encryption algorithms===
  
=== EAP Authentication methods ===
+
RouterOS ESP supports various encryption and authentication algorithms.
  
<table border="1">
+
Authentication:
 +
<ul class="bullets">
 +
  <li><b>MD5</b>
 +
  <li><b>SHA1</b>
 +
  <li><b>SHA2 (256-bit, 512-bit)</b>
 +
</ul>
 +
 
 +
Encryption:
 +
<ul class="bullets">
 +
  <li><b>AES</b> - 128-bit, 192-bit and 256-bit key AES-CBC, AES-CTR and AES-GCM algorithms;
 +
  <li><b>Blowfish</b> - added since v4.5
 +
  <li><b>Twofish</b> - added since v4.5
 +
  <li><b>Camellia</b> -  128-bit, 192-bit and 256-bit key Camellia encryption algorithm added since v4.5
 +
  <li><b>DES</b> - 56-bit DES-CBC encryption algorithm;
 +
  <li><b>3DES</b> - 168-bit DES encryption algorithm;
 +
</ul>
 +
 
 +
===Hardware acceleration===
 +
 
 +
Hardware acceleration allows to do faster encryption process by using built-in encryption engine inside CPU.
 +
<table class="styled_table">
 
<tr>
 
<tr>
  <th>Outer Auth</th>
+
<th rowspan=2 style="border-right: 2px solid white;">RouterBoard</th>
  <th>Inner Auth</th>
+
<th colspan=4 style="border-right: 2px solid white;">DES and 3DES</th>
 +
<th colspan=4 style="border-right: 2px solid white;">AES-CBC</th>
 +
<th colspan=4 style="border-right: 2px solid white;">AES-CTR</th>
 +
<th colspan=4>AES-GCM</th>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
  <td>EAP-GTC</td>
+
<th>MD5</th>
  <td></td>
+
<th>SHA1</th>
 +
<th>SHA256</th>
 +
<th style="border-right: 2px solid white;">SHA512</th>
 +
<th>MD5</th>
 +
<th>SHA1</th>
 +
<th>SHA256</th>
 +
<th style="border-right: 2px solid white;">SHA512</th>
 +
<th>MD5</th>
 +
<th>SHA1</th>
 +
<th>SHA256</th>
 +
<th style="border-right: 2px solid white;">SHA512</th>
 +
<th>MD5</th>
 +
<th>SHA1</th>
 +
<th>SHA256</th>
 +
<th>SHA512</th>
 
</tr>
 
</tr>
<tr><td>EAP-MD5</td><td></td></tr>
+
<tr><td>[https://mikrotik.com/product/cap_ac RBcAPGi-5acD2nD (cAP ac)] *</td>
<tr><td>EAP-MSCHAPv2</td><td></td></tr>
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
<tr>
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
  <td>EAP-PEAPv0</td>
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
  <td>
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
EAP-MSCHAPv2<br \>
+
 
EAP-GPSK<br \>
+
<tr><td>[https://mikrotik.com/product/audience RBD25G-5HPacQD2HPnD (Audience)] *</td>
EAP-GTC<br \>
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
EAP-MD5<br \>
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
EAP-TLS<br \>
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
  </td>
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>  
</tr>
+
 
<tr><td>EAP-SIM</td><td></td></tr>
+
<tr><td>[https://mikrotik.com/product/audience_lte6_kit RBD25GR-5HPacQD2HPnD&R11e-LTE6 (Audience LTE6 kit)] *</td>
<tr><td>EAP-TLS</td><td></td></tr>
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
<tr>
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
  <td>EAP-TTLS</td>
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
  <td>
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>  
PAP <br \>
+
 
CHAP <br \>
+
<tr><td>[https://mikrotik.com/product/hap_ac2 RBD52G-5HacD2HnD (hAP ac<sup>2</sup>)] *</td>
MS-CHAP <br \>
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
MS-CHAPv2 <br \>
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
EAP-MSCHAPv2<br \>
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
EAP-GTC<br \>
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
EAP-MD5<br \>
+
 
EAP-TLS<br \>
+
<tr><td>[https://mikrotik.com/product/disc_lite5_ac RBDiscG-5acD (DISC Lite5 ac)] *</td>
  </td>
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
</tr>
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
</table>
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
 +
 
 +
<tr><td>[https://mikrotik.com/product/ldf_5_ac RBLDFG-5acD (LDF 5 ac)] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
 +
 
 +
<tr><td>[https://mikrotik.com/product/lhg_5_ac RBLHGG-5acD (LHG 5 ac)] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
 +
 
 +
<tr><td>[https://mikrotik.com/product/lhg_xl_52_ac RBLHGG-5HPacD2HPnD-XL (LHG XL 52 ac)] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>  
 +
 
 +
<tr><td>[https://mikrotik.com/product/lhg_xl_5_ac RBLHGG-5acD-XL (LHG XL 5 ac)] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>  
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
  
<b>EAP-TLS</b> on Windows is called "Smart Card or other certificate".
+
<tr><td>[https://mikrotik.com/product/wireless_wire_dish RBLHGG-60ad (Wireless Wire Dish)] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
  
==Mode Config==
+
<tr><td>[https://mikrotik.com/product/m11g RBM11G] ****</td>
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec mode-config</code></p>
+
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
  
 +
<tr><td>[https://mikrotik.com/product/rbm33g RBM33G] ****</td>
 +
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
  
{{ Note | If RouterOS client is initiator, it will always send CISCO UNITY extension, and RouterOS supports only split-include from this extension.}}
+
<tr><td>[https://mikrotik.com/product/sxtsq_5_ac RBSXTsqG-5acD (SXTsq 5 ac)] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
  
{{Mr-arg-table-h
+
<tr><td>[https://mikrotik.com/product/wap_60g RBwAPG-60ad (wAP 60G)] *</td>
|prop=Property
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|desc=Description
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
}}
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
  
{{Mr-arg-table
+
<tr><td>[https://mikrotik.com/product/wap_60g_ap RBwAPG-60ad-A (wAP 60G AP)] *</td>
|arg=address-pool
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|type=none {{!}} string
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|default=
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|desc=Name of the address pool from which responder will try to assign address if mode-config is enabled.
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
}}
 
  
{{Mr-arg-table
+
<tr><td>[https://mikrotik.com/product/rb450gx4 RB450Gx4] *</td>
|arg=address-prefix-length
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|type=integer [1..32]
+
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|default=
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|desc=Prefix length (netmask) of assigned address from the pool.
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
}}
 
  
{{Mr-arg-table
+
<tr><td>[https://mikrotik.com/product/RB750Gr3 RB750Gr3 (hEX)] ****</td>
|arg=comment
+
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|type=string
+
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|default=
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
|desc=
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
}}
 
  
{{Mr-arg-table
+
<tr><td>[https://mikrotik.com/product/hex_s RB760iGS (hEX S)] ****</td>
|arg=name
+
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|type=string
+
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
|default=
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
|desc=
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
}}
 
  
{{Mr-arg-table
+
<tr><td>[https://mikrotik.com/product/RB850Gx2 RB850Gx2] **</td>
|arg=static-dns
+
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
|type=IP
+
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
|default=
+
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
|desc=Manually specified DNS server's IP address to be sent to the client
+
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
}}
+
 
 +
<tr><td>[https://mikrotik.com/product/RB1100AHx2 RB1100AHx2]</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
 +
 
 +
<tr><td>[https://mikrotik.com/product/rb1100ahx4 RB1100AHx4] and [https://mikrotik.com/product/RB1100Dx4 RB1100AHx4 Dude Edition]</td>
 +
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CTR --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-GCM --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td></tr>
 +
 
 +
<tr><td>[https://mikrotik.com/product/RB1200 RB1200] ***</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CTR --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
 +
 
 +
<tr><td>[https://mikrotik.com/product/RB3011UiAS-RM RB3011UiAS-RM] *</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightpink">no</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr> 
 +
 
 +
<tr><td>[https://mikrotik.com/product/rb4011igs_rm RB4011iGS+RM] and [https://mikrotik.com/product/rb4011igs_5hacq2hnd_in RB4011iGS+5HacQ2HnD-IN]</td>
 +
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CTR --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-GCM --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td></tr>
 +
 
 +
<tr><td>Cloud Core Router series</td>
 +
<!-- DES and 3DES --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CTR --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-GCM --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td></tr>
 +
 
 +
<tr><td>x86 (AES-NI) ***</td>
 +
<!-- DES and 3DES --><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td><td style="background-color:lightpink">no</td>
 +
<!-- AES-CBC --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-CTR --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td>
 +
<!-- AES-GCM --><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td><td style="background-color:lightgreen">yes</td></tr>
 +
</table>
 +
 
 +
<nowiki>*</nowiki> supported only 128 bit and 256 bit key sizes
 +
 
 +
<nowiki>**</nowiki> only manufactured since 2016, serial numbers that begin with number 5 and 7
 +
 
 +
<nowiki>***</nowiki> AES-CBC and AES-CTR only encryption is accelerated, hashing done in software
 +
 
 +
<nowiki>****</nowiki> DES is not supported, only 3DES and AES-CBC
 +
 
 +
IPsec throughput results of various encryption and hash algorithm combinations are published on [https://mikrotik.com/product/ MikroTik products page]. When testing throughput, please follow the guidelines available in the  [[Manual:Tools/Traffic_Generator#IpSec_tunnel_performance_test|Traffic Generator manual page]]
 +
 
 +
==Policies==
 +
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec policy</code></p>
  
{{Mr-arg-table
 
|arg=system-dns
 
|type=yes {{!}} no
 
|default=
 
|desc=When this option is enabled DNS addresses will be taken from /ip dns
 
}}
 
  
{{Mr-arg-table-end
+
Policy table is used to determine whether security settings should be applied to a packet.
|arg=split-include
 
|type=list of ip prefix
 
|default=
 
|desc=List of subnets in CIDR format, which to tunnel. Subnets will be sent to the peer using CISCO UNITY extension, remote peer will create specific dynamic policies.
 
}}
 
  
==XAuth Users==
 
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec user</code></p>
 
  
List of allowed XAuth users
+
'''Properties'''
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 303: Line 409:
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=address
+
|arg=action
|type=IP
+
|type=discard {{!}} encrypt {{!}} none
|default=
+
|default=encrypt
|desc=IP address assigned to the client. If not set dynamic address is used allocated from the address-pool defined in [[#Mode_Config | Mode Config menu]].
+
|desc=Specifies what to do with packet matched by the policy.
 +
* <var>none</var> - pass the packet unchanged.
 +
* <var>discard</var> - drop the packet.
 +
* <var>encrypt</var> - apply transformations specified in this policy and it's SA.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=name
+
|arg=comment
 
|type=string
 
|type=string
 
|default=
 
|default=
|desc=Username
+
|desc=Short description of the policy.
 
}}
 
}}
  
{{Mr-arg-table-end
+
{{Mr-arg-table
|arg=password
+
|arg=disabled
|type=string
+
|type=yes {{!}} no
|default=
+
|default=no
|desc=
+
|desc=Whether policy is used to match packets.
 
}}
 
}}
  
==Peer configuration==
+
{{Mr-arg-table
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec peer</code></p>
+
|arg=dst-address
 +
|type=IP/IPv6 prefix
 +
|default=0.0.0.0/32
 +
|desc=Destination address to be matched in packets. Applicable when tunnel mode (<var>tunnel=yes</var>) or template (<var>template=yes</var>) is used.
 +
}}
  
 +
{{Mr-arg-table
 +
|arg=dst-port
 +
|type=integer:0..65535 {{!}} any
 +
|default=any
 +
|desc=Destination port to be matched in packets. If set to <var>any</var> all ports will be matched.
 +
}}
  
Peer configuration settings are used to establish connections between IKE daemons ([[#Internet_Key_Exchange_Protocol | '''phase 1''']] configuration). This connection then will be used to negotiate keys and algorithms for SAs.
+
{{Mr-arg-table
 
+
|arg=group
Starting from v6rc12 responder side now uses initiator exchange type for peer config selection. It means that you can configure multiple ipsec peers with the same address but different exchange modes.
+
|type=string
 +
|default=default
 +
|desc=Name of the [[#Groups | policy group]] to which this template is assigned.
 +
}}
  
{{Note | exchange modes '''main''' and '''l2tp-main''' are treated the same, so these modes cannot be used select config between multiple peers.}}
 
 
{{Mr-arg-table-h
 
|prop=Property
 
|desc=Description
 
}}
 
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=address
+
|arg=ipsec-protocols
|type=IP/IPv6 Prefix
+
|type=ah {{!}} esp
|default=0.0.0.0/0
+
|default=esp
|desc=If remote peer's address matches this prefix, then the peer configuration is used in authentication and establishment of '''Phase 1'''. If several peer's addresses match several configuration entries, the most specific one (i.e. the one with largest netmask) will be used.
+
|desc=Specifies what combination  of Authentication Header and Encapsulating Security Payload protocols you want to apply to matched traffic.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=auth-method
+
|arg=level
|type=eap-radius {{!}} pre-shared-key {{!}} pre-shared-key-xauth {{!}} rsa-signature {{!}} rsa-key {{!}} rsa-signature-hybrid
+
|type=require {{!}} unique {{!}} use
|default=pre-shared-key
+
|default=require
|desc=Authentication method:
+
|desc=Specifies what to do if some of the SAs for this policy cannot be found:
* <var>eap-radius</var> - IKEv2 EAP RADIUS passthrough authentication for responder (RFC 3579). Server certificate in this case is required. If server certificate is not specified then only clients supporting EAP-only (RFC 5998) will be able to connect. Note that EAP method should be compatible with EAP-only.
+
* <var>use</var> - skip this transform, do not drop packet and do not acquire SA from IKE daemon;
* <var>pre-shared-key</var> - authenticate by a password (secret) string shared between the peers
+
* <var>require</var> - drop packet and acquire SA;
* <var>rsa-signature</var> - authenticate using a pair of RSA certificates
+
* <var>unique</var> - drop packet and acquire a unique SA that is only used with this particular policy. It is used in setups where multiple clients can sit behind one public IP address (clients behind NAT).
* <var>rsa-key</var> - authenticate using a RSA key imported in [[#Keys | Ipsec key]] menu.
 
* <var>pre-shared-key-xauth</var> - mutual PSK authentication + xauth username/password. <var>passive</var> parameter identifies server/client side
 
* <var>rsa-signature-hybrid</var> - responder certificate authentication with initiator Xauth. <var>passive</var> parameter identifies server/client side
 
 
 
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=certificate
+
|arg=peer
 
|type=string
 
|type=string
 
|default=
 
|default=
|desc=Name of a certificate listed in [[M:System/Certificates | certificate table]] (signing packets; the certificate must have private key). Applicable if RSA signature authentication method (auth-method=rsa-signature) is used.
+
|desc=Name of the [[#Peers | peer]] on which the policy applies.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=comment
+
|arg=proposal
 
|type=string
 
|type=string
|default=
+
|default=default
|desc=Short description of the peer.
+
|desc=Name of the [[#Proposals| proposal template]] that will be sent by IKE daemon to establish SAs for this policy.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=compatibility-options
+
|arg=protocol
|type=skip-peer-id-validation
+
|type=all {{!}}  egp {{!}} ggp{{!}} icmp {{!}} igmp {{!}} ...
|default=
+
|default=all
|desc=Compatibility options to work with peers not following RFC guidelines.
+
|desc=IP packet protocol to match.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=dh-group
+
|arg=src-address
|type=ec2n155  {{!}} ec2n185  {{!}} modp1024  {{!}} modp1536  {{!}} modp2048  {{!}} modp3072  {{!}} modp4096  {{!}} modp6144  {{!}} modp768
+
|type=ip/ipv6 prefix
|default=modp1024
+
|default=0.0.0.0/32
|desc=[[#Diffie-Hellman Groups | Diffie-Hellman group]] (cipher strength)
+
|desc=Source address to be matched in packets. Applicable when tunnel mode (<var>tunnel=yes</var>) or template (<var>template=yes</var>) is used.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=disabled
+
|arg=src-port
|type=yes {{!}} no
+
|type=any {{!}} integer:0..65535
|default=no
+
|default=any
|desc=Whether peer is used to match remote peer's prefix.
+
|desc=Source port to be matched in packets. If set to <var>any</var> all ports will be matched.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=dpd-interval
+
|arg=template
|type=time {{!}} disable-dpd
+
|type=yes {{!}} no
|default=2m
+
|default=no
|desc=Dead peer detection interval. If set to <var>disable-dpd</var>, dead peer detection will not be used.
+
|desc=Creates a template and assigns it to specified [[#Groups | policy group]].
 +
Following parameters are used by template:
 +
* <var>group</var> - name of the [[#Groups | policy group]] to which this template is assigned;
 +
* <var>src-address</var>, <var>dst-address</var> - Requested subnet must match in both directions(for example 0.0.0.0/0 to allow all);
 +
* <var>protocol</var> - protocol to match, if set to all, then any protocol is accepted;
 +
* <var>proposal</var> - SA parameters used for this template;
 +
* <var>level</var> - useful when <var>unique</var> is required in setups with multiple clients behind NAT.
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-table-end
|arg=dpd-maximum-failures
+
|arg=tunnel
|type=integer: 1..100
+
|type=yes {{!}} no
|default=5
+
|default=no
|desc=Maximum count of failures until peer is considered to be dead. Applicable if DPD is enabled.
+
|desc=Specifies whether to use tunnel mode.
 
}}
 
}}
  
{{Mr-arg-table
 
|arg=enc-algorithm
 
|type=3des {{!}} aes-128 {{!}} aes-192 {{!}} aes-256 {{!}} blowfish {{!}} camellia-128 {{!}} camellia-192 {{!}} camellia-256 {{!}} des
 
|default=aes-128
 
|desc=List of encryption algorithms that will be used by the peer.
 
}}
 
  
{{Mr-arg-table
+
'''Read only properties'''
|arg=exchange-mode
+
 
|type=aggressive {{!}} base {{!}} main {{!}} main-l2tp {{!}} ike2
+
{{Mr-arg-table-h
|default=main
+
|prop=Property
|desc=Different ISAKMP phase 1 exchange modes according to RFC 2408. Do not use other modes then main unless you know what you are doing.
+
|desc=Description
'''main-l2tp''' mode relaxes rfc2409 section 5.4, to allow pre-shared-key authentication in main mode. <var>ike2</var> mode enables Ikev2 RFC 7296. Parameters that are ignored by Ikev2 <var>proposal-check</var>, <var>compatibility-options</var>, <var>lifebytes</var>, <var>dpd-maximum-failures</var>.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=generate-policy
+
|arg=active
|type=no {{!}} port-override {{!}} port-strict
+
|type=yes {{!}} no
|default=no
+
|desc=Whether this policy is currently in use.
|desc=Allow this peer to establish SA for non-existing policies. Such policies are created dynamically for the lifetime of SA. Automatic policies allows, for example, to create IPsec secured [[M:Interface/L2TP | L2TP]] tunnels, or any other setup where remote peer's IP address is not known at the configuration time.
 
* <var>no</var> - do not generate policies
 
* <var>port-override</var> -- generate policies and force policy to use '''any''' port (old behavior)
 
* <var>port-strict</var> -- use ports from peer's proposal, which should match peer's policy
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=hash-algorithm
+
|arg=default
|type=md5 {{!}} sha1 {{!}} sha256 {{!}} sha512
+
|type=yes {{!}} no
|default=sha1
+
|desc=Whether this is a default system entry.
|desc=Hashing algorithm. SHA (Secure Hash Algorithm) is stronger, but slower. MD5 uses 128-bit key, sha1-160bit key.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=key
+
|arg=dynamic
|type=string
+
|type=yes {{!}} no
|default=
+
|desc=Whether this is a dynamically added or generated entry.
|desc=Name of the key from [[#Keys | key menu]]. Applicable if auth-method=rsa-key.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=lifebytes
+
|arg=invalid
|type=Integer: 0..4294967295
+
|type=yes {{!}} no
|default=0
+
|desc=Whether this policy is invalid - possible cause is duplicate policy with the same <var>src-address</var> and <var>dst-address</var>.
|desc=Phase 1 lifebytes is used only as administrative value which is added to proposal. Used in cases if remote peer requires specific lifebytes value to establish phase 1.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=lifetime
+
|arg=ph2-count
|type=time
+
|type=integer
|default=1d
+
|desc=Number of active phase 2 sessions associated with the policy.
|desc=Phase 1 lifetime: specifies how long the SA will be valid.
+
}}
 +
 
 +
{{Mr-arg-ro-table
 +
|arg=ph2-state
 +
|type=expired {{!}} no-phase2 {{!}} established
 +
|desc=Indication of the progress of key establishing.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=local-address
+
|arg=sa-dst-address
|type=IP/IPv6 Address
+
|type=ip/ipv6 address
|default=
+
|default=::
|desc=Routers local address on which Phase 1 should be bounded to.
+
|desc=SA destination IP/IPv6 address (remote peer).
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-table-end
|arg=mode-config
+
|arg=sa-src-address
|type=none {{!}} request-only {{!}} string
+
|type=ip/ipv6 address
|default=none
+
|default=::
|desc=Name of the mode config parameters from [[#Mode_Config | <code>mode-config</code> menu]]. When parameter is set mode-config is enabled.
+
|desc=SA source IP/IPv6 address (local peer).
* initiator peer on phase1 will send mode-config request and will set assigned IP address and DNS.
 
* responder will assign ip address if address-pool is specified, will send also DNS server addresses and split-include subnets (if defined).
 
 
}}
 
}}
  
{{Mr-arg-table
 
|arg=my-id
 
|type=auto {{!}} fqdn {{!}} user-fqdn {{!}} key-id
 
|default=auto
 
|desc=This parameter sets IKE ID to specified mode. It is possible to manually set two modes FQDN and USER_FQDN.
 
* '''FQDN''' - fully qualified domain name
 
* '''USER_FQDN''' - specifies a fully-qualified username string, for example, "user@domain.com";
 
* '''address''' - IP address is used as ID;
 
* '''auto''' - tries to use correct ID automatically: IP for PSK, FQDN for Cert based connections;
 
* '''key-id''' - Use the specified key-id for the identity
 
  
 +
{{Warning | policy order is important starting form v6.40. Now it works similar as firewall filters where policies are executed from top to bottom (<var>priority</var> parameter is removed).}}
 +
 +
{{Note |
 +
All packets are IPIP encapsulated in tunnel mode, and their new IP header's src-address and dst-address are set to sa-src-address and sa-dst-address values of this policy. If you do not use tunnel mode (id est you use transport mode), then only packets whose source and destination addresses are the same as sa-src-address and sa-dst-address can be processed by this policy. Transport mode can only work with packets that originate at and are destined for IPsec peers (hosts that established security associations). To encrypt traffic between networks (or a network and a host) you have to use tunnel mode.
 
}}
 
}}
  
{{Mr-arg-table
+
===Statistics===
|arg=nat-traversal
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec statistics</code></p>
|type=yes {{!}} no
+
 
|default=no
+
 
|desc=Use Linux NAT-T mechanism to solve IPsec incompatibility with NAT routers inbetween IPsec peers. This can only be used with ESP protocol (AH is not supported by design, as it signs the complete packet, including IP header, which is changed by NAT, rendering AH signature invalid). The method encapsulates IPsec ESP traffic into UDP streams in order to overcome some minor issues that made ESP incompatible with NAT.
+
This menu shows various IPsec statistics and errors.
}}
 
  
{{Mr-arg-table
 
|arg=notrack-chain
 
|type=string
 
|default=
 
|desc=Adds raw firewall rules matching ipsec policy to specified chain.
 
}}
 
  
{{Mr-arg-table
+
'''Read only properties'''
|arg=passive
 
|type=yes {{!}} no
 
|default=no
 
|desc=When passive mode is enabled will wait for remote peer to initiate IKE connection. Enabled passive mode also indicates that peer is xauth responder, and disabled passive mode - xauth initiator. When passive mode is disabled peer will try to establish not only phase1, but also phase2 automatically, if policies are configured or created during phase1.
 
}}
 
  
{{Mr-arg-table
+
{{Mr-arg-table-h
|arg=policy-template-group
+
|prop=Property
|type=none {{!}} string
+
|desc=Description
|default=
 
|desc=If generate-policy is enabled, responder checks against templates from the same [[#Policy_Groups | group]]. If none of the templates match, Phase2 SA will not be established.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=port
+
|arg=in-errors
|type=integer:0..65535
+
|type=integer
|default=500
+
|desc=All inbound errors that are not matched by other counters.
|desc=Communication port used (when router is initiator) to connect to remote peer in cases if remote peer uses non-default port.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=proposal-check
+
|arg=in-buffer-errors
|type=claim {{!}} exact {{!}} obey {{!}} strict
+
|type=integer
|default=obey
+
|desc=No free buffer.
|desc=Phase 2 lifetime check logic:
 
* <var>claim</var> - take shortest of proposed and configured lifetimes and notify initiator about it
 
* <var>exact</var> -  require lifetimes to be the same
 
* <var>obey</var> -  accept whatever is sent by an initiator
 
* <var>strict</var> -  if proposed lifetime is longer than the default then reject proposal otherwise accept proposed lifetime
 
 
}}
 
}}
  
{{Mr-arg-table
+
 
|arg=remote-certificate
+
{{Mr-arg-ro-table
|type=string
+
|arg=in-header-errors
|default=
+
|type=integer
|desc=Name of a certificate  (listed in [[M:System/Certificates | certificate table]]) for authenticating the remote side (validating packets; no private key required). Applicable if RSA signature authentication method is used.
+
|desc=Header error.
If remote-certificate is not specified then received certificate from remote peer is used and checked against CA in [[Manual:System/Certificates | certificate store]]. Proper CA must be imported in certificate store.
 
 
}}
 
}}
  
{{Mr-arg-table
+
 
|arg=secret
+
{{Mr-arg-ro-table
|type=string
+
|arg=in-no-states
|default=
+
|type=integer
|desc=Secret string (in case pre-shared key authentication is used). If it starts with '0x', it is parsed as a hexadecimal value
+
|desc=No state is found i.e. either inbound SPI, address, or IPsec protocol at SA is wrong.
 
}}
 
}}
  
{{Mr-arg-table
+
 
|arg=send-initial-contact
+
{{Mr-arg-ro-table
|type=yes {{!}} no
+
|arg=in-state-protocol-errors
|default=yes
+
|type=integer
|desc=Specifies whether to send "initial contact" IKE packet or wait for remote side, this packet should trigger removal of old peer SAs for current source address.
+
|desc=Transformation protocol specific error, for example SA key is wrong or hardware accelerator is unable to handle amount of packets.
Usually in road warrior setups clients are initiators and this parameter should be set to no. Initial contact is not sent if modecfg or xauth is enabled for ikev1.
 
 
}}
 
}}
  
{{Mr-arg-table
 
|arg=xauth-login
 
|type=string
 
|default=
 
|desc=initiator (client) XAuth username
 
}}
 
  
{{Mr-arg-table-end
+
{{Mr-arg-ro-table
|arg=xauth-password
+
|arg=in-state-mode-errors
|type=string
+
|type=integer
|default=
+
|desc=Transformation mode specific error.
|desc=initiator (client) XAuth password
 
 
}}
 
}}
  
  
{{Note |
+
{{Mr-arg-ro-table
IPSec phases information is erased, when /ip ipsec peer configuration is modified on the fly, however packets are being encrypted/decrypted because of installed-sa (for example remote-peers information is erased, when peer configuration is modified.}}
+
|arg=in-state-sequence-errors
 +
|type=integer
 +
|desc=Sequence number is out of window.
 +
}}
  
==Keys==
 
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec key</code></p>
 
  
This submenu list all imported public/private keys, that can be used for peer authentication.
+
{{Mr-arg-ro-table
Submenu also has several commands to work with keys.
+
|arg=in-state-expired
 
+
|type=integer
For example print below shows two imported 1024-bit keys, one public and one private.
+
|desc=State is expired.
<pre>
 
[admin@PoETik] /ip ipsec key> print
 
Flags: P - private-key, R - rsa
 
#    NAME                                                              KEY-SIZE
 
0 PR priv                                                              1024-bit
 
1  R pub                                                                1024-bit
 
</pre>
 
 
 
 
 
'''Commands'''
 
 
 
{{Mr-arg-table-h
 
|prop=Property
 
|desc=Description
 
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=export-pub-key
+
|arg=in-state-mismatches
|type=file-name; key
+
|type=integer
|desc=Export public key to file from one of existing private keys.  
+
|desc=State has mismatched option, for example UDP encapsulation type is mismatched.  
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=generate-key
+
|arg=in-state-invalid
|type=key-size; name
+
|type=integer
|desc=Generate private key. Takes two parameters, name of newly generated key and key size 1024,2048 and 4096.
+
|desc=State is invalid.
 
}}
 
}}
  
{{Mr-arg-ro-table-end
+
{{Mr-arg-ro-table
|arg=import
+
|arg=in-template-mismatches
|type=file-name; name
+
|type=integer
|desc=Import key from file.
+
|desc=No matching template for states, e.g. inbound SAs are correct but SP rule is wrong. Possible cause is mismatched sa-source or sa-destination address.
 
}}
 
}}
  
==Policy==
+
{{Mr-arg-ro-table
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec policy</code></p>
+
|arg=in-no-policies
 +
|type=integer
 +
|desc=No policy is found for states, e.g. inbound SAs are correct but no SP is found.
 +
}}
  
 +
{{Mr-arg-ro-table
 +
|arg=in-policy-blocked
 +
|type=integer
 +
|desc=Policy discards.
 +
}}
  
Policy table is used to determine whether security settings should be applied to a packet.
+
{{Mr-arg-ro-table
 +
|arg=in-policy-errors
 +
|type=integer
 +
|desc=Policy errors.
 +
}}
  
{{Warning | policy order is important starting form v6.40. Now it works similar as firewall filters where policies are executed from top to bottom (<var>priority</var> parameter is removed).}}
+
{{Mr-arg-ro-table
 +
|arg=out-errors
 +
|type=integer
 +
|desc=All outbound errors that are not matched by other counters.
 +
}}
  
 
+
{{Mr-arg-ro-table
{{Mr-arg-table-h
+
|arg=out-bundle-errors
|prop=Property
+
|type=integer
|desc=Description
+
|desc=Bundle generation error.
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=action
+
|arg=out-bundle-check-errors
|type=discard {{!}} encrypt {{!}} none
+
|type=integer
|default=encrypt
+
|desc=Bundle check error.
|desc=Specifies what to do with packet matched by the policy.
 
* <var>none</var> - pass the packet unchanged
 
* <var>discard</var> - drop the packet
 
* <var>encrypt</var> - apply transformations specified in this policy and it's SA
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=comment
+
|arg=out-no-states
|type=string
+
|type=integer
|default=
+
|desc=No state is found.
|desc=Short description of the policy
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=disabled
+
|arg=out-state-protocol-errors
|type=yes {{!}} no
+
|type=integer
|default=no
+
|desc=Transformation protocol specific error.
|desc=Whether policy is used to match packets.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=dst-address
+
|arg=out-state-mode-errors
|type=IP/IPv6 prefix
+
|type=integer
|default=0.0.0.0/32
+
|desc=Transformation mode specific error.
|desc=Destination address to be matched in packets.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=dst-port
+
|arg=out-state-sequence-errors
|type=integer:0..65535 {{!}} any
+
|type=integer
|default=any
+
|desc=Sequence errors, for example sequence number overflow.
|desc=Destination port to be matched in packets. If set to '''any''' all ports will be matched
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=group
+
|arg=out-state-expired
|type=string
+
|type=integer
|default=default
+
|desc=State is expired.
|desc=Name of the [[#Policy_Group | policy group]] to which this template is assigned.
 
 
}}
 
}}
  
 
+
{{Mr-arg-ro-table
{{Mr-arg-table
+
|arg=out-policy-blocked
|arg=ipsec-protocols
+
|type=integer
|type=ah {{!}} esp
+
|desc=Policy discards.
|default=esp
 
|desc=Specifies what combination  of Authentication Header and Encapsulating Security Payload protocols you want to apply to matched traffic
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=level
+
|arg=out-policy-dead
|type=require {{!}} unique {{!}} use
+
|type=integer
|default=require
+
|desc=Policy is dead.
|desc=Specifies what to do if some of the SAs for this policy cannot be found:
+
}}
* <var>use</var> - skip this transform, do not drop packet and do not acquire SA from IKE daemon
+
 
* <var>require</var> - drop packet and acquire SA
+
{{Mr-arg-ro-table-end
* <var>unique</var> - drop packet and acquire a unique SA that is only used with this particular policy. It is used in setups where multiple clients can sit behind one public IP address (clients behind NAT).
+
|arg=out-policy-errors
 +
|type=integer
 +
|desc=Policy error.
 
}}
 
}}
  
{{Mr-arg-table
+
==Proposals==
|arg=manual-sa
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec proposal</code></p>
|type=string {{!}} none
+
 
|default=none
+
 
|desc=Name of the [[#Manual SA|manual SA]] template
+
Proposal information that will be sent by IKE daemons to establish SAs for certain policy.
 +
 
 +
 
 +
'''Properties'''
 +
 
 +
{{Mr-arg-table-h
 +
|prop=Property
 +
|desc=Description
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=proposal
+
|arg=auth-algorithms
|type=string
+
|type=md5{{!}}null{{!}}sha1{{!}}sha256{{!}}sha512
|default=default
+
|default=sha1
|desc=Name of the [[#Proposal settings|proposal template]] that will be sent by IKE daemon to establish SAs for this policy.
+
|desc=Allowed algorithms for authorization. SHA (Secure Hash Algorithm) is stronger, but slower. MD5 uses 128-bit key, sha1-160bit key.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=protocol
+
|arg=comment
|type=all {{!}}  egp {{!}} ggp{{!}} icmp {{!}} igmp {{!}} ...
+
|type=string
|default=all
+
|default=
|desc=IP packet protocol to match.
+
|desc=
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=sa-dst-address
+
|arg=disabled
|type=ip/ipv6 address
+
|type=yes {{!}} no
|default=::
+
|default=no
|desc=SA destination IP/IPv6 address (remote peer).
+
|desc=Whether item is disabled.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=sa-src-address
+
|arg=enc-algorithms
|type=ip/ipv6 address
+
|type=null{{!}}des{{!}}3des{{!}}aes-128-cbc{{!}}aes-128-cbc{{!}}aes-128gcm{{!}}aes-192-cbc{{!}}aes-192-ctr{{!}}aes-192-gcm{{!}}aes-256-cbc{{!}}aes-256-ctr{{!}}aes-256-gcm{{!}}blowfish{{!}}camellia-128{{!}}camellia-192{{!}}camellia-256{{!}}twofish
|default=::
+
|default=aes-256-cbc,aes-192-cbc,aes-128-cbc
|desc=SA source IP/IPv6 address (local peer).
+
|desc=Allowed algorithms and key lengths to use for SAs.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=src-address
+
|arg=lifetime
|type=ip/ipv6 prefix
+
|type=time
|default=0.0.0.0/32
+
|default=30m
|desc=Source IP prefix
+
|desc=How long to use SA before throwing it out.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=src-port
+
|arg=name
|type=any {{!}} integer:0..65535
+
|type=string
|default=any
+
|default=
|desc=Source Port of the packet
+
|desc=
}}
 
 
 
{{Mr-arg-table
 
|arg=template
 
|type=yes {{!}} no
 
|default=no
 
|desc=Creates a template and assigns it to specified [[#Policy_Group | policy group]]
 
Following parameters are used by template:
 
* src-address, dst-address - Requested subnet must match in both directions(for example 0.0.0.0/0 to allow all)
 
* protocol - protocol to match, if set to all, then any protocol is accepted
 
* proposal - SA parameters used for this template
 
* level - useful when 'unique' is required in setups with multiple clients behind NAT.
 
 
}}
 
}}
  
 
{{Mr-arg-table-end
 
{{Mr-arg-table-end
|arg=tunnel
+
|arg=pfs-group
|type=yes {{!}} no
+
|type=ec2n155 {{!}} ec2n185 {{!}} ecp256 {{!}} ecp384 {{!}} ecp521 {{!}} modp768 {{!}} modp1024 {{!}} modp1536 {{!}} modp2048 {{!}} modp3072 {{!}} modp4096 {{!}} modp6144 {{!}} modp8192 {{!}} none
|default=no
+
|default=modp1024
|desc=Specifies whether to use tunnel mode
+
|desc=Diffie-Helman group used for Perfect Forward Secrecy.
}}
 
 
 
 
 
{{Note |
 
All packets are IPIP encapsulated in tunnel mode, and their new IP header's src-address and dst-address are set to sa-src-address and sa-dst-address values of this policy. If you do not use tunnel mode (id est you use transport mode), then only packets whose source and destination addresses are the same as sa-src-address and sa-dst-address can be processed by this policy. Transport mode can only work with packets that originate at and are destined for IPsec peers (hosts that established security associations). To encrypt traffic between networks (or a network and a host) you have to use tunnel mode.
 
 
}}
 
}}
  
  
===Policy Stats===
+
'''Read only properties'''
 
 
Read-only parameters
 
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 778: Line 832:
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-ro-table-end
|arg=ph2-count
+
|arg=default
|type=integer
+
|type=yes {{!}} no
|desc=Number of active phase2 sessions associated with the policy.
+
|default=
 +
|desc=Whether this is a default system entry.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
==Groups==
|arg=ph2-state
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec policy group</code></p>
|type=expired {{!}} no-phase2 {{!}} established
+
 
|desc=Indication of the progress of key establishing.
 
}}
 
  
{{Mr-arg-ro-table-end
+
In this menu it is possible to create additional policy groups used by policy templates.
|arg=priority
 
|type=
 
|desc=Shows kernel priority
 
}}
 
  
  
Additionally you can get policy stats with command <b><code>/ip ipsec policy print stats</code></b> will show current status of the policy. Additional read-only parameters will be printed.
+
'''Properties'''
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 804: Line 853:
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=in-accepted
+
|arg=name
|type=integer
+
|type=string
|desc=How many incoming packets were passed by the policy without an attempt to decrypt.
+
|default=
 +
|desc=
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table-end
|arg=in-dropped
+
|arg=comment
|type=integer
+
|type=string
|desc=How many incoming packets were dropped by the policy without an attempt to decrypt
+
|default=
 +
|desc=
 
}}
 
}}
  
{{Mr-arg-ro-table
+
==Peers==
|arg=in-transformed
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec peer</code></p>
|type=integer
 
|desc=How many incoming packets were decrypted (ESP) and/or verified (AH) by the policy
 
}}
 
  
{{Mr-arg-ro-table
 
|arg=out-accepted
 
|type=integer
 
|desc=How many outgoing packets were passed by the policy without an attempt to encrypt.
 
}}
 
  
{{Mr-arg-ro-table
+
Peer configuration settings are used to establish connections between IKE daemons. This connection then will be used to negotiate keys and algorithms for SAs. Exchange mode is the only unique identifier between the peers, meaning that there can be multiple peer configurations with the same <var>remote-address</var> as long as different <var>exchange-mode</var> is used.
|arg=out-dropped
 
|type=integer
 
|desc=How many outgoing packets were dropped by the policy without an attempt to encrypt.
 
}}
 
  
{{Mr-arg-ro-table-end
 
|arg=out-transformed
 
|type=integer
 
|desc=How many outgoing packets were encrypted (ESP) and/or verified (AH) by the policy.
 
}}
 
  
==Policy Groups==
+
'''Properties'''
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec policy group</code></p>
 
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 849: Line 882:
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=name
+
|arg=address
|type=string
+
|type=IP/IPv6 Prefix
|default=
+
|default=0.0.0.0/0
|desc=
+
|desc=If remote peer's address matches this prefix, then the peer configuration is used in authentication and establishment of '''Phase 1'''. If several peer's addresses match several configuration entries, the most specific one (i.e. the one with largest netmask) will be used.
 
}}
 
}}
  
{{Mr-arg-table-end
+
{{Mr-arg-table
 
|arg=comment
 
|arg=comment
 
|type=string
 
|type=string
 
|default=
 
|default=
|desc=
+
|desc=Short description of the peer.
 
}}
 
}}
  
==Proposal settings==
+
{{Mr-arg-table
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec proposal</code></p>
+
|arg=disabled
 +
|type=yes {{!}} no
 +
|default=no
 +
|desc=Whether peer is used to match remote peer's prefix.
 +
}}
  
 
+
{{Mr-arg-table
Proposal information that will be sent by IKE daemon to establish SAs for this policy ([[#Internet_Key_Exchange_Protocol | '''Phase 2''']]). Configured proposals are set in [[#Policy | policy configuration]].
+
|arg=exchange-mode
 
+
|type=aggressive {{!}} base {{!}} main {{!}} ike2
 
+
|default=main
{{Mr-arg-table-h
+
|desc=Different ISAKMP phase 1 exchange modes according to RFC 2408.
|prop=Property
+
'''main''' mode relaxes rfc2409 section 5.4, to allow pre-shared-key authentication in main mode. <var>ike2</var> mode enables Ikev2 RFC 7296. Parameters that are ignored by IKEv2 <var>proposal-check</var>, <var>compatibility-options</var>, <var>lifebytes</var>, <var>dpd-maximum-failures</var>, <var>nat-traversal</var>.
|desc=Description
 
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=auth-algorithms
+
|arg=local-address
|type=md5{{!}}sha1{{!}}null{{!}}sha256{{!}}sha512
+
|type=IP/IPv6 Address
|default=sha1
+
|default=
|desc=Allowed algorithms for authorization. SHA (Secure Hash Algorithm) is stronger, but slower. MD5 uses 128-bit key, sha1-160bit key..
+
|desc=Routers local address on which Phase 1 should be bounded to.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=comment
+
|arg=name
 
|type=string
 
|type=string
 
|default=
 
|default=
|desc=Short description of an item.
+
|desc=
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=disabled
+
|arg=passive
 
|type=yes {{!}} no
 
|type=yes {{!}} no
 
|default=no
 
|default=no
|desc=Whether item is disabled.
+
|desc=When passive mode is enabled will wait for remote peer to initiate IKE connection. Enabled passive mode also indicates that peer is xauth responder, and disabled passive mode - xauth initiator. When passive mode is disabled peer will try to establish not only phase1, but also phase2 automatically, if policies are configured or created during phase1.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=enc-algorithms
+
|arg=port
|type=null{{!}}des{{!}}3des{{!}}aes-128-cbc{{!}}aes-128-cbc{{!}}aes-128gcm{{!}}aes-192-cbc{{!}}aes-192-ctr{{!}}aes-192-gcm{{!}}aes-256-cbc{{!}}aes-256-ctr{{!}}aes-256-gcm{{!}}blowfish{{!}}camellia-128{{!}}camellia-192{{!}}camellia-256{{!}}twofish
+
|type=integer:0..65535
|default=aes-128-cbc
+
|default=500
|desc=Allowed algorithms and key lengths to use for SAs.
+
|desc=Communication port used (when router is initiator) to connect to remote peer in cases if remote peer uses non-default port.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=lifetime
+
|arg=profile
|type=time
 
|default=30m
 
|desc=How long to use SA before throwing it out.
 
}}
 
 
 
{{Mr-arg-table
 
|arg=name
 
 
|type=string
 
|type=string
|default=
+
|default=default
|desc=Name of the proposal template, that will be identified in other parts of ipsec configuration.
+
|desc=Name of the [[#Profiles| profile template]] that will be used during IKE negotiation.
 
}}
 
}}
  
 
{{Mr-arg-table-end
 
{{Mr-arg-table-end
|arg=pfs-group
+
|arg=send-initial-contact
|type=ec2n155 {{!}} ec2n185 {{!}} modp1024 {{!}} modp1536 {{!}} modp2048 {{!}} modp3072 {{!}} modp4096 {{!}} modp6144 {{!}} modp768 {{!}} none
+
|type=yes {{!}} no
|default=modp1024
+
|default=yes
|desc=Diffie-Helman group used for Perfect Forward Secrecy.
+
|desc=Specifies whether to send "initial contact" IKE packet or wait for remote side, this packet should trigger removal of old peer SAs for current source address.
 +
Usually in road warrior setups clients are initiators and this parameter should be set to no. Initial contact is not sent if modecfg or xauth is enabled for ikev1.
 
}}
 
}}
  
==Manual SA==
 
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec manual-sa</code></p>
 
  
 
+
'''Read only properties'''
Menu is used to configure SAs manually. Created SA template then can be used in [[#Policy | policy]] configuration.
 
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 934: Line 961:
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table
|arg=ah-algorithm
+
|arg=dynamic
|type=in/out <br />
+
|type=yes {{!}} no
in,out = md5{{!}}null{{!}}sha1
+
|default=
|default=null
+
|desc=Whether this is a dynamically added entry by different service (e.g L2TP).
|desc=Authentication Header encryption algorithm.
 
 
}}
 
}}
  
{{Mr-arg-table
+
{{Mr-arg-ro-table-end
|arg=ah-key
+
|arg=responder
|type=string/string
+
|type=yes {{!}} no
 
|default=
 
|default=
|desc=Incoming-authentication-key/outgoing-authentication-key
+
|desc=Whether this peer will act as a responder only (listen to incoming requests) and not initiate a connection.
 
}}
 
}}
  
{{Mr-arg-table
 
|arg=ah-spi
 
|type=0x100..FFFFFFFF/0x100..FFFFFFFF
 
|default=0x100
 
|desc=Incoming-SA-SPI/outgoing-SA-SPI
 
}}
 
  
{{Mr-arg-table
+
==Identities==
|arg=disabled
+
 
|type=yes {{!}} no
+
Identities are configuration parameters that are specific to the remote peer. Main purpose of an identity is to handle authentication and verify peer's integrity.
|default=no
+
 
|desc=Defines whether item is ignored or used
+
'''Properties'''
 +
 
 +
{{Mr-arg-table-h
 +
|prop=Property
 +
|desc=Description
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=esp-auth-algorithm
+
|arg=auth-method
|type=in/out<br />
+
|type=digital-signature {{!}} eap {{!}} eap-radius {{!}} pre-shared-key {{!}} pre-shared-key-xauth {{!}} rsa-key {{!}} rsa-signature-hybrid
in,out = md5{{!}}null{{!}}sha1
+
|default=pre-shared-key
|default=null
+
|desc=Authentication method:
|desc=Encapsulating Security Payload authentication encryption algorithm
+
* <var>digital-signature</var> - authenticate using a pair of RSA certificates;
 +
* <var>eap</var> - IKEv2 EAP authentication for initiator (peer with netmask of /32). Must be used together with <var>eap-methods</var>;
 +
* <var>eap-radius</var> - IKEv2 EAP RADIUS passthrough authentication for responder (RFC 3579). Server certificate in this case is required. If server certificate is not specified then only clients supporting EAP-only (RFC 5998) will be able to connect. Note that EAP method should be compatible with EAP-only;
 +
* <var>pre-shared-key</var> - authenticate by a password (pre-shared secret) string shared between the peers (not recommended since offline attack on pre-shared key is possible);
 +
* <var>rsa-key</var> - authenticate using a RSA key imported in [[#Keys | keys]] menu. Only supported in IKEv1;
 +
* <var>pre-shared-key-xauth</var> - authenticate by a password (pre-shared secret) string shared between the peers + XAuth username and password. Only supported in IKEv1;
 +
* <var>rsa-signature-hybrid</var> - responder certificate authentication with initiator XAuth. Only supported in IKEv1.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=esp-auth-key
+
|arg=certificate
|type=string/string
+
|type=string
 
|default=
 
|default=
|desc=Incoming-authentication-key/outgoing -authentication-key
+
|desc=Name of a certificate listed in [[M:System/Certificates | System/Certificates]] (signing packets; the certificate must have private key). Applicable if digital signature authentication method (<var>auth-method=digital-signature</var>) or EAP (<var>auth-method=eap</var>) is used.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=esp-enc-algorithm
+
|arg=comment
|type=in/out<br />
+
|type=string
in,out = 3des {{!}} aes-128 {{!}} aes-192 {{!}} aes-256 {{!}} des {{!}} ...
+
|default=
|default=null
+
|desc=Short description of the identity.
|desc=Incoming-encryption-algorithm
 
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=esp-enc-key
+
|arg=disabled
|type=string/string
+
|type=yes {{!}} no
|default=
+
|default=no
|desc=Incoming-encryption-key/outgoing-encryption-key
+
|desc=Whether identity is used to match remote peer.
 
}}
 
}}
 +
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=esp-spi
+
|arg=eap-methods
|type=0x100..FFFFFFFF/0x100..FFFFFFFF
+
|type=eap-mschapv2 {{!}} eap-peap {{!}} eap-tls {{!}} eap-ttls
|default=0x100
+
|default=eap-tls
|desc=Incoming-SA-SPI/outgoing-SA-SPI
+
|desc=All EAP methods requires whole certificate chain including intermediate and root CA certificates to be present in [[M:System/Certificates | System/Certificates]] menu. Also <var>username</var> and <var>password</var> (if required by authentication server) must be specified. Multiple EAP methods may be specified and will be used in specified order. Currently supported EAP methods:
 +
* <var>eap-mschapv2</var>;
 +
* <var>eap-peap</var> - also known as PEAPv0/EAP-MSCHAPv2;
 +
* <var>eap-tls</var> - requires additional client certificate specified under <var>certificate</var> parameter;
 +
* <var>eap-ttls</var>.
 
}}
 
}}
  
 
{{Mr-arg-table
 
{{Mr-arg-table
|arg=lifetime
+
|arg=generate-policy
|type=time
+
|type=no {{!}} port-override {{!}} port-strict
|default=0s
+
|default=no
|desc=Lifetime of this SA
+
|desc=Allow this peer to establish SA for non-existing policies. Such policies are created dynamically for the lifetime of SA. Automatic policies allows, for example, to create IPsec secured [[M:Interface/L2TP | L2TP]] tunnels, or any other setup where remote peer's IP address is not known at the configuration time.
 +
* <var>no</var> - do not generate policies;
 +
* <var>port-override</var> - generate policies and force policy to use '''any''' port (old behavior);
 +
* <var>port-strict</var> - use ports from peer's proposal, which should match peer's policy.
 
}}
 
}}
  
{{Mr-arg-table-end
+
{{Mr-arg-table
|arg=name
+
|arg=key
 
|type=string
 
|type=string
 
|default=
 
|default=
|desc=Name of the item for reference from policies
+
|desc=Name of the private key from [[#Keys | keys]] menu. Applicable if RSA key authentication method (<var>auth-method=rsa-key</var>) is used.
 
}}
 
}}
  
==Installed SA==
+
{{Mr-arg-table
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec installed-sa</code></p>
+
|arg=match-by
 +
|type=remote-id {{!}} certificate
 +
|default=remote-id
 +
|desc=Defines the logic used for peer's identity validation.
 +
* <var>remote-id</var> - will verify the peer's ID according to <var>remote-id</var> setting.
 +
* <var>certificate</var> will verify the peer's certificate with what is specified under <var>remote-certificate</var> setting.
 +
}}
  
 +
{{Mr-arg-table
 +
|arg=mode-config
 +
|type=none {{!}} *request-only {{!}} string
 +
|default=none
 +
|desc=Name of the configuration parameters from [[#Mode_Configs | mode-config]] menu. When parameter is set mode-config is enabled.
 +
}}
  
This facility provides information about installed security associations including the keys.
+
{{Mr-arg-table
 
+
|arg=my-id
 
+
|type=auto {{!}} address {{!}} fqdn {{!}} user-fqdn {{!}} key-id
{{Mr-arg-table-h
+
|default=auto
|prop=Property
+
|desc=On initiator, this controls what ID_i is sent to the responder. On responder, this controls what ID_r is sent to the initiator. In IKEv2, responder also expects this ID in received ID_r from initiator.
|desc=Description
+
* <var>auto</var> - tries to use correct ID automatically: IP for pre-shared key, SAN (DN if not present) for certificate based connections;
 +
* <var>address</var> - IP address is used as ID;
 +
* <var>fqdn</var> - fully qualified domain name;
 +
* <var>key-id</var> - use the specified key ID for the identity;
 +
* <var>user fqdn</var> - specifies a fully-qualified username string, for example, "user@domain.com".
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=AH
+
|arg=notrack-chain
|type=yes {{!}} no
+
|type=string
|desc=
+
|default=
 +
|desc=Adds [[M:IP/Firewall/Raw | IP/Firewall/Raw]] rules matching IPsec policy to specified chain. Use together with <var>generate-policy</var>.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=ESP
+
|arg=password
|type=yes {{!}} no
+
|type=string
|desc=
+
|default=
 +
|desc=XAuth or EAP password. Applicable if pre-shared key with XAuth authentication method (<var>auth-method=pre-shared-key-xauth</var>) or EAP (<var>auth-method=eap</var>) is used.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=add-lifetime
+
|arg=peer
|type=time/time
+
|type=string
|desc=Added lifetime for the SA in format soft/hard
+
|default=
* soft - time period after which ike will try to establish new SA
+
|desc=Name of the [[#Peers | peer]] on which the identity applies.
* hard - time period after which SA is deleted
 
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=addtime
+
|arg=policy-template-group
|type=time
+
|type=none {{!}} string
|desc=Date and time when this SA was added.
+
|default=default
 +
|desc=If <var>generate-policy</var> is enabled, traffic selectors are checked against templates from the same [[#Groups | group]]. If none of the templates match, Phase 2 SA will not be established.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=auth-algorithm
+
|arg=remote-certificate
|type=sha1 {{!}} md5
 
|desc=Shows currently used authentication algorithm
 
}}
 
 
 
{{Mr-arg-ro-table
 
|arg=auth-key
 
 
|type=string
 
|type=string
|desc=Shows used authentication key
+
|default=
 +
|desc=Name of a certificate  (listed in [[M:System/Certificates | System/Certificates]]) for authenticating the remote side (validating packets; no private key required). If <var>remote-certificate</var> is not specified then received certificate from remote peer is used and checked against CA in certificate menu. Proper CA must be imported in certificate store. If <var>remote-certificate</var> and <var>match-by=certificate</var> is specified, only the specific client certificate will be matched. Applicable if digital signature authentication method (<var>auth-method=digital-signature</var>) is used.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=current-bytes
+
|arg=remote-id
|type=64-bit integer
+
|type=auto {{!}} fqdn {{!}} user-fqdn {{!}} key-id {{!}} ignore
|desc=Shows number of bytes seen by this SA.
+
|default=auto
 +
|desc=This parameter controls what ID value to expect from the remote peer. Note that all types except for <var>ignore</var> will verify remote peer's ID with received certificate. In case when the peer sends certificate name as its ID, it is checked against the certificate, else the ID is checked against Subject Alt. Name.
 +
* <var>auto</var> - accept all ID's;
 +
* <var>fqdn</var> - fully qualified domain name. Only supported in IKEv2;
 +
* <var>user fqdn</var> - a fully-qualified username string, for example, "user@domain.com". Only supported in IKEv2;
 +
* <var>key-id</var> - specific key ID for the identity. Only supported in IKEv2;
 +
* <var>ignore</var> - do not verify received ID with certificate (dangerous).
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=dst-address
+
|arg=remote-key
|type=IP
+
|type=string
|desc=
+
|default=
 +
|desc=Name of the public key from [[#Keys | keys]] menu. Applicable if RSA key authentication method (<var>auth-method=rsa-key</var>) is used.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=enc-algorithm
+
|arg=secret
|type=des {{!}} 3des {{!}} aes ...
+
|type=string
|desc=Shows currently used encryption algorithm
+
|default=
 +
|desc=Secret string. If it starts with '0x', it is parsed as a hexadecimal value. Applicable if pre-shared key authentication method (<var>auth-method=pre-shared-key</var> and <var>auth-method=pre-shared-key-xauth</var>) is used.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table-end
|arg=pfs
+
|arg=username
|type=yes {{!}} no
+
|type=string
|desc=
+
|default=
 +
|desc=XAuth or EAP username. Applicable if pre-shared key with XAuth authentication method (<var>auth-method=pre-shared-key-xauth</var>) or EAP (<var>auth-method=eap</var>) is used.
 
}}
 
}}
  
{{Mr-arg-ro-table
 
|arg=replay
 
|type=integer
 
|desc=
 
}}
 
  
{{Mr-arg-ro-table
+
'''Read only properties'''
|arg=spi
+
 
|type=string
+
{{Mr-arg-table-h
|desc=
+
|prop=Property
}}
+
|desc=Description
 
 
{{Mr-arg-ro-table
 
|arg=src-address
 
|type=IP
 
|desc=
 
 
}}
 
}}
  
 
{{Mr-arg-ro-table-end
 
{{Mr-arg-ro-table-end
|arg=state
+
|arg=dynamic
|type=string
+
|type=yes {{!}} no
|desc=Shows the current state of the SA ("mature", "dying" etc)
+
|default=
 +
|desc=Whether this is a dynamically added entry by different service (e.g L2TP).
 
}}
 
}}
  
===Flushing SAs===
+
==Profiles==
  
Sometimes after incorrect/incomplete negotiations took place, it is required to flush manually the installed SA table so that SA could be renegotiated. This option is provided by the <code>/ip ipsec installed-sa flush</code> command.
+
Profiles defines a set of parameters that will be used for IKE negotiation during Phase 1. These parameters may be common with other peer configurations.
  
This command accepts only one property:
+
'''Properties'''
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 1,122: Line 1,172:
 
|desc=Description
 
|desc=Description
 
}}
 
}}
{{Mr-arg-table-end
+
 
|arg=sa-type
+
{{Mr-arg-table
|type=ah {{!}} all {{!}} esp
+
|arg=dh-group
|default=all
+
|type=modp768 {{!}} modp1024 {{!}} ec2n155 {{!}} ec2n185 {{!}} modp1536 {{!}} modp2048 {{!}} modp3072 {{!}} modp4096 {{!}} modp6144 {{!}} modp8192 {{!}} ecp256 {{!}} ecp384 {{!}} ecp521
|desc=Specifies SA types to flush:
+
|default=modp1024,modp2048
* <var>ah</var> - delete AH protocol SAs only
+
|desc=[[#Diffie-Hellman Groups | Diffie-Hellman group]] (cipher strength)
* <var>esp</var> - delete ESP protocol SAs only
 
* <var>all</var> - delete both ESP and AH protocols SAs
 
 
}}
 
}}
  
==Remote Peers==
+
{{Mr-arg-table
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec remote-peers</code></p>
+
|arg=dpd-interval
 
+
|type=time {{!}} disable-dpd
 
+
|default=2m
This submenu provides you with various statistics about remote peers that currently have established phase 1 connections with this router. Note that if peer doesn't show up here, it doesn't mean that no IPsec traffic is being exchanged with it.  
+
|desc=Dead peer detection interval. If set to <var>disable-dpd</var>, dead peer detection will not be used.
 
+
}}
  
Read only properties:
+
{{Mr-arg-table
 
+
|arg=dpd-maximum-failures
{{Mr-arg-table-h
+
|type=integer: 1..100
|prop=Property
+
|default=5
|desc=Description
+
|desc=Maximum count of failures until peer is considered to be dead. Applicable if DPD is enabled.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=local-address
+
|arg=enc-algorithm
|type=ip/ipv6 address
+
|type=3des {{!}} aes-128 {{!}} aes-192 {{!}} aes-256 {{!}} blowfish {{!}} camellia-128 {{!}} camellia-192 {{!}} camellia-256 {{!}} des
|desc=Local ISAKMP SA address on the router used by the peer
+
|default=aes-128
 +
|desc=List of encryption algorithms that will be used by the peer.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=remote-address
+
|arg=hash-algorithm
|type=ip/ipv6 address
+
|type=md5 {{!}} sha1 {{!}} sha256 {{!}} sha512
|desc=Remote peer's ip/ipv6 address
+
|default=sha1
 +
|desc=Hashing algorithm. SHA (Secure Hash Algorithm) is stronger, but slower. MD5 uses 128-bit key, sha1-160bit key.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=side
+
|arg=lifebytes
|type=initiator {{!}} responder
+
|type=Integer: 0..4294967295
|desc=Shows which side initiated the Phase1 negotiation.
+
|default=0
 +
|desc=Phase 1 lifebytes is used only as administrative value which is added to proposal. Used in cases if remote peer requires specific lifebytes value to establish phase 1.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=state
+
|arg=lifetime
|type=string
+
|type=time
|desc=State of phase 1 negotiation with the peer. For example when phase1 and phase 2 are negotiated it will show state "established".
+
|default=1d
 +
|desc=Phase 1 lifetime: specifies how long the SA will be valid.
 
}}
 
}}
  
{{Mr-arg-ro-table-end
+
{{Mr-arg-table
|arg=established
+
|arg=name
|type=time
+
|type=string
|desc=How long peers are in established state.
+
|default=
 +
|desc=
 
}}
 
}}
  
 +
{{Mr-arg-table
 +
|arg=nat-traversal
 +
|type=yes {{!}} no
 +
|default=yes
 +
|desc=Use Linux NAT-T mechanism to solve IPsec incompatibility with NAT routers inbetween IPsec peers. This can only be used with ESP protocol (AH is not supported by design, as it signs the complete packet, including IP header, which is changed by NAT, rendering AH signature invalid). The method encapsulates IPsec ESP traffic into UDP streams in order to overcome some minor issues that made ESP incompatible with NAT.
 +
}}
  
===Closing all IPsec connections===
+
{{Mr-arg-table-end
 
+
|arg=proposal-check
Menu has a command to quickly close all established ipsec connections. This command will clear all installed SAs (Phase2) and remove all entries from remote-peers menu (Phase1).
+
|type=claim {{!}} exact {{!}} obey {{!}} strict
 +
|default=obey
 +
|desc=Phase 2 lifetime check logic:
 +
* <var>claim</var> - take shortest of proposed and configured lifetimes and notify initiator about it
 +
* <var>exact</var> -  require lifetimes to be the same
 +
* <var>obey</var> -  accept whatever is sent by an initiator
 +
* <var>strict</var> -  if proposed lifetime is longer than the default then reject proposal otherwise accept proposed lifetime
 +
}}
 +
 
 +
==Active Peers==
 +
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec active-peers</code></p>
  
Usage:
 
<pre>
 
/ip ipsec remote-peers kill-connections
 
</pre>
 
  
==Statistics==
+
This menu provides various statistics about remote peers that currently have established phase 1 connection.
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec statistics</code></p>
 
  
  
This menu shows various ipsec statistics
+
'''Read only properties'''
  
 
{{Mr-arg-table-h
 
{{Mr-arg-table-h
Line 1,198: Line 1,262:
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-errors
+
|arg=dynamic-address
|type=integer
+
|type=ip/ipv6 address
|desc=All inbound errors that are not matched by other counters.
+
|desc=Dynamically assigned IP address by [[#Mode_configs | mode config]]
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-buffer-errors
+
|arg=last-seen
|type=integer
+
|type=time
|desc=No free buffer.
+
|desc=Duration since last message received by this peer.
 
}}
 
}}
 
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-header-errors
+
|arg=local-address
|type=integer
+
|type=ip/ipv6 address
|desc=Header error
+
|desc=Local address on the router used by this peer.
 
}}
 
}}
 
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-no-states
+
|arg=natt-peer
|type=integer
+
|type=yes {{!}} no
|desc=No state is found i.e. Either inbound SPI, address, or IPsec protocol at SA is wrong
+
|desc=Whether NAT-T is used for this peer.
 
}}
 
}}
 
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-state-protocol-errors
+
|arg=ph2-total
 
|type=integer
 
|type=integer
|desc=Transformation protocol specific error, for example SA key is wrong or hardware accelerator is unable to handle amount of packets.
+
|desc=Total amount of active IPsec security associations.
 
}}
 
}}
 
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-state-mode-errors
+
|arg=remote-address
|type=integer
+
|type=ip/ipv6 address
|desc=Transformation mode specific error
+
|desc=Remote peer's ip/ipv6 address.
 
}}
 
}}
 
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-state-sequence-errors
+
|arg=responder
|type=integer
+
|type=yes {{!}} no
|desc=Sequence number is out of window
+
|desc=Whether the connection is initiated by remote peer.
 
}}
 
}}
 
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-state-expired
+
|arg=rx-bytes
 
|type=integer
 
|type=integer
|desc=State is expired
+
|desc=Total amount of bytes received from this peer.
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-state-mismatches
+
|arg=rx-packets
 
|type=integer
 
|type=integer
|desc=State has mismatched option, for example UDP encapsulation type is mismatched.  
+
|desc=Total amount of packets received from this peer.
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-state-invalid
+
|arg=side
|type=integer
+
|type=initiator {{!}} responder
|desc=State is invalid
+
|desc=Shows which side initiated the Phase1 negotiation.
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-template-mismatches
+
|arg=state
|type=integer
+
|type=string
|desc=No matching template for states, e.g. Inbound SAs are correct but SP rule is wrong. Possible cause is mismatched sa-source or sa-destination address.
+
|desc=State of phase 1 negotiation with the peer. For example when phase1 and phase 2 are negotiated it will show state "established".
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-no-policies
+
|arg=tx-bytes
 
|type=integer
 
|type=integer
|desc=No policy is found for states, e.g. Inbound SAs are correct but no SP is found
+
|desc=Total amount of bytes transmitted to this peer.
 
}}
 
}}
  
 
{{Mr-arg-ro-table
 
{{Mr-arg-ro-table
|arg=in-policy-blocked
+
|arg=tx-packets
 
|type=integer
 
|type=integer
|desc=Policy discards
+
|desc=Total amount of packets transmitted to this peer.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-ro-table-end
|arg=in-policy-errors
+
|arg=uptime
|type=integer
+
|type=time
|desc=Policy errors
+
|desc=How long peers are in established state.
 
}}
 
}}
  
{{Mr-arg-ro-table
 
|arg=out-errors
 
|type=integer
 
|desc=All outbound errors that are not matched by other counters
 
}}
 
  
{{Mr-arg-ro-table
+
'''Commands'''
|arg=out-bundle-errors
+
 
|type=integer
+
{{Mr-arg-table-h
|desc=Bundle generation error
+
|prop=Property
 +
|desc=Description
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-ro-table-end
|arg=out-bundle-check-errors
+
|arg=kill-connections
|type=integer
+
|type=
|desc=Bundle check error
+
|desc=Manually disconnects all remote peers.
 
}}
 
}}
  
{{Mr-arg-ro-table
+
==Mode configs==
|arg=out-no-states
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec mode-config</code></p>
|type=integer
 
|desc=No state is found
 
}}
 
  
{{Mr-arg-ro-table
 
|arg=out-state-protocol-errors
 
|type=integer
 
|desc=Transformation protocol specific error
 
}}
 
  
{{Mr-arg-ro-table
+
ISAKMP and IKEv2 configuration attributes are configured in this menu.
|arg=out-state-mode-errors
 
|type=integer
 
|desc=Transformation mode specific error
 
}}
 
  
{{Mr-arg-ro-table
 
|arg=out-state-sequence-errors
 
|type=integer
 
|desc=Sequence errors, for example Sequence number overflow
 
}}
 
  
{{Mr-arg-ro-table
+
'''Properties'''
|arg=out-state-expired
 
|type=integer
 
|desc=State is expired
 
}}
 
  
{{Mr-arg-ro-table
+
{{Mr-arg-table-h
|arg=out-policy-blocked
+
|prop=Property
|type=integer
+
|desc=Description
|desc=Policy discards
 
 
}}
 
}}
  
{{Mr-arg-ro-table
+
{{Mr-arg-table
|arg=out-policy-dead
+
|arg=address-pool
|type=integer
+
|type=none {{!}} string
|desc=Policy is dead
+
|default=
 +
|desc=Name of the address pool from which responder will try to assign address if mode-config is enabled.
 
}}
 
}}
  
{{Mr-arg-ro-table-end
+
{{Mr-arg-table
|arg=out-policy-errors
+
|arg=address-prefix-length
|type=integer
+
|type=integer [1..32]
|desc=Policy error
+
|default=
 +
|desc=Prefix length (netmask) of assigned address from the pool.
 
}}
 
}}
  
==Application Examples==
+
{{Mr-arg-table
 +
|arg=comment
 +
|type=string
 +
|default=
 +
|desc=
 +
}}
  
===Simple Mutual PSK XAuth Config===
+
{{Mr-arg-table
 +
|arg=name
 +
|type=string
 +
|default=
 +
|desc=
 +
}}
  
Server side config:
+
{{Mr-arg-table
 
+
|arg=responder
<pre>
+
|type=yes {{!}} no
/ip ipsec peer
+
|default=no
add address=2.2.2.1 auth-method=pre-shared-key-xauth secret="123" passive=yes
+
|desc=Specifies whether the configuration will work as an initiator (client) or responder (server). Initiator will request for mode-config parameters from responder.
 +
}}
  
/ip ipsec user
+
{{Mr-arg-table
add name=test password=345
+
|arg=split-include
</pre>
+
|type=list of IP prefix
 +
|default=
 +
|desc=List of subnets in CIDR format, which to tunnel. Subnets will be sent to the peer using CISCO UNITY extension, remote peer will create specific dynamic policies.
 +
}}
  
Client side config:
+
{{Mr-arg-table
 +
|arg=src-address-list
 +
|type=address list
 +
|default=
 +
|desc=Specifying an address list will generate dynamic source NAT rules. This parameter is only available with <var>responder=no</var>. [[#RoadWarrior_client_with_NAT | RoadWarrior client with NAT]]
 +
}}
  
<pre>
+
{{Mr-arg-table
/ip ipsec peer
+
|arg=static-dns
add address=2.2.2.2 auth-method=pre-shared-key-xauth secret="123" \
+
|type=list of IP
  xauth-login=test xauth-password=345
+
|default=
</pre>
+
|desc=Manually specified DNS server's IP address to be sent to the client.
 +
}}
  
 
+
{{Mr-arg-table-end
{{Note | On server side it is mandatory to set <var>passive</var> to '''yes''' when XAuth is used. }}
+
|arg=system-dns
 +
|type=yes {{!}} no
 +
|default=
 +
|desc=When this option is enabled DNS addresses will be taken from <code>/ip dns</code>.
 +
}}
  
  
===Road Warrior setup with Mode Conf===
+
'''Read only properties'''
  
 +
{{Mr-arg-table-h
 +
|prop=Property
 +
|desc=Description
 +
}}
  
Consider setup where worker need to access other co-workers (workstations) and local office server remotely.
+
{{Mr-arg-ro-table-end
Office has two subnets:
+
|arg=default
* 192.168.55.0/24 for workstations
+
|type=yes {{!}} no
* 192.168.66.0/24 network that must not be reachable by RoadWarrior clients
+
|default=
* 10.5.8.0/24 for servers
+
|desc=Whether this is a default system entry.
 +
}}
  
And access to those networks should be secure.
+
{{ Note | Not all IKE implementations support multiple split networks provided by split-include option. }}
  
[[file:ipsec-road-warrior.png]]
+
{{ Note | If RouterOS client is initiator, it will always send CISCO UNITY extension, and RouterOS supports only split-include from this extension.}}
  
Typically in RoadWarrior setups as this it is impossible to know from which address user will connect, so we need to set up <var>generate-policy</var> parameter on the server side. However this leads to other problems, client can generate any policy and access any network in the office. Even set 0.0.0.0/0 and deny internet access to office workers.
+
{{ Note | It is not possible to use system-dns and static-dns at the same time.}}
  
'''Mode Conf''', '''policy group''' and '''policy templates''' will allow us to overcome these problems.
+
==Installed SAs==
 +
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec installed-sa</code></p>
  
  
====IPsec Server Config====
+
This menu provides information about installed security associations including the keys.
  
At first we need a pool from which RoadWarrior will will get an address. Typically in office you set up DHCP server for local workstations, the same DHCP pool can be used.
 
<pre>
 
/ip pool
 
add name=ipsec-RW ranges=192.168.77.2-192.168.77.254
 
</pre>
 
  
Next we need to set up what settings to send to the client using Mode Conf. 
+
'''Read only properties'''
<pre>
 
/ip ipsec mode-config
 
add address-pool=ipsec-RW name=RW-cfg split-include=\
 
    10.5.8.0/24,192.168.55.0/24
 
</pre>
 
As you can see we specified from which pool to give out address and two allowed subnets.
 
  
 +
{{Mr-arg-table-h
 +
|prop=Property
 +
|desc=Description
 +
}}
  
Now to allow only specific source/destination address in generated policies we will use policy group and create policy templates:
+
{{Mr-arg-ro-table
<pre>
+
|arg=AH
/ip ipsec policy group
+
|type=yes {{!}} no
add name=RoadWarrior
+
|desc=Whether AH protocol is used by this SA.
 +
}}
  
/ip ipsec policy
+
{{Mr-arg-ro-table
add dst-address=192.168.77.0/24 group=RoadWarrior src-address=10.5.8.0/24 \
+
|arg=ESP
    template=yes
+
|type=yes {{!}} no
add dst-address=192.168.77.0/24 group=RoadWarrior src-address=192.168.55.0/24 \
+
|desc=Whether ESP protocol is used by this SA.
    template=yes
+
}}
</pre>
 
  
 +
{{Mr-arg-ro-table
 +
|arg=add-lifetime
 +
|type=time/time
 +
|desc=Added lifetime for the SA in format soft/hard:
 +
* soft - time period after which ike will try to establish new SA;
 +
* hard - time period after which SA is deleted.
 +
}}
  
Now we just add xauth users and peer with enabled Mode Conf and policy group.
+
{{Mr-arg-ro-table
<pre>
+
|arg=addtime
/ip ipsec user
+
|type=time
add name=user1 password=123
+
|desc=Date and time when this SA was added.
add name=user2 password=234
+
}}
  
/ip ipsec peer
+
{{Mr-arg-ro-table
add auth-method=pre-shared-key-xauth generate-policy=port-strict mode-config=RW-cfg \
+
|arg=auth-algorithm
    policy-template-group=RoadWarrior secret=123 passive=yes
+
|type=md5 {{!}} null {{!}} sha1 {{!}} ...
 +
|desc=Currently used authentication algorithm.
 +
}}
  
</pre>
+
{{Mr-arg-ro-table
 +
|arg=auth-key
 +
|type=string
 +
|desc=Used authentication key.
 +
}}
  
==== Apple iOS (iPhone/iPad) Client ====
+
{{Mr-arg-ro-table
 
+
|arg=current-bytes
For iOS devices to be able to connect, '''proposal''' changes are needed:
+
|type=64-bit integer
 +
|desc=Number of bytes seen by this SA.
 +
}}
  
* does not work with 3des encryption algorithm, '''aes-128/256''' works
+
{{Mr-arg-ro-table
* auth algorithm must be '''sha1'''
+
|arg=dst-address
* PFS group must be '''none'''
+
|type=IP
* lifetime must be '''8 hours'''
+
|desc=Destination address of this SA.
 +
}}
  
Example of valid proposal configuration for iOS devices:
+
{{Mr-arg-ro-table
<pre>
+
|arg=enc-algorithm
/ip ipsec proposal
+
|type=des {{!}} 3des {{!}} aes-cbc {{!}} ...
set default enc-algorithms=aes-128-cbc,aes-256-cbc lifetime=8h \
+
|desc=Currently used encryption algorithm.
    pfs-group=none
+
}}
</pre>
 
  
{{ Note | Iphone does not work with split-include 0.0.0.0/0. If you set 0.0.0.0/0 for older clients traffic will not be sent over the tunnel, for newer ios clients tunnel will not be established.}}
+
{{Mr-arg-ro-table
 +
|arg=enc-key
 +
|type=string
 +
|desc=Used encryption key.
 +
}}
  
==== Android Client Notes ====
+
{{Mr-arg-ro-table
 +
|arg=enc-key-size
 +
|type=number
 +
|desc=Used encryption key length.
 +
}}
  
Android devices are trying to add policy with destination 0.0.0.0/0, so you have to make sure that correct policy template is added.
+
{{Mr-arg-ro-table
 +
|arg=expires-in
 +
|type=yes {{!}} no
 +
|desc=Time left until rekeying.
 +
}}
  
In our case we need to add:
+
{{Mr-arg-ro-table
<pre>
+
|arg=hw-aead
/ip ipsec policy
+
|type=yes {{!}} no
add group=RoadWarrior dst-address=192.168.77.0/24 src-address=0.0.0.0/0 template=yes
+
|desc=Whether this SA is [[#Hardware_acceleration | hardware accelerated]].
</pre>
+
}}
  
====RouterOS Client Config====
+
{{Mr-arg-ro-table
 +
|arg=replay
 +
|type=integer
 +
|desc=Size of replay window in bytes.
 +
}}
  
<pre>
+
{{Mr-arg-ro-table
/ip ipsec peer
+
|arg=spi
add address=2.2.2.2 auth-method=pre-shared-key-xauth generate-policy=port-strict secret=123 \
+
|type=string
    xauth-login=user1 xauth-password=123 mode-config=request-only
+
|desc=Security Parameter Index identification tag
</pre>
+
}}
  
====Shrew Client Config====
+
{{Mr-arg-ro-table
 +
|arg=src-address
 +
|type=IP
 +
|desc=Source address of this SA.
 +
}}
  
<pre>
+
{{Mr-arg-ro-table-end
n:version:2
+
|arg=state
n:network-ike-port:500
+
|type=string
n:network-mtu-size:1380
+
|desc=Shows the current state of the SA ("mature", "dying" etc)
n:network-natt-port:4500
+
}}
n:network-natt-rate:15
+
 
n:network-frag-size:540
+
 
n:network-dpd-enable:0
+
'''Commands'''
n:client-banner-enable:0
+
 
n:network-notify-enable:0
+
{{Mr-arg-table-h
n:client-wins-used:0
+
|prop=Property
n:client-wins-auto:1
+
|desc=Description
n:client-dns-used:1
+
}}
n:client-dns-auto:0
+
 
n:client-splitdns-used:1
+
{{Mr-arg-ro-table-end
n:client-splitdns-auto:0
+
|arg=flush
n:phase1-dhgroup:2
+
|type=
n:phase1-life-secs:86400
+
|desc=Manually removes all installed security associations.
n:phase1-life-kbytes:0
+
}}
n:vendor-chkpt-enable:0
+
 
n:phase2-life-secs:300
+
==Keys==
n:phase2-life-kbytes:0
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec key</code></p>
n:policy-nailed:1
+
 
n:policy-list-auto:1
+
 
n:client-addr-auto:1
+
This menu lists all imported public andprivate keys, that can be used for peer authentication. Menu has several commands to work with keys.
s:network-host:2.2.2.2
+
 
s:client-auto-mode:pull
+
 
s:client-iface:virtual
+
'''Properties'''
s:network-natt-mode:disable
+
 
s:network-frag-mode:disable
+
{{Mr-arg-table-h
s:auth-method:mutual-psk-xauth
+
|prop=Property
s:ident-client-type:address
+
|desc=Description
s:ident-server-type:address
+
}}
b:auth-mutual-psk:MTIz
+
 
s:phase1-exchange:main
+
{{Mr-arg-table-end
s:phase1-cipher:3des
+
|arg=name
s:phase1-hash:md5
+
|type=string
s:phase2-transform:esp-3des
+
|default=
s:phase2-hmac:sha1
+
|desc=
s:ipcomp-transform:disabled
+
}}
n:phase2-pfsgroup:2
 
s:policy-level:require
 
  
</pre>
 
  
===Road Warrior setup Ikev2 RSA auth===
+
'''Read only properties'''
Consider the same setup scenario as in [[#Road_Warrior_setup_with_Mode_Conf | Road Warrior setup with Mode Conf]] example.
 
====Ikev2 Server Setup====
 
  
Before we start to configure ipsec, we will need certificates. Some certificate requirements should be met to connect various devices to our server:
+
{{Mr-arg-table-h
* Common name should contain IP or DNS name of the server (required by Windows)
+
|prop=Property
* Subject Alt name should have IP or DNS of the server (required for other clients, like strongSwan client on Android)
+
|desc=Description
* EKU tls-server and tls-client is required for Windows.
+
}}
  
Considering all requirements above, lets make server and client certificates:
+
{{Mr-arg-ro-table
<pre>
+
|arg=key-size
/certificate
+
|type=1024 {{!}} 2048 {{!}} 4096
add common-name=ca name=ca
+
|desc=Size of this key.
sign ca ca-crl-host=2.2.2.2
+
}}
add common-name=2.2.2.2 subject-alt-name=IP:2.2.2.2 key-usage=tls-server name=server1
 
sign server1 ca=ca
 
add common-name=client1 key-usage=tls-client name=client1
 
sign client1 ca=ca
 
add common-name=client2 key-usage=tls-client name=client2
 
</pre>
 
  
 +
{{Mr-arg-ro-table
 +
|arg=private-key
 +
|type=yes {{!}} no
 +
|desc=Whether this is a private key.
 +
}}
  
Now that we have certificates, server can be configured. Note that windows client requires modeconf, so we will use it to give out IP addresses from pool and send DNS, we also need to modify default template a little, to allow policies only from specific source addresses and generate unique level (required by multiple clients behind the same public IP):
+
{{Mr-arg-ro-table-end
<pre>
+
|arg=rsa
/ip pool add name=rw-pool ranges=192.168.77.2-192.168.77.254
+
|type=yes {{!}} no
/ip ipsec policy
+
|desc=Whether this is a RSA key.
set 0 level=unique dst-address=192.168.77.0/24
+
}}
/ip ipsec mode-conf
 
add name=cfg1 system-dns=yes address-pool=rw-pool address-prefix=32
 
/ip ipsec peer
 
add auth-method=rsa-signature certificate=server1 generate-policy=port-strict \
 
  mode-config=cfg1 passive=yes remote-certificate=none exchange-mode=ike2
 
</pre>
 
  
{{Note | Windows uses point-to-point links so specifying any prefix other than 32 in mode-config settings will do nothing. Split include subnets are ignored as well}}
 
  
{{Note | Currently RouterOS does not support any of EAP authentication methods}}
+
'''Commands'''
  
==== RouterOS Client Config ====
+
{{Mr-arg-table-h
 +
|prop=Property
 +
|desc=Description
 +
}}
  
First step is to export client certificate and key from the server:
+
{{Mr-arg-ro-table
<pre>
+
|arg=export-pub-key
/certificate export-certificate ca
+
|type=file-name; key
/certificate export-certificate client1 export-passphrase=1234567890
+
|desc=Export public key to file from one of existing private keys.
</pre>
+
}}
  
Upload exported ca.crt, client1.crt and client1.key files to client's device and import with <code>/certificate import</code> command.
+
{{Mr-arg-ro-table
When it is done set up the client
+
|arg=generate-key
<pre>
+
|type=key-size; name
/ip ipsec peer add address=2.2.2.2 auth-method=rsa-signature certificate=client1 \
+
|desc=Generate private key. Takes two parameters, name of newly generated key and key size 1024,2048 and 4096.
  mode-config=request-only exchange-mode=ike2 generate-policy=port-strict
+
}}
</pre>
 
  
==== Windows Client Config ====
+
{{Mr-arg-ro-table-end
 +
|arg=import
 +
|type=file-name; name
 +
|desc=Import key from file.
 +
}}
  
Windows client does not allow to import certificate and key separately. So we must use external tool (for example, OpenSSL) to convert .crt and .key files to pkcs12 format.
+
==Settings==
<pre>
+
<p id="shbox"><b>Sub-menu:</b> <code>/ip ipsec settings</code></p>
openssl pkcs12 -export -out cl1.pfx -inkey cert_export_client1.key -in cert_export_client1.crt -certfile cert_export_ca.crt
 
</pre>
 
  
To import certificates, open Microsoft Management Console (mmc) Press Ctrl+M and add "Certificates" from the list and choose "Local Computer".
 
  
[[file:snap-in.png]]
+
{{Mr-arg-table-h
 +
|prop=Property
 +
|desc=Description
 +
}}
  
Now Right Click on "Personal" folder pick "All Tasks"->"Import...". Select cl1.pfx file.
+
{{Mr-arg-table
 +
|arg=accounting
 +
|type=yes {{!}} no
 +
|default=
 +
|desc=Whether to send RADIUS accounting requests to RADIUS server. Applicable if EAP Radius (<var>auth-method=eap-radius</var>) or pre-shared key with XAuth authentication method (<var>auth-method=pre-shared-key-xauth</var>) is used.
 +
}}
  
[[file:cert-import.png]]
+
{{Mr-arg-table
 +
|arg=interim-update
 +
|type=time
 +
|default=
 +
|desc=Interval between each consecutive RADIUS accounting Interim update. Accounting must be enabled.
 +
}}
  
CA and client certificate should appear in "Personal"-> "Certificates" folder.
+
{{Mr-arg-table-end
CA certificate need to be moved to Trusted Root list. Simply drag and drop CA to "Trusted Root Certificates" folder. Only client certificate should stay in "Personal".
+
|arg=xauth-use-radius
 +
|type=yes {{!}} no
 +
|default=
 +
|desc=Whether to use [[Manual:RADIUS_Client | Radius client]] for XAuth users or not.
 +
}}
  
[[file:mmc-personal.png]]
+
==Application Guides==
  
Now you are ready to set up the client.
+
===RoadWarrior client with NAT===
After adding VPN tunnel choose VPN type IKEv2 and "Use machine certificates"
 
  
[[file:win-ike2.png]]
+
Consider setup as illustrated below. RouterOS acts as a RoadWarrior client connected to Office allowing access to its internal resources.
  
==== Android Client Notes ====
+
[[file:Ipsec-road-warrior-client.png]]
  
Native Android client does not support ikev2 at the moment. StrongSwan client from Play Store can be used to connect to ikev2 server.
+
Tunnel is established, local mode-config IP address is received and a set of dynamic policies are generated.
StrongSwan client the same as windows accept certificates and keys in pkcs12 format. So external tool is needed to convert exported .crt and .key files to .pfx and then import .pfx file.
 
  
After its imported you will see CA and Client cert in user certificates:
+
<pre>
 +
[admin@pair_r1] > ip ipsec policy print
 +
Flags: T - template, X - disabled, D - dynamic, I - invalid, A - active, * - default
 +
0 T * group=default src-address=::/0 dst-address=::/0 protocol=all proposal=default template=yes
  
[[file:android-cert-import.png | 300px]]
+
1  DA  src-address=192.168.77.254/32 src-port=any dst-address=10.5.8.0/24 dst-port=any protocol=all
 +
      action=encrypt level=unique ipsec-protocols=esp tunnel=yes sa-src-address=10.155.107.8
 +
      sa-dst-address=10.155.107.9 proposal=default ph2-count=1
  
 +
2  DA  src-address=192.168.77.254/32 src-port=any dst-address=192.168.55.0/24 dst-port=any protocol=all
 +
      action=encrypt level=unique ipsec-protocols=esp tunnel=yes sa-src-address=10.155.107.8
 +
      sa-dst-address=10.155.107.9 proposal=default ph2-count=1
 +
</pre>
  
Now you can pick them in profile configuration.
+
Currently only packets with source address of 192.168.77.254/32 will match the IPsec policies. For local network to be able to reach remote subnets, it is necessary to change the source address of local hosts to the dynamically assigned mode config IP address. It is possible to generate source NAT rules dynamically. This can be done by creating a new address list which contains of all local networks that NAT rule should be applied. In our case, it is 192.168.88.0/24.
  
[[file:android-cl-cert.png | 300px]]
+
<pre>
 +
/ip firewall address-list add address=192.168.88.0/24 list=local-RW
 +
</pre>
  
Ca certificate is selected automatically as shown in screenshot below, but if for some reason you need to specify exact CA certificate, then unselect "Select automatically" and pick imported CA from the list.
+
By specifying the address list under mode-config initiator configuration, a set of source NAT rules will be dynamically generated.
  
[[file:android-ca-cert.png | 300px]]
+
<pre>
 +
/ip ipsec mode-config set [ find name="request-only" ] src-address-list=local-RW
 +
</pre>
  
When connecting Android StrongSwan clients, make sure that on RouterOS proposal settings DH group is disabled, otherwise phase2 will fail.
+
When the IPsec tunnel is established, we can see the dynamically created source NAT rules for each network. Now every host in 192.168.88.0/24 is able to access Office's internal resources.
  
==== iOS client configuration ====
+
<pre>
 +
[admin@pair_r1] > ip firewall nat print
 +
Flags: X - disabled, I - invalid, D - dynamic
 +
0  D ;;; ipsec mode-config
 +
      chain=srcnat action=src-nat to-addresses=192.168.77.254 dst-address=192.168.55.0/24 src-address-list=local-RW
 +
 
 +
1  D ;;; ipsec mode-config
 +
      chain=srcnat action=src-nat to-addresses=192.168.77.254 dst-address=10.5.8.0/24 src-address-list=local-RW
 +
</pre>
 +
 
 +
===Simple mutual PSK XAuth configuration===
  
Generate a new certificate for the client and sign it with previously created CA.
+
Server side configuration:
  
 
<pre>
 
<pre>
/certificate
+
/ip ipsec peer
add common-name=iOS_client name=iOS_client
+
add address=2.2.2.1 auth-method=pre-shared-key-xauth secret="123" passive=yes
sign iOS_client ca=ca
+
 
 +
/ip ipsec user
 +
add name=test password=345
 
</pre>
 
</pre>
  
When installing certificates, check which formats iOS supports, client certificate can not be imported from CRT and KEY files, but you can use PKCS12 format. Typically PKCS12 bundle contains also CA certificate, but iOS does not install this CA, so self-signed CA certificate must be installed separately using PEM format.
+
Client side configuration:
  
 
<pre>
 
<pre>
/certificate
+
/ip ipsec peer
export-certificate ca type=pem
+
add address=2.2.2.2 auth-method=pre-shared-key-xauth secret="123" \
export-certificate iOS_client type=pkcs12 export-passphrase=1234567890
+
  xauth-login=test xauth-password=345
 
</pre>
 
</pre>
  
Two files are now located in the routers Files section: <b>cert_export_ca.crt</b> and <b>cert_export_iOS_client.p12</b>. Download and open these files on the iOS device and install both certificates by following the instructions. It is necessary to mark the self-signed CA certificate as trusted on the iOS device. This can be done in Settings -> General -> About -> Certificate Trust Settings menu. When it is done, check whether both certificates are marked as "verified" under Settings -> General -> Profiles menu.
 
  
[[File:Ikev2_cert_ios.PNG]]
+
{{Note | On server side it is mandatory to set <var>passive</var> to '''yes''' when XAuth is used. }}
  
 +
===Allow only IPsec encapsulated traffic===
  
You can now proceed to Settings -> General -> VPN menu and add a new configuration. Remote ID must be set equal to common-name or subjAltName of server's certificate. Local ID can be left blank.
+
There are some scenarios where for security reasons you would like to drop access from/to specific networks if incoming/outgoing packets are not encrypted. For example, if we have L2TP/IPsec setup we would want to drop non encrypted L2TP connection attempts.
  
[[File:Ikev2_conf_ios.PNG]]
+
There are several ways how to achieve this:
 +
* Using IPsec policy matcher in firewall;
 +
* Using generic IPsec policy with <var>action</var> set to '''drop''' and lower priority (can be used in Road Warrior setups where dynamic policies are generated);
 +
* By setting DSCP or priority in mangle and matching the same values in firewall after decapsulation.
  
 +
====IPsec policy matcher====
  
Currently iOS is compatible with the following Phase 1 (Peer) and Phase 2 (Proposal) proposal sets:
+
Lets set up IPsec policy matcher to accept all packets that matched any of IPsec policies and drop the rest:
  
<table class="styled_table" style="width:50%">
+
<pre>
<tr>
+
add chain=input comment="ipsec policy matcher" in-interface=WAN \
<th colspan=3>Phase 1</th>
+
    ipsec-policy=in,ipsec
</tr>
+
add action=drop chain=input comment="drop all" in-interface=WAN log=yes
<tr>
+
</pre>
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>DH Group</th>
+
 
</tr>
+
IPsec policy matcher takes two parameters '''direction,policy'''. We used incoming direction and IPsec policy. IPsec policy option allows us to inspect packets after decapsulation, so for example if we want to allow only gre encapsulated packet from specific source address and drop the rest we could set up following rules:
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp2048</td></tr>
 
<tr><td>SHA256</td><td>AES-256-CBC</td><td>ecp256</td></tr>
 
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp1536</td></tr>
 
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp1536</td></tr>
 
<tr><td>SHA1</td><td>AES-128-CBC</td><td>modp1024</td></tr>
 
<tr><td>SHA1</td><td>3DES</td><td>modp1024</td></tr>
 
</table>
 
  
 +
<pre>
 +
add chain=input comment="ipsec policy matcher" in-interface=WAN \
 +
    ipsec-policy=in,ipsec protocol=gre src=address=192.168.33.1
 +
add action=drop chain=input comment="drop all" in-interface=WAN log=yes
 +
</pre>
  
<table class="styled_table" style="width:50%">
+
For L2TP rule set would be:
<tr>
 
<th colspan=3>Phase 2</th>
 
</tr>
 
<tr>
 
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>PFS Group</th>
 
</tr>
 
<tr><td>SHA256</td><td>AES-256-CBC</td><td>none</td></tr>
 
<tr><td>SHA1</td><td>AES-128-CBC</td><td>none</td></tr>
 
<tr><td>SHA1</td><td>3DES</td><td>none</td></tr>
 
</table>
 
  
 +
<pre>
 +
add chain=input comment="ipsec policy matcher" in-interface=WAN \
 +
    ipsec-policy=in,ipsec protocol=udp dst-port=1701
 +
add action=drop chain=input protocol=udp dst-port=1701 comment="drop l2tp" in-interface=WAN log=yes
 +
</pre>
  
{{Warning | Phase 2 (/ip ipsec proposal) PFS Group must be set to 'none' for rekeying to work properly.}}
+
====Using generic IPsec policy====
{{Note | If you are connected to the VPN over WiFi, the iOS device can go into sleep mode and disconnect from the network.}}
 
  
===Road Warrior setup Ikev1 RSA Auth===
+
The trick of this method is to add default policy with action drop. Lets assume we are running L2TP/IPsec server on public 1.1.1.1 address and we want to drop all non encrypted L2TP:
 
 
====Creating Certificates====
 
 
 
All certificates can be created on RouterOS server using certificate manager.
 
[[Manual:Create_Certificates#Generate_certificates_on_RouterOS | <code>See example >></code>]]
 
 
 
====Ipsec Server Config====
 
  
 
<pre>
 
<pre>
 
/ip ipsec policy group
 
add name=test
 
 
/ip ipsec peer
 
add auth-method=rsa-signature certificate=server exchange-mode=main \
 
    generate-policy=port-override passive=yes policy-template-group=test remote-certificate=none
 
 
/ip ipsec policy
 
/ip ipsec policy
add dst-address=172.16.1.0/24 group=test src-address=172.16.2.0/24 template=yes
+
add src-address=1.1.1.1 dst-address=0.0.0.0/0 sa-src-address=1.1.1.1 \
 
+
  protocol=udp src-port=1701 tunnel=yes action=discard
 
</pre>
 
</pre>
  
====Ipsec Client Config====
+
Now router will drop any L2TP unencrypted incoming traffic, but after successful L2TP/IPsec connection dynamic policy is created with higher priority than it is on default static rule and packets matching that dynamic rule can be forwarded.
  
====Testing CRL====
+
{{ Note | Policy order is important! For this to work, make sure the static drop policy is below the dynamic policies. Move it below the policy template if necessary. }}
  
Now lets say client2 should not be able to connect anymore. We need to revoke its certificate so that it is excluded from CRL list.
 
 
<pre>
 
<pre>
/certificate
+
[admin@rack2_10g1] /ip ipsec policy> print
issued-revoke client2
+
Flags: T - template, X - disabled, D - dynamic, I - inactive, * - default
</pre>
+
0 T * group=default src-address=::/0 dst-address=::/0 protocol=all
 +
      proposal=default template=yes
  
Notice R flag, which means that certificate is revoked
+
D src-address=1.1.1.1/32 src-port=1701 dst-address=10.5.130.71/32
<pre>
+
      dst-port=any protocol=udp action=encrypt level=require
[admin@pe0] /certificate> print
+
      ipsec-protocols=esp tunnel=no sa-src-address=1.1.1.1
Flags: K - private-key, D - dsa, L - crl, C - smart-card-key,
+
      sa-dst-address=10.5.130.71
A - authority, I - issued, R - revoked, E - expired, T - trusted
+
 
  #        NAME              COMMON-NAME              FINGERPRINT             
+
  2    src-address=1.1.1.1/32 src-port=1701 dst-address=0.0.0.0/0
0 K L A T myCa              myCa                      7fa636e6576495fe78f1a4...
+
      dst-port=any protocol=udp action=discard level=unique
1 K  I T server            server                    cf0650a291bf4685f2fbd3...
+
      ipsec-protocols=esp tunnel=yes sa-src-address=1.1.1.1
2 K  I  client1            client1                  26233de30e89b203b946ab...
+
      sa-dst-address=0.0.0.0 proposal=default manual-sa=none
3 K  R  client2            client2                  cf172b62201befaf8d8966...
 
  
 
</pre>
 
</pre>
  
 +
===Manually specifying local-address parameter under Peer configuration===
 +
 +
====Using different routing table====
  
Now if you kill current connection client2 will no be able to establish phase1.
+
IPsec, as any other service in RouterOS, uses main routing table regardless what <var>local-address</var> parameter is used for Peer configuration. It is necessary to apply routing marks to both IKE and IPSec traffic.
  
===Site to Site IpSec Tunnel===
+
Consider the following example. There are two default routes - one in main routing table and another in routing table "backup". It is necessary to use the backup link for IPsec site to site tunnel.
  
Consider setup as illustrated below
+
<pre>
 +
[admin@pair_r1] > /ip route print detail
 +
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit
 +
0 A S  dst-address=0.0.0.0/0 gateway=10.155.107.1 gateway-status=10.155.107.1 reachable via  ether1 distance=1 scope=30 target-scope=10 routing-mark=backup
  
[[file:site-to-site-ipsec-example.png]]
+
1 A S  dst-address=0.0.0.0/0 gateway=172.22.2.115 gateway-status=172.22.2.115 reachable via  ether2 distance=1 scope=30 target-scope=10
  
Two remote office routers are connected to internet and office workstations behind routers are NATed. Each office has its own local subnet, 10.1.202.0/24 for Office1 and 10.1.101.0/24 for Office2. Both remote offices needs secure tunnel to local networks behind routers.
+
2 ADC  dst-address=10.155.107.0/25 pref-src=10.155.107.8 gateway=ether1 gateway-status=ether1 reachable distance=0 scope=10
  
 +
3 ADC  dst-address=172.22.2.0/24 pref-src=172.22.2.114 gateway=ether2 gateway-status=ether2 reachable distance=0 scope=10
  
====IP Connectivity====
+
4 ADC  dst-address=192.168.1.0/24 pref-src=192.168.1.1 gateway=bridge-local gateway-status=ether2 reachable distance=0 scope=10
  
On both routers ether1 is used as wan port and ether2 is used to connect workstations. Also NAT rules are set tu masquerade local networks.
+
[admin@pair_r1] > /ip firewall nat print 
 +
Flags: X - disabled, I - invalid, D - dynamic
 +
0    chain=srcnat action=masquerade out-interface=ether1 log=no log-prefix=""
  
 +
1    chain=srcnat action=masquerade out-interface=ether2 log=no log-prefix=""
  
Office1 router:
+
</pre>
<pre>
 
/ip address
 
add address=192.168.90.1/24 interface=ether1
 
add address=10.1.202.1/24 interface=ether2
 
  
/ip route
+
IPsec peer and policy configurations are created using the backup link's source address, as well as NAT bypass rule for IPsec tunnel traffic.
add gateway=192.168.90.254
 
  
 +
<pre>
 +
/ip ipsec peer
 +
add address=10.155.130.136/32 local-address=10.155.107.8 secret=test
 +
/ip ipsec policy
 +
add sa-src-address=10.155.107.8 src-address=192.168.1.0/24 dst-address=172.16.0.0/24 sa-dst-address=10.155.130.136 tunnel=yes
 
/ip firewall nat
 
/ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade
+
add action=accept chain=srcnat src-address=192.168.1.0/24 dst-address=172.16.0.0/24 place-before=0
 
</pre>
 
</pre>
  
Office2 router:
+
Currently, we see "phase1 negotiation failed due to time up" errors in the log. It is because IPsec tries to reach the remote peer using the main routing table with incorrect source address. It is necessary to mark UDP/500, UDP/4500 and ipsec-esp packets using Mangle.
 +
 
 
<pre>
 
<pre>
/ip address
+
/ip firewall mangle
add address=192.168.80.1/24 interface=ether1
+
add action=mark-connection chain=output connection-mark=no-mark dst-address=10.155.130.136 dst-port=500,4500 \
add address=10.1.101.1/24 interface=ether2
+
new-connection-mark=ipsec passthrough=yes protocol=udp
 
+
add action=mark-connection chain=output connection-mark=no-mark dst-address=10.155.130.136 new-connection-mark=ipsec \
/ip route
+
passthrough=yes protocol=ipsec-esp
add gateway=192.168.80.254
+
add action=mark-routing chain=output connection-mark=ipsec new-routing-mark=backup passthrough=no
 
 
/ip firewall nat
 
add chain=srcnat out-interface=ether1 action=masquerade
 
 
</pre>
 
</pre>
  
====IpSec Peer's config====
+
====Using same routing table with multiple IP addresses====
  
Next step is to add peer's configuration. We need to specify peers address and port and pre-shared-key. Other parameters are left to default values.
+
Consider the following example. There are multiple IP addresses from the same subnet on the public interface. Masquerade rule is configured on out-interface. It is necessary to use one of the IP addresses explicitly.
  
Office1 router:
 
<pre>
 
/ip ipsec peer
 
add address=192.168.80.1/32 port=500 auth-method=pre-shared-key secret="test"
 
</pre>
 
Office2 router:
 
 
<pre>
 
<pre>
/ip ipsec peer
+
[admin@pair_r1] > /ip address print
add address=192.168.90.1/32 port=500 auth-method=pre-shared-key secret="test"
+
Flags: X - disabled, I - invalid, D - dynamic
</pre>
+
#  ADDRESS            NETWORK        INTERFACE
 +
192.168.1.1/24    192.168.1.0    bridge-local
 +
1  172.22.2.1/24      172.22.2.0      ether1
 +
2  172.22.2.2/24      172.22.2.0      ether1
 +
3  172.22.2.3/24      172.22.2.0      ether1
  
====Policy and proposal====
+
[admin@pair_r1] > /ip route print
 +
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit
 +
#      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 +
1 A S  0.0.0.0/0                          172.22.2.115              1
 +
3 ADC  172.22.2.0/24      172.22.2.1      ether1                    0
 +
4 ADC  192.168.1.0/24    192.168.1.1    bridge-local              0
  
It is important that proposed authentication and encryption algorithms match on both routers. In this example we can use predefined "default" proposal
+
[admin@pair_r1] /ip firewall nat> print
 +
Flags: X - disabled, I - invalid, D - dynamic
 +
0    chain=srcnat action=masquerade out-interface=ether1 log=no log-prefix=""  
  
<pre>
 
[admin@MikroTik] /ip ipsec proposal> print
 
Flags: X - disabled
 
0  name="default" auth-algorithms=sha1 enc-algorithms=3des lifetime=30m
 
    pfs-group=modp1024
 
 
</pre>
 
</pre>
  
As we already have proposal as a next step we need correct IpSec policy. We want to encrypt traffic coming form 10.1.202.0/24 to 10.1.101.0/24 and vice versa.
+
IPsec peer and policy configuration is created using one of the public IP addresses.
  
Office1 router:
 
 
<pre>
 
<pre>
 +
/ip ipsec peer
 +
add address=10.155.130.136/32 local-address=172.22.2.3 secret=test
 
/ip ipsec policy
 
/ip ipsec policy
add src-address=10.1.202.0/24 src-port=any dst-address=10.1.101.0/24 dst-port=any \
+
add sa-src-address=172.22.2.3 src-address=192.168.1.0/24 dst-address=172.16.0.0/24 sa-dst-address=10.155.130.136 tunnel=yes
sa-src-address=192.168.90.1 sa-dst-address=192.168.80.1 \
+
/ip firewall nat
tunnel=yes action=encrypt proposal=default
+
add action=accept chain=srcnat src-address=192.168.1.0/24 dst-address=172.16.0.0/24 place-before=0
 
</pre>
 
</pre>
Office2 router:
+
 
 +
Currently the phase 1 connection uses a different source address than we specified and "phase1 negotiation failed due to time up" errors are shown in the logs. This is because masquerade is changing the source address of the connection to match pref-src address of the connected route. Solution is to exclude connections from the public IP address from being masqueraded.
 +
 
 
<pre>
 
<pre>
/ip ipsec policy
+
/ip firewall nat
add src-address=10.1.101.0/24 src-port=any dst-address=10.1.202.0/24 dst-port=any \
+
add action=accept chain=srcnat protocol=udp src-port=500,4500 place-before=0
sa-src-address=192.168.80.1 sa-dst-address=192.168.90.1 \
 
tunnel=yes action=encrypt proposal=default
 
 
</pre>
 
</pre>
Note that we configured tunnel mode instead of transport, as this is site to site encryption.
 
  
====NAT and Fasttrack Bypass====
+
==Application Examples==
 +
 
 +
===Site to Site IPsec tunnel===
  
At this point if you will try to establish IpSec tunnel it will not work, packets will be rejected. This is because both routers have NAT rules that is changing source address before packet is encrypted. Router is unable to encrypt the packet, because source address do not match address specified in policy configuration. For more information see [[M:Packet_Flow#IPsec_encryption|packet flow ipsec example]].
+
Consider setup as illustrated below. Two remote office routers are connected to internet and office workstations are behind NAT. Each office has its own local subnet, 10.1.202.0/24 for Office1 and 10.1.101.0/24 for Office2. Both remote offices needs secure tunnel to local networks behind routers.
  
 +
[[file:site-to-site-ipsec-example.png]]
  
To fix this we need to set up NAT bypass rule.
+
====Site 1 configuration====
 +
 
 +
Start off by creating new Phase 1 [[#Profiles | profile]] and Phase 2 [[#Proposals | proposal]] entries using stronger or weaker encryption parameters that suits your needs. It is advised to create separate entries for each menu so that they are unique for each [[#Peers | peer]] in case it is necessary to adjust any of the settings in the future. These parameters must match between the sites or else the connection will not establish.
  
Office1 router:
 
 
<pre>
 
<pre>
/ip firewall nat
+
/ip ipsec profile
add chain=srcnat action=accept  place-before=0 \
+
add dh-group=modp2048 enc-algorithm=aes-128 name=ike1-site2
src-address=10.1.202.0/24 dst-address=10.1.101.0/24
+
/ip ipsec proposal
 +
add enc-algorithms=aes-128-cbc name=ike1-site2 pfs-group=modp2048
 +
</pre>
 +
 
 +
Continue by configuring a [[#Peers | peer]]. Specify the <var>address</var> of the remote router. This address should be reachable through UDP/500 and UDP/4500 ports, so make sure appropriate actions are taken regarding the router's firewall. Specify the <var>name</var> for this peer as well as the newly created <var>profile</var>.
 +
 
 +
<pre>
 +
/ip ipsec peer
 +
add address=192.168.80.1/32 name=ike1-site2 profile=ike1-site2
 
</pre>
 
</pre>
Office2 router:
+
 
 +
The next step is to create an [[#Identities | identity]]. For a basic pre-shared key secured tunnel, there is nothing much to set except for a '''strong''' <var>secret</var> and the <var>peer</var> to which this identity applies.
 +
 
 
<pre>
 
<pre>
/ip firewall nat
+
/ip ipsec identity
add chain=srcnat action=accept  place-before=0 \
+
add peer=ike1-site2 secret=thisisnotasecurepsk
src-address=10.1.101.0/24 dst-address=10.1.202.0/24
 
 
</pre>
 
</pre>
  
{{Note | If you previously tried to establish tunnel before NAT bypass rule was added, you have to clear connection table from existing connection or restart the routers }}
+
{{Warning | If security matters, consider using IKEv2 and a different <var>auth-method</var>. }}
  
It is very important that bypass rule is placed at the top of all other NAT rules.
+
Lastly, create a [[#Policies | policy]] which controls the networks/hosts between whom traffic should be encrypted.
  
Another issue is if you have fasttrack enabled, packet bypasses ipsec policies. So we need to add accept rule before fasttrack
 
 
<pre>
 
<pre>
/ip firewall filter
+
/ip ipsec policy
add chain=forward action=accept place-before=1
+
add src-address=10.1.202.0/24 src-port=any dst-address=10.1.101.0/24 dst-port=any \
src-address=10.1.101.0/24 dst-address=10.1.202.0/24 connection-state=established,related
+
tunnel=yes action=encrypt proposal=default peer=ike1-site2
add chain=forward action=accept place-before=1
 
src-address=10.1.202.0/24 dst-address=10.1.101.0/24 connection-state=established,related
 
 
</pre>
 
</pre>
  
However this can add significant load to CPU if there is a fair amount of tunnels and significant traffic on each tunnel.
+
====Site 2 configuration====
  
Solution is to use RAW firewall tables to bypass connection tracking, that way eliminating need of filter rules listed above and reducing load on CPU by approximately 30%.
+
Office 2 configuration is almost identical as Office 1 with proper IP address configuration. Start off by creating new Phase 1 [[#Profiles | profile]] and Phase 2 [[#Proposals | proposal]] entries.
  
 
<pre>
 
<pre>
/ip firewall raw
+
/ip ipsec profile
add action=notrack chain=prerouting src-address=10.1.101.0/24 dst-address=10.1.202.0/24
+
add dh-group=modp2048 enc-algorithm=aes-128 name=ike1-site1
add action=notrack chain=prerouting src-address=10.1.202.0/24 dst-address=10.1.101.0/24
+
/ip ipsec proposal
 +
add enc-algorithms=aes-128-cbc name=ike1-site1 pfs-group=modp2048
 
</pre>
 
</pre>
  
===L2TP/IPSec setup===
+
Next is the [[#Peers | peer]] and [[#Identities | identity]].
  
See [[Manual:Interface/L2TP#Basic_L2TP.2FIpSec_setup | L2TP configuration examples]].
+
<pre>
 +
/ip ipsec peer
 +
add address=192.168.90.1/32 name=ike1-site1 profile=ike1-site1
 +
/ip ipsec identity
 +
add peer=ike1-site1 secret=thisisnotasecurepsk
 +
</pre>
  
===Allow Only Ipsec Encapsulated Traffic===
+
When it is done, create a [[#Policies | policy]]:
  
There are some scenarios where for security reasons you would like to drop access from/to specific networks if incoming/outgoing packets are not encrypted. For example, If we have L2TP/Ipsec setup we would want to drop non encrypted L2TP connection attempts.
 
 
There are several ways how to achieve this:
 
* Using ipsec policy matcher in firewall;
 
* Using generic ipsec policy with action=drop and lower priority (can be used in road warrior setups where dynamic policies are generated);
 
* By setting DSCP or priority in mangle and matching the same values in firewall after decapsulation.
 
 
====Ipsec Policy Matcher====
 
 
Lets set up ipsec policy matcher to accept all packets that matched any of ipsec policies and drop the rest
 
 
<pre>
 
<pre>
add chain=input comment="ipsec policy matcher" in-interface=WAN \
+
/ip ipsec policy
    ipsec-policy=in,ipsec
+
add src-address=10.1.101.0/24 src-port=any dst-address=10.1.202.0/24 dst-port=any \
add action=drop chain=input comment="drop all" in-interface=WAN log=yes
+
tunnel=yes action=encrypt proposal=default peer=ike1-site1
 
</pre>
 
</pre>
  
Ipsec policy matcher takes two parameters direction, policy. We used incoming direction and ipsec policy. Ipsec policy option allows us to inspect packets after decapsulation, so for example if we want to allow only gre encapsulated packet from specific source address and drop the rest we could set up following rules
+
At this point, the tunnel should be established and two IPsec Security Associations should be created on both routers:
  
 
<pre>
 
<pre>
add chain=input comment="ipsec policy matcher" in-interface=WAN \
+
/ip ipsec
    ipsec-policy=in,ipsec protocol=gre src=address=192.168.33.1
+
remote-peers print
add action=drop chain=input comment="drop all" in-interface=WAN log=yes
+
installed-sa print
 
</pre>
 
</pre>
  
 +
====NAT and Fasttrack Bypass====
 +
 +
At this point if you try to send traffic over the IPsec tunnel, it will not work, packets will be lost. This is because both routers have NAT rules (masquerade) that is changing source address before packet is encrypted. Router is unable to encrypt the packet, because source address do not match address specified in policy configuration. For more information see [[M:Packet_Flow#IPsec_encryption | IPsec packet flow example]].
 +
 +
To fix this we need to set up [[M:IP/Firewall/NAT | IP/Firewall/NAT]] bypass rule.
 +
 +
Office 1 router:
  
For L2TP rule set would be:
 
 
<pre>
 
<pre>
add chain=input comment="ipsec policy matcher" in-interface=WAN \
+
/ip firewall nat
    ipsec-policy=in,ipsec protocol=udp dst-port=1701
+
add chain=srcnat action=accept  place-before=0 \
add action=drop chain=input protocol=udp dst-port=1701 comment="drop l2tp" in-interface=WAN log=yes
+
src-address=10.1.202.0/24 dst-address=10.1.101.0/24
 
</pre>
 
</pre>
  
====Using generic Ipsec Policy====
+
Office 2 router:
  
The trick of this method is to add default policy with action drop. Lets assume we are running L2TP/IpSec server 1.1.1.1 with public address and we want to drop all non encrypted L2TP:
+
<pre>
 +
/ip firewall nat
 +
add chain=srcnat action=accept  place-before=0 \
 +
src-address=10.1.101.0/24 dst-address=10.1.202.0/24
 +
</pre>
 +
 
 +
{{Note | If you previously tried to establish an IP connection before NAT bypass rule was added, you have to clear connection table from existing connection or restart both routers. }}
 +
 
 +
It is very important that bypass rule is placed at the top of all other NAT rules.
 +
 
 +
Another issue is if you have [[M:IP/Fasttrack | IP/Fasttrack]] enabled, packet bypasses IPsec policies. So we need to add accept rule before FastTrack.
  
 
<pre>
 
<pre>
/ip ipsec policy
+
/ip firewall filter
add src-address=1.1.1.1 dst-address=0.0.0.0/0 sa-src-address=1.1.1.1 \
+
add chain=forward action=accept place-before=1
  protocol=udp src-port=1701 tunnel=yes action=discard
+
src-address=10.1.101.0/24 dst-address=10.1.202.0/24 connection-state=established,related
 +
add chain=forward action=accept place-before=1
 +
src-address=10.1.202.0/24 dst-address=10.1.101.0/24 connection-state=established,related
 
</pre>
 
</pre>
  
Now router will drop any L2TP unencrypted incoming traffic, but after successful L2TP/Ipsec connection dynamic policy is created with higher priority than it is on default static rule and packets matching that dynamic rule can be forwarded.
+
However, this can add significant load to router's CPU if there is a fair amount of tunnels and significant traffic on each tunnel.
  
{{ Note | Starting from RouterOS 6.40 policy order is important. For this to work, make sure the static drop policy is below the dynamic policies. Move it below the policy template if necessary. }}
+
Solution is to use [[M:IP/Firewall/Raw | IP/Firewall/Raw]] to bypass connection tracking, that way eliminating need of filter rules listed above and reducing load on CPU by approximately 30%.
  
 
<pre>
 
<pre>
[admin@rack2_10g1] /ip ipsec policy> print
+
/ip firewall raw
Flags: T - template, X - disabled, D - dynamic, I - inactive, * - default
+
add action=notrack chain=prerouting src-address=10.1.101.0/24 dst-address=10.1.202.0/24
0 T * group=default src-address=::/0 dst-address=::/0 protocol=all
+
add action=notrack chain=prerouting src-address=10.1.202.0/24 dst-address=10.1.101.0/24
      proposal=default template=yes
+
</pre>
  
1  D  src-address=1.1.1.1/32 src-port=1701 dst-address=10.5.130.71/32
+
===Road Warrior setup using IKEv2 with RSA authentication===
      dst-port=any protocol=udp action=encrypt level=require
 
      ipsec-protocols=esp tunnel=no sa-src-address=1.1.1.1
 
      sa-dst-address=10.5.130.71
 
  
2    src-address=1.1.1.1/32 src-port=1701 dst-address=0.0.0.0/0
+
This example explains how to establish a secure IPsec connection between a device connected to the Internet (road warrior client) and a device running RouterOS acting as a server.
      dst-port=any protocol=udp action=discard level=unique
 
      ipsec-protocols=esp tunnel=yes sa-src-address=1.1.1.1
 
      sa-dst-address=0.0.0.0 proposal=default manual-sa=none
 
  
</pre>
+
[[file:ipsec-road-warrior.png]]
  
===Connecting with Shrew Client and allowing only Encrypted traffic===
 
  
* [[IPSEC_between_Mikrotik_router_and_a_Shrew_client | See example here]]
+
====RouterOS server configuration====
  
 +
Before configuring IPsec, it is required to set up certificates. It is possible to use a separate Certificate Authority for certificate management, however in this example, self signed certificates are generated in RouterOS [[Manual:System/Certificates | System/Certificates]] menu. Some certificate requirements should be met to connect various devices to the server:
 +
* Common name should contain IP or DNS name of the server;
 +
* SAN (subject alternative name) should have IP or DNS of the server;
 +
* EKU (extended key usage) tls-server and tls-client are required.
  
==Troubleshooting/FAQ==
+
Considering all requirements above, generate CA and server certificates:
 +
<pre>
 +
/certificate
 +
add common-name=ca name=ca
 +
sign ca ca-crl-host=2.2.2.2
 +
add common-name=2.2.2.2 subject-alt-name=IP:2.2.2.2 key-usage=tls-server name=server1
 +
sign server1 ca=ca
 +
</pre>
 +
 
 +
Now that valid certificates are created on the router, add new Phase 1 [[#Profiles | profile]] and Phase 2 [[#Proposals | proposal]] entries with <var>pfs-group=none</var>.
  
;Phase 1 Failed to get valid proposal
 
:
 
 
<pre>
 
<pre>
[admin@MikroTik] /log> print
+
/ip ipsec profile
(..)
+
add name=ike2
17:12:32 ipsec,error no suitable proposal found.  
+
/ip ipsec proposal
17:12:32 ipsec,error 10.5.107.112 failed to get valid proposal.  
+
add name=ike2 pfs-group=none
17:12:32 ipsec,error 10.5.107.112 failed to pre-process ph1 packet (side: 1, status 1).  
+
</pre>
17:12:32 ipsec,error 10.5.107.112 phase1 negotiation failed.
+
 
(..)
+
[[#Mode_configs | Mode config]] is used for address distribution from [[Manual:IP/Pools | IP/Pools]].
 +
 
 +
<pre>
 +
/ip pool
 +
add name=ike2-pool ranges=192.168.77.2-192.168.77.254
 +
/ip ipsec mode-config
 +
add address-pool=ike2-pool address-prefix-length=32 name=ike2-conf
 +
</pre>
 +
 
 +
Since that the policy template must be adjusted to allow only specific network [[#Policies | policies]], it is advised to create a separate policy [[#Groups | group]] and template.  
 +
 
 +
<pre>
 +
/ip ipsec policy group
 +
add name=ike2-policies
 +
/ip ipsec policy
 +
add dst-address=192.168.77.0/24 group=ike2-policies proposal=ike2 src-address=0.0.0.0/0 template=yes
 +
</pre>
 +
 
 +
Create a new IPsec [[#Peers | peer]] entry which will listen to all incoming IKEv2 requests.
 +
 
 +
<pre>
 +
/ip ipsec peer
 +
add exchange-mode=ike2 name=ike2 passive=yes profile=ike2
 +
</pre>
 +
 
 +
=====Identity configuration=====
 +
 
 +
[[#Identities | Identity]] menu allows to match specific remote peers and assign different configuration for each one of them. First, create a default identity, that will accept all peers, but will verify the peer's identity with its certificate.
 +
 
 +
<pre>
 +
/ip ipsec identity
 +
add auth-method=digital-signature certificate=server1 generate-policy=port-strict mode-config=ike2-conf peer=ike2 policy-template-group=ike2-policies
 
</pre>
 
</pre>
:Peers are unable to negotiate encryption parameters causing the connection to drop. To solve this issue, enable IPSec debug logs and find out which parameters are proposed by the remote peer and adjust configuration accordingly.
 
<pre>
 
[admin@MikroTik] /system logging> add topics=ipsec,!debug
 
</pre>
 
<pre>
 
[admin@MikroTik] /log> print
 
(..)
 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#1):Peer(prop#1:trns#1) = MD5:SHA
 
17:21:08 ipsec rejected enctype: DB(prop#1:trns#2):Peer(prop#1:trns#1) = 3DES-CBC:AES-CBC
 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#2):Peer(prop#1:trns#1) = MD5:SHA
 
17:21:08 ipsec rejected enctype: DB(prop#1:trns#1):Peer(prop#1:trns#2) = AES-CBC:3DES-CBC
 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#1):Peer(prop#1:trns#2) = MD5:SHA
 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#2):Peer(prop#1:trns#2) = MD5:SHA
 
17:21:08 ipsec,error no suitable proposal found.
 
17:21:08 ipsec,error 10.5.107.112 failed to get valid proposal.
 
17:21:08 ipsec,error 10.5.107.112 failed to pre-process ph1 packet (side: 1, status 1).
 
17:21:08 ipsec,error 10.5.107.112 phase1 negotiation failed.
 
(..)
 
</pre>
 
:In this example, remote end requires SHA1 to be used as hash algorithm, but MD5 is configured on local router. Setting before the column symbol (:) is configured on the local side, parameter after the column symbol (:) is configured on the remote side.
 
 
;"phase1 negotiation failed due to time up" what does it mean?
 
:There are communication problems between the peers. Possible causes include - misconfigured Phase 1 IP addresses; firewall blocking UDP ports 500 and 4500; NAT between peers not properly translating IPsec negotiation packets.
 
  
;Random packet drops or connections over the tunnel is very slow, enabling packet sniffer/torch fixes the problem
+
{{Note | If peer's ID (ID_i) is not matching with the certificate it sends, the identity lookup will fail. See <var>remote-id</var> in [[#Identities | identities]] section. }}
:Problem is that before encapsulation packets are sent to fasttrack/fastpath, thus bypassing ipsec policy.
+
 
:Solution is to exclude traffic that need to be encapsulated/decaplsulated from fasttrack, see configuration example [[#NAT_and_Fasttrack_Bypass | here]].
+
For example, we want to assign different [[#Mode_configs | mode config]] for user "A", who uses certificate "rw-client1" to authenticate itself to the server. First of all, make sure a new mode config is created and ready to be applied for the specific user.
 +
 
 +
<pre>
 +
/ip ipsec mode-config
 +
add address=192.168.66.2 address-prefix-length=32 name=usr_A split-include=192.168.55.0/24 system-dns=no
 +
</pre>
 +
 
 +
It is possible apply this configuration for user "A" by using <var>match-by=certificate</var> parameter and specifying his certificate with <var>remote-certificate</var>.
 +
 
 +
<pre>
 +
/ip ipsec identity
 +
add auth-method=digital-signature certificate=server1 generate-policy=port-strict match-by=certificate mode-config=usr_A peer=ike2 policy-template-group=ike2-policies remote-certificate=rw-client1
 +
</pre>
 +
 
 +
=====Split tunnel configuration=====
 +
 
 +
Split tunneling is a method which allows road warrior clients to only access a specific secured network and at the same time send the rest of the traffic based on their internal routing table (as opposed to sending all traffic over the tunnel). To configure split tunneling, changes to [[#Mode_configs | mode config]] parameters are needed.
 +
 
 +
For example we will allow our road warrior clients to only access 10.5.8.0/24 network.
 +
 
 +
<pre>
 +
/ip ipsec mode-conf
 +
set [find name="rw-conf"] split-include=10.5.8.0/24
 +
</pre>
 +
 
 +
It is also possible to send specific DNS server for the client to use. By default <var>system-dns=yes</var> is used, which sends DNS servers that are configured on the router itself in [[Manual:IP/DNS | IP/DNS]]. We can force the client to use different DNS server by using the <var>static-dns</var> parameter.
 +
 
 +
<pre>
 +
/ip ipsec mode-conf
 +
set [find name="rw-conf"] system-dns=no static-dns=10.5.8.1
 +
</pre>
 +
 
 +
While it is possible to adjust IPsec policy template to only allow road warrior clients to generate [[#Policies | policies]] to network configured by <var>split-include</var> parameter, this can cause compatibility issues with different vendor implementations (see [[#Known_limitations | known limitations]]). Instead of adjusting the policy template, allow access to secured network in [[Manual:IP/Firewall/Filter | IP/Firewall/Filter]] and drop everything else.
 +
 
 +
<pre>
 +
/ip firewall filter
 +
add action=drop chain=forward src-address=192.168.77.0/24 dst-address=!10.5.8.0/24
 +
</pre>
 +
 
 +
{{Warning | Split networking is not a security measure. The client (initiator) can still request a different Phase 2 traffic selector. }}
 +
 
 +
=====Generating client certificates=====
 +
 
 +
To generate a new certificate for the client and sign it with previously created CA.
 +
 
 +
<pre>
 +
/certificate
 +
add common-name=rw-client1 name=rw-client1 key-usage=tls-client
 +
sign rw-client1 ca=ca
 +
</pre>
 +
 
 +
<b>PKCS12 format</b> is accepted by most of client implementations, so when exporting the certificate, make sure PKCS12 is specified.
 +
 
 +
<pre>
 +
/certificate
 +
export-certificate rw-client1 export-passphrase=1234567890 type=pkcs12
 +
</pre>
 +
 
 +
A file named <i>cert_export_rw-client1.p12</i> is now located in the routers [[Manual:System/File | System/File]] section. This file should be securely transported to the client device.
 +
 
 +
Typically PKCS12 bundle contains also CA certificate, but some vendors may not install this CA, so self-signed CA certificate must be exported separately using PEM format.
 +
 
 +
<pre>
 +
/certificate
 +
export-certificate ca type=pem
 +
</pre>
 +
 
 +
A file named <i>cert_export_ca.crt</i> is now located in the routers [[Manual:System/File | System/File]] section. This file should also be securely transported to the client device.
 +
 
 +
<b>PEM</b> is another certificate format for use in client software that do not support PKCS12. Principle is pretty much the same.
 +
 
 +
<pre>
 +
/certificate
 +
export-certificate ca
 +
export-certificate rw-client1 export-passphrase=1234567890
 +
</pre>
 +
 
 +
Three files are now located in the routers Files section: <i>cert_export_ca.crt</i>, <i>cert_export_rw-client1.crt</i> and <i>cert_export_rw-client1.key</i> which should be securely transported to the client device.
 +
 
 +
=====Known limitations=====
 +
 
 +
Here is a list of known limitations by popular client software IKEv2 implementations.
 +
 
 +
* Windows will always ignore networks received by <var>split-include</var> and request policy with destination 0.0.0.0/0 (TSr). When IPsec-SA is generated, Windows requests DHCP option 249 to which RouterOS will respond with configured <var>split-include</var> networks automatically.
 +
 
 +
* Both Apple macOS and iOS will only accept the first <var>split-include</var> network.
 +
 
 +
* Both Apple macOS and iOS will use the DNS servers from <var>system-dns</var> and <var>static-dns</var> parameters only when 0.0.0.0/0 <var>split-include</var> is used.
 +
 
 +
* While some implementations can make use of different PFS group for phase 2, it is advised to use <var>pfs-grou=none</var> under [[#Proposals | proposals]] to avoid any compatibility issues.
 +
 
 +
==== RouterOS client configuration ====
 +
 
 +
Import a PKCS12 format certificate in RouterOS.
 +
 
 +
<pre>
 +
/certificate import file-name=cert_export_RouterOS_client.p12 passphrase=1234567890
 +
</pre>
 +
 
 +
There should now be the self-signed CA certificate and the client certificate in Certificate menu. Find out the name of the client certificate.
 +
 
 +
<pre>
 +
/certificate print
 +
</pre>
 +
 
 +
<b>cert_export_RouterOS_client.p12_0</b> is the client certificate.
 +
 
 +
It is advised to create a separate Phase 1 [[#Profiles | profile]] and Phase 2 [[#Proposals | proposal]] configurations to not interfere with any existing IPsec configuration.
 +
 
 +
<pre>
 +
/ip ipsec profile
 +
add name=ike2-rw
 +
/ip ipsec proposal
 +
add name=ike2-rw pfs-group=none
 +
</pre>
 +
 
 +
While it is possible to use the default [[#Policies | policy]] template for policy generation, it is better to create a new policy [[#Groups | group]] and template to separate this configuration from any other IPsec configuration.
 +
 
 +
<pre>
 +
/ip ipsec policy group
 +
add name=ike2-rw
 +
/ip ipsec policy
 +
add group=ike2-rw proposal=ike2-rw template=yes
 +
</pre>
 +
 
 +
Create a new [[#Mode_configs | mode config]] entry with <var>responder=no</var> that will request configuration parameters from the server.
 +
 
 +
<pre>
 +
/ip ipsec mode-config
 +
add name=ike2-rw responder=no
 +
</pre>
 +
 
 +
Lastly, create [[#Peers | peer]] and [[#Identities | identity]] configurations.
 +
 
 +
<pre>
 +
/ip ipsec peer
 +
add address=2.2.2.2/32 exchange-mode=ike2 name=ike2-rw-client
 +
/ip ipsec identity
 +
add auth-method=digital-signature certificate=cert_export_RouterOS_client.p12_0 generate-policy=port-strict mode-config=ike2-rw peer=ike2-rw-client policy-template-group=ike2-rw
 +
</pre>
 +
 
 +
Verify that the connection is successfully established.
 +
 
 +
<pre>
 +
/ip ipsec
 +
remote-peers print
 +
installed-sa print
 +
</pre>
 +
 
 +
===== Enabling dynamic source NAT rule generation =====
 +
 
 +
If we look at the generated dynamic [[#Policies | policies]], we see that only traffic with a specific (received by [[#Mode_configs | mode config]]) source address will be sent through the tunnel. But a router in most cases will need to route a specific device or network through the tunnel. In such case we can use source NAT to change the source address of packets to match the mode config address. Since the mode config address is dynamic, it is impossible to create static source NAT rule. In RouterOS it is possible to generate dynamic source NAT rules for mode config clients.
 +
 
 +
[[file:Ipsec-road-warrior-client.png]]
 +
 
 +
For example, we have a local network 192.168.88.0/24 behind the router and we want all traffic from this network to be sent over the tunnel. First of all, we have to make a new [[M:IP/Firewall/Address_list | IP/Firewall/Address list]] which consists of our local network.
 +
 
 +
<pre>
 +
/ip firewall address-list
 +
add address=192.168.88.0/24 list=local
 +
</pre>
 +
 
 +
When it is done, we can assign newly created [[M:IP/Firewall/Address_list | IP/Firewall/Address list]] to [[#Mode_configs | mode config]] configuration.
 +
 
 +
<pre>
 +
/ip ipsec mode-config
 +
set [ find name=ike2-rw ] src-address-list=local
 +
</pre>
 +
 
 +
Verify correct source NAT rule is dynamically generated when the tunnel is established.
 +
 
 +
<pre>
 +
[admin@MikroTik] > /ip firewall nat print
 +
Flags: X - disabled, I - invalid, D - dynamic
 +
0  D ;;; ipsec mode-config
 +
      chain=srcnat action=src-nat to-addresses=192.168.77.254 src-address-list=local dst-address-list=!local
 +
</pre>
 +
 
 +
{{Warning | Make sure dynamic [[#Mode_configs | mode config]] address is not a part of local network. }}
 +
 
 +
==== Windows client configuration ====
 +
 
 +
Open PKCS12 format certificate file on the Windows computer. Install the certificate by following the instructions. Make sure you select Local Machine store location.
 +
 
 +
[[File:Ike2v2_cert_win.png | 1300px]]
 +
 
 +
You can now proceed to Network and Internet settings -> VPN and add a new configuration. Fill in the Connection name, Server name or address parameters. Select IKEv2 under VPN type. When it is done, it is necessary to select "Use machine certificates". This can be done in Network and Sharing Center by clicking the Properties menu for the VPN connection. The setting is located under Security tab.
 +
 
 +
[[File:Ike2v2_conf_win.png | 1300px]]
 +
 
 +
Currently Windows 10 is compatible with the following Phase 1 ([[#Profiles | profiles]]) and Phase 2 ([[#Proposals | proposals]]) proposal sets:
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 1</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>DH Group</th>
 +
</tr>
 +
<tr><td>SHA1</td><td>3DES</td><td>modp1024</td></tr>
 +
<tr><td>SHA256</td><td>3DES</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA256</td><td>AES-128-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>AES-192-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA256</td><td>AES-192-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>AES-256-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-GCM</td><td>modp1024</td></tr>
 +
<tr><td>SHA256</td><td>AES-128-GCM</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>AES-256-GCM</td><td>modp1024</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-GCM</td><td>modp1024</td></tr>
 +
</table>
 +
 
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 2</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>PFS Group</th>
 +
</tr>
 +
<tr><td>SHA1</td><td>AES-256-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>3DES</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>DES</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>none</td><td>none</td></tr>
 +
</table>
 +
 
 +
 
 +
==== macOS client configuration ====
 +
 
 +
Open PKCS12 format certificate file on the macOS computer and install the certificate in "System" keychain. It is necessary to mark the CA certificate as trusted manually since it is self-signed. Locate the certificate macOS Keychain Access app under System tab and mark it as Always Trust.
 +
 
 +
[[File:Ikev2_cert_macos.png | 900px]]
 +
 
 +
You can now proceed to System Preferences -> Network and add a new configuration by clicking the + button. Select Interface: VPN, VPN Type: IKEv2 and name your connection. Remote ID must be set equal to common-name or subjAltName of server's certificate. Local ID can be left blank. Under Authentication Settings select None and choose the client certificate. You can now test the connectivity.
 +
 
 +
[[File:Ikev2_conf_macos.png | 900px]]
 +
 
 +
Currently macOS is compatible with the following Phase 1 ([[#Profiles | profiles]]) and Phase 2 ([[#Proposals | proposals]]) proposal sets:
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 1</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>DH Group</th>
 +
</tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp2048</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>ecp256</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp1536</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>3DES</td><td>modp1024</td></tr>
 +
</table>
 +
 
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 2</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>PFS Group</th>
 +
</tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>3DES</td><td>none</td></tr>
 +
</table>
 +
 
 +
 
 +
 
 +
==== iOS client configuration ====
 +
 
 +
Typically PKCS12 bundle contains also CA certificate, but iOS does not install this CA, so self-signed CA certificate must be installed separately using PEM format. Open these files on the iOS device and install both certificates by following the instructions. It is necessary to mark the self-signed CA certificate as trusted on the iOS device. This can be done in Settings -> General -> About -> Certificate Trust Settings menu. When it is done, check whether both certificates are marked as "verified" under Settings -> General -> Profiles menu.
 +
 
 +
[[File:Ikev2_cert_ios.PNG | 900px]]
 +
 
 +
 
 +
You can now proceed to Settings -> General -> VPN menu and add a new configuration. Remote ID must be set equal to common-name or subjAltName of server's certificate. Local ID can be left blank.
 +
 
 +
[[File:Ikev2_conf_ios.PNG | 450px]]
 +
 
 +
 
 +
Currently iOS is compatible with the following Phase 1 ([[#Profiles | profiles]]) and Phase 2 ([[#Proposals | proposals]]) proposal sets:
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 1</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>DH Group</th>
 +
</tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp2048</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>ecp256</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>modp1536</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>modp1024</td></tr>
 +
<tr><td>SHA1</td><td>3DES</td><td>modp1024</td></tr>
 +
</table>
 +
 
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 2</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>PFS Group</th>
 +
</tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>3DES</td><td>none</td></tr>
 +
</table>
 +
 
 +
 
 +
{{Note | If you are connected to the VPN over WiFi, the iOS device can go into sleep mode and disconnect from the network.}}
 +
 
 +
 
 +
==== Android (strongSwan) client configuration ====
 +
 
 +
Currently there is no IKEv2 native support in Android, however it is possible to use strongSwan from Google Play Store which brings IKEv2 to Android. StrongSwan accepts PKCS12 format certificates, so before setting up the VPN connection in strongSwan, make sure you download the PKCS12 bundle to your Android device. When it is done, create a new VPN profile in strongSwan, type in the server IP and choose "IKEv2 Certificate" as VPN Type. When selecting a User certificate, press Install and follow the certificate extract procedure by specifying the PKCS12 bundle. Save the profile and test the connection by pressing on the VPN profile.
 +
 
 +
[[file:Ikev2_conf_android.png | 1080px]]
 +
 
 +
 
 +
It is possible to specify custom encryption settings in strongSwan by ticking the "Show advanced settings" checkbox. Currently strongSwan by default is compatible with the following Phase 1 ([[#Profiles | profiles]]) and Phase 2 ([[#Proposals | proposals]]) proposal sets:
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 1</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>DH Group</th>
 +
</tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>modp2048</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>ecp256</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>ecp384</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>ecp521</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>modp3072</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>modp4096</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>modp6144</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-CBC</td><td>modp8192</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>modp2048</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>ecp256</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>ecp384</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>ecp521</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>modp3072</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>modp4096</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>modp6144</td></tr>
 +
<tr><td>SHA*</td><td>AES-*-GCM</td><td>modp8192</td></tr>
 +
</table>
 +
 
 +
 
 +
<table class="styled_table" style="width:50%">
 +
<tr>
 +
<th colspan=3>Phase 2</th>
 +
</tr>
 +
<tr>
 +
<th>Hash Algorithm</th><th>Encryption Algorithm</th><th>PFS Group</th>
 +
</tr>
 +
<tr><td>none</td><td>AES-256-GCM</td><td>none</td></tr>
 +
<tr><td>none</td><td>AES-128-GCM</td><td>none</td></tr>
 +
<tr><td>SHA256</td><td>AES-256-CBC</td><td>none</td></tr>
 +
<tr><td>SHA512</td><td>AES-256-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>AES-256-CBC</td><td>none</td></tr>
 +
<tr><td>SHA256</td><td>AES-192-CBC</td><td>none</td></tr>
 +
<tr><td>SHA512</td><td>AES-192-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>AES-192-CBC</td><td>none</td></tr>
 +
<tr><td>SHA256</td><td>AES-128-CBC</td><td>none</td></tr>
 +
<tr><td>SHA512</td><td>AES-128-CBC</td><td>none</td></tr>
 +
<tr><td>SHA1</td><td>AES-128-CBC</td><td>none</td></tr>
 +
</table>
 +
 
 +
==== Linux (strongSwan) client configuration ====
 +
 
 +
Download the PKCS12 certificate bundle and move it to /etc/ipsec.d/private directory.
 +
 
 +
Add exported passphrase for the private key to /etc/ipsec.secrets file where "strongSwan_client.p12" is the file name and "1234567890" is the passphrase.
 +
 
 +
<pre>
 +
: P12 strongSwan_client.p12 "1234567890"
 +
</pre>
 +
 
 +
Add a new connection to /etc/ipsec.conf file
 +
 
 +
<pre>
 +
conn "ikev2"
 +
        keyexchange=ikev2
 +
        ike=aes128-sha1-modp2048
 +
        esp=aes128-sha1
 +
        leftsourceip=%modeconfig
 +
        leftcert=strongSwan_client.p12
 +
        leftfirewall=yes
 +
        right=2.2.2.2
 +
        rightid="CN=2.2.2.2"
 +
        rightsubnet=0.0.0.0/0
 +
        auto=add
 +
</pre>
 +
 
 +
You can now restart (or start) the ipsec daemon and initialize the connection
 +
 
 +
<pre>
 +
$ ipsec restart
 +
$ ipsec up ikev2
 +
</pre>
 +
 
 +
===Road Warrior setup with Mode Conf===
 +
 
 +
 
 +
Consider setup where worker need to access other co-workers (workstations) and local office server remotely.
 +
Office has two subnets:
 +
* 192.168.55.0/24 for workstations
 +
* 192.168.66.0/24 network that must not be reachable by RoadWarrior clients
 +
* 10.5.8.0/24 for servers
 +
 
 +
And access to those networks should be secure.
 +
 
 +
[[file:ipsec-road-warrior.png]]
 +
 
 +
Typically in RoadWarrior setups as this it is impossible to know from which address user will connect, so we need to set up <var>generate-policy</var> parameter on the server side. However this leads to other problems, client can generate any policy and access any network in the office. Even set 0.0.0.0/0 and deny internet access to office workers.
 +
 
 +
'''Mode Conf''', '''policy group''' and '''policy templates''' will allow us to overcome these problems.
 +
 
 +
 
 +
====IPsec Server Config====
 +
 
 +
At first we need a pool from which RoadWarrior will will get an address. Typically in office you set up DHCP server for local workstations, the same DHCP pool can be used.
 +
<pre>
 +
/ip pool
 +
add name=ipsec-RW ranges=192.168.77.2-192.168.77.254
 +
</pre>
 +
 
 +
Next we need to set up what settings to send to the client using Mode Conf. 
 +
<pre>
 +
/ip ipsec mode-config
 +
add address-pool=ipsec-RW name=RW-cfg split-include=\
 +
    10.5.8.0/24,192.168.55.0/24
 +
</pre>
 +
As you can see we specified from which pool to give out address and two allowed subnets.
 +
 
 +
 
 +
Now to allow only specific source/destination address in generated policies we will use policy group and create policy templates:
 +
<pre>
 +
/ip ipsec policy group
 +
add name=RoadWarrior
 +
 
 +
/ip ipsec policy
 +
add dst-address=192.168.77.0/24 group=RoadWarrior src-address=10.5.8.0/24 \
 +
    template=yes
 +
add dst-address=192.168.77.0/24 group=RoadWarrior src-address=192.168.55.0/24 \
 +
    template=yes
 +
</pre>
 +
 
 +
 
 +
Now we just add xauth users and peer with enabled Mode Conf and policy group.
 +
<pre>
 +
/ip ipsec user
 +
add name=user1 password=123
 +
add name=user2 password=234
 +
 
 +
/ip ipsec peer
 +
add auth-method=pre-shared-key-xauth generate-policy=port-strict mode-config=RW-cfg \
 +
    policy-template-group=RoadWarrior secret=123 passive=yes
 +
 
 +
</pre>
 +
 
 +
==== Apple iOS (iPhone/iPad) Client ====
 +
 
 +
For iOS devices to be able to connect, '''proposal''' changes are needed:
 +
 
 +
* does not work with 3des encryption algorithm, '''aes-128/256''' works
 +
* auth algorithm must be '''sha1'''
 +
* PFS group must be '''none'''
 +
* lifetime must be '''8 hours'''
 +
 
 +
Example of valid proposal configuration for iOS devices:
 +
<pre>
 +
/ip ipsec proposal
 +
set default enc-algorithms=aes-128-cbc,aes-256-cbc lifetime=8h \
 +
    pfs-group=none
 +
</pre>
 +
 
 +
{{ Note | Iphone does not work with split-include 0.0.0.0/0. If you set 0.0.0.0/0 for older clients traffic will not be sent over the tunnel, for newer ios clients tunnel will not be established.}}
 +
 
 +
==== Android Client Notes ====
 +
 
 +
Android devices are trying to add policy with destination 0.0.0.0/0, so you have to make sure that correct policy template is added.
 +
 
 +
In our case we need to add:
 +
<pre>
 +
/ip ipsec policy
 +
add group=RoadWarrior dst-address=192.168.77.0/24 src-address=0.0.0.0/0 template=yes
 +
</pre>
 +
 
 +
====RouterOS Client Config====
 +
 
 +
<pre>
 +
/ip ipsec peer
 +
add address=2.2.2.2 auth-method=pre-shared-key-xauth generate-policy=port-strict secret=123 \
 +
    xauth-login=user1 xauth-password=123 mode-config=request-only
 +
</pre>
 +
 
 +
====Shrew Client Config====
 +
 
 +
<pre>
 +
n:version:2
 +
n:network-ike-port:500
 +
n:network-mtu-size:1380
 +
n:network-natt-port:4500
 +
n:network-natt-rate:15
 +
n:network-frag-size:540
 +
n:network-dpd-enable:0
 +
n:client-banner-enable:0
 +
n:network-notify-enable:0
 +
n:client-wins-used:0
 +
n:client-wins-auto:1
 +
n:client-dns-used:1
 +
n:client-dns-auto:0
 +
n:client-splitdns-used:1
 +
n:client-splitdns-auto:0
 +
n:phase1-dhgroup:2
 +
n:phase1-life-secs:86400
 +
n:phase1-life-kbytes:0
 +
n:vendor-chkpt-enable:0
 +
n:phase2-life-secs:300
 +
n:phase2-life-kbytes:0
 +
n:policy-nailed:1
 +
n:policy-list-auto:1
 +
n:client-addr-auto:1
 +
s:network-host:2.2.2.2
 +
s:client-auto-mode:pull
 +
s:client-iface:virtual
 +
s:network-natt-mode:disable
 +
s:network-frag-mode:disable
 +
s:auth-method:mutual-psk-xauth
 +
s:ident-client-type:address
 +
s:ident-server-type:address
 +
b:auth-mutual-psk:MTIz
 +
s:phase1-exchange:main
 +
s:phase1-cipher:3des
 +
s:phase1-hash:md5
 +
s:phase2-transform:esp-3des
 +
s:phase2-hmac:sha1
 +
s:ipcomp-transform:disabled
 +
n:phase2-pfsgroup:2
 +
s:policy-level:require
 +
 
 +
</pre>
 +
 
 +
===Basic L2TP/IPsec setup===
 +
 
 +
This example demonstrates how to easily setup L2TP/IPsec server on RouterOS for road warrior connections (works with Windows, Android, iOS, macOS and other vendor L2TP/IPsec implementations).
 +
 
 +
====RouterOS server configuration====
 +
 
 +
First step is to enable L2TP server:
 +
 
 +
<pre>
 +
/interface l2tp-server server
 +
set enabled=yes use-ipsec=required ipsec-secret=mySecret default-profile=default
 +
</pre>
 +
 
 +
<var>use-ipsec</var> is set to <b>required</b> to make sure that only IPsec encapsulated L2TP connections are accepted.
 +
 
 +
Now what it does is enables L2TP server and creates dynamic IPsec peer with specified secret.
 +
 
 +
<pre>
 +
[admin@MikroTik] /ip ipsec peer> print
 +
0  D address=0.0.0.0/0 local-address=0.0.0.0 passive=yes port=500
 +
      auth-method=pre-shared-key secret="123" generate-policy=port-strict
 +
      exchange-mode=main-l2tp send-initial-contact=yes nat-traversal=yes
 +
      hash-algorithm=sha1 enc-algorithm=3des,aes-128,aes-192,aes-256
 +
      dh-group=modp1024 lifetime=1d dpd-interval=2m dpd-maximum-failures=5
 +
</pre>
 +
 
 +
{{Note | Care must be taken if static IPsec peer configuration exists. }}
 +
 
 +
Next step is to create VPN pool and add some users.
 +
 
 +
<pre>
 +
/ip pool add name=vpn-pool range=192.168.99.2-192.168.99.100
 +
 
 +
/ppp profile
 +
set default local-address=192.168.99.1 remote-address=vpn-pool
 +
 
 +
/ppp secret
 +
add name=user1 password=123
 +
add name=user2 password=234
 +
</pre>
 +
 
 +
Now router is ready to accept L2TP/IPsec client connections.
 +
 
 +
====RouterOS client configuration====
 +
 
 +
For RouterOS to work as L2TP/IPsec client, it is as simple as adding a new L2TP client.
 +
 
 +
<pre>
 +
/interface l2tp-client
 +
add connect-to=1.1.1.1 disabled=no ipsec-secret=mySecret name=l2tp-out1 \
 +
    password=123 use-ipsec=yes user=user1
 +
</pre>
 +
 
 +
It will automatically create dynamic IPsec peer and policy configuration.
 +
 
 +
===Site to Site GRE tunnel over IPsec (IKEv2) using DNS===
 +
 
 +
This example explains how it is possible to establish a secure and encrypted GRE tunnel between two RouterOS devices when one or both sites do not have a static IP address. Before making this configuration possible, it is necessary to have a DNS name assigned to one of the devices which will act as a responder (server). For simplicity, we will use RouterOS built in DDNS service [[Manual:IP/Cloud | IP/Cloud]].
 +
 
 +
[[file:Site-to-site-gre-over-ipsec-example.png]]
 +
 
 +
====Site 1 (server) configuration====
 +
 
 +
This is the side that will listen to incoming connections and act as a responder. We will use [[#Mode_configs | mode config]] to provide an IP address for the second site, but first create a loopback (blank) bridge and assign an IP address to it that will be used later for GRE tunnel establishment.
 +
 
 +
<pre>
 +
/interface bridge
 +
add name=loopback
 +
/ip address
 +
add address=192.168.99.1 interface=loopback
 +
</pre>
 +
 
 +
Continuing with the IPsec configuration, start off by creating new Phase 1 [[#Profiles | profile]] and Phase 2 [[#Proposals | proposal]] entries using stronger or weaker encryption parameters that suits your needs. Note that this configuration example will listen to all incoming IKEv2 requests, meaning the profile configuration will be shared between all other configurations (e.g. RoadWarrior).
 +
 
 +
<pre>
 +
/ip ipsec profile
 +
add dh-group=ecp256,modp2048,modp1024 enc-algorithm=aes-256,aes-192,aes-128 name=ike2
 +
/ip ipsec proposal
 +
add auth-algorithms=null enc-algorithms=aes-128-gcm name=ike2-gre pfs-group=none
 +
</pre>
 +
 
 +
Next, create new [[#Mode_configs | mode config]] entry with <var>responder=yes</var>. This will provide an IP configuration for the other site as well as the host (loopback address) for policy generation.
 +
 
 +
<pre>
 +
/ip ipsec mode-config
 +
add address=192.168.99.2 address-prefix-length=32 name=ike2-gre split-include=192.168.99.1/32 system-dns=no
 +
</pre>
 +
 
 +
It is advised to create a new [[#Groups | policy group]] to separate this configuration from any existing or future IPsec configuration.
 +
 
 +
<pre>
 +
/ip ipsec policy group
 +
add name=ike2-gre
 +
</pre>
 +
 
 +
Now it is time to set up a new [[#Policies | policy]] template that will match the remote peers new dynamic address and the loopback address.
 +
 
 +
<pre>
 +
/ip ipsec policy
 +
add dst-address=192.168.99.2/32 group=ike2-gre proposal=ike2-gre src-address=192.168.99.1/32 template=yes
 +
</pre>
 +
 
 +
The next step is to create [[#Peers | peer]] configuration that will listen for all IKEv2 requests. If you already have such entry, you can skip this step.
 +
 
 +
<pre>
 +
/ip ipsec peer
 +
add exchange-mode=ike2 name=ike2 passive=yes profile=ike2
 +
</pre>
 +
 
 +
Lastly, set up an [[#Identities | identity]] that will match our remote peer by pre-shared-key authentication with specific <var>secret</var>.
 +
 
 +
<pre>
 +
/ip ipsec identity
 +
add generate-policy=port-strict mode-config=ike2-gre peer=ike2 policy-template-group=ike2-gre secret=test
 +
</pre>
 +
 
 +
The server side is now configured and listening to all IKEv2 requests. Please make sure the firewall is not blocking UDP/4500 port.
 +
 
 +
The last step is to create the GRE interface itself. This can also be done later when IPsec connection is established from the client side.
 +
 
 +
<pre>
 +
/interface gre
 +
add local-address=192.168.99.1 name=gre-tunnel1 remote-address=192.168.99.2
 +
</pre>
 +
 
 +
====Site 2 (client) configuration====
 +
 
 +
Similarly to server configuration, start off by creating new Phase 1 [[#Profiles | profile]] and Phase 2 [[#Proposals | proposal]] configurations. Since this side will be the initiator, we can use more specific profile configuration to control which exact encryption parameters are used, just make sure they overlap with what is configured on the server side.
 +
 
 +
<pre>
 +
/ip ipsec profile
 +
add dh-group=ecp256 enc-algorithm=aes-256 name=ike2-gre
 +
/ip ipsec proposal
 +
add auth-algorithms=null enc-algorithms=aes-128-gcm name=ike2-gre pfs-group=none
 +
</pre>
 +
 
 +
Next, create new [[#Mode_configs | mode config]] entry with <var>responder=no</var>. This will make sure the peer requests IP and split-network configuration from the server.
 +
 
 +
<pre>
 +
/ip ipsec mode-config
 +
add name=ike2-gre responder=no
 +
</pre>
 +
 
 +
It is also advised to create a new [[#Groups | policy group]] to separate this configuration from any existing or future IPsec configuration.
 +
 
 +
<pre>
 +
/ip ipsec policy group
 +
add name=ike2-gre
 +
</pre>
 +
 
 +
Create a new [[#Policies | policy]] template on the client side as well.
 +
 
 +
<pre>
 +
/ip ipsec policy
 +
add dst-address=192.168.99.1/32 group=ike2-gre proposal=ike2-gre src-address=192.168.99.2/32 template=yes
 +
</pre>
 +
 
 +
Move on to [[#Peers | peer]] configuration. Now we can specify the DNS name for the server under <var>address</var> parameter. Obviously, you can use an IP address as well.
 +
 
 +
<pre>
 +
/ip ipsec peer
 +
add address=n.mynetname.net exchange-mode=ike2 name=p1.ez profile=ike2-gre
 +
</pre>
 +
 
 +
Lastly, create an [[#Identities | identity]] for our newly created peer.
 +
 
 +
<pre>
 +
/ip ipsec identity
 +
add generate-policy=port-strict mode-config=ike2-gre peer=p1.ez policy-template-group=ike2-gre secret=test
 +
</pre>
 +
 
 +
If everything was done properly, there should be a new dynamic policy present.
 +
 
 +
<pre>
 +
/ip ipsec policy print
 +
Flags: T - template, X - disabled, D - dynamic, I - invalid, A - active, * - default
 +
0 T * group=default src-address=::/0 dst-address=::/0 protocol=all proposal=default template=yes
 +
 
 +
1 T  group=ike2-gre src-address=192.168.99.2/32 dst-address=192.168.99.1/32 protocol=all proposal=ike2-gre template=yes
 +
 
 +
2  DA  src-address=192.168.99.2/32 src-port=any dst-address=192.168.99.1/32 dst-port=any protocol=all action=encrypt level=unique ipsec-protocols=esp
 +
      tunnel=yes sa-src-address=172.17.2.1 sa-dst-address=172.17.2.2 proposal=ike2-gre ph2-count=1
 +
</pre>
 +
 
 +
A secure tunnel is now established between both sites which will encrypt all traffic between 192.168.99.2 <=> 192.168.99.1 addresses. We can use these addresses to create a GRE tunnel.
 +
 
 +
<pre>
 +
/interface gre
 +
add local-address=192.168.99.2 name=gre-tunnel1 remote-address=192.168.99.1
 +
</pre>
 +
 
 +
===IKEv2 EAP between NordVPN and RouterOS===
 +
 
 +
[[IKEv2_EAP_between_NordVPN_and_RouterOS | Example available here]]
 +
 
 +
==Troubleshooting/FAQ==
 +
 
 +
;Phase 1 Failed to get valid proposal
 +
:
 +
<pre>
 +
[admin@MikroTik] /log> print
 +
(..)
 +
17:12:32 ipsec,error no suitable proposal found.
 +
17:12:32 ipsec,error 10.5.107.112 failed to get valid proposal.
 +
17:12:32 ipsec,error 10.5.107.112 failed to pre-process ph1 packet (side: 1, status 1).
 +
17:12:32 ipsec,error 10.5.107.112 phase1 negotiation failed.
 +
(..)
 +
</pre>
 +
:Peers are unable to negotiate encryption parameters causing the connection to drop. To solve this issue, enable IPSec debug logs and find out which parameters are proposed by the remote peer and adjust configuration accordingly.
 +
<pre>
 +
[admin@MikroTik] /system logging> add topics=ipsec,!debug
 +
</pre>
 +
<pre>
 +
[admin@MikroTik] /log> print
 +
(..)
 +
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#1):Peer(prop#1:trns#1) = MD5:SHA
 +
17:21:08 ipsec rejected enctype: DB(prop#1:trns#2):Peer(prop#1:trns#1) = 3DES-CBC:AES-CBC
 +
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#2):Peer(prop#1:trns#1) = MD5:SHA
 +
17:21:08 ipsec rejected enctype: DB(prop#1:trns#1):Peer(prop#1:trns#2) = AES-CBC:3DES-CBC
 +
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#1):Peer(prop#1:trns#2) = MD5:SHA
 +
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#2):Peer(prop#1:trns#2) = MD5:SHA
 +
17:21:08 ipsec,error no suitable proposal found.
 +
17:21:08 ipsec,error 10.5.107.112 failed to get valid proposal.
 +
17:21:08 ipsec,error 10.5.107.112 failed to pre-process ph1 packet (side: 1, status 1).
 +
17:21:08 ipsec,error 10.5.107.112 phase1 negotiation failed.
 +
(..)
 +
</pre>
 +
:In this example, remote end requires SHA1 to be used as hash algorithm, but MD5 is configured on local router. Setting before the column symbol (:) is configured on the local side, parameter after the column symbol (:) is configured on the remote side.
 +
 
 +
;"phase1 negotiation failed due to time up" what does it mean?
 +
:There are communication problems between the peers. Possible causes include - misconfigured Phase 1 IP addresses; firewall blocking UDP ports 500 and 4500; NAT between peers not properly translating IPsec negotiation packets.
 +
:This error message can also appear when <var>local-address</var> parameter is not used properly. More information available [[#Manually_specifying_local-address_parameter_under_Peer_configuration | here]].
 +
 
 +
;Random packet drops or connections over the tunnel is very slow, enabling packet sniffer/torch fixes the problem
 +
:Problem is that before encapsulation packets are sent to Fasttrack/FastPath, thus bypassing IPsec policy checking.
 +
:Solution is to exclude traffic that need to be encapsulated/decaplsulated from Fasttrack, see configuration example [[#NAT_and_Fasttrack_Bypass | here]].
 +
 
 +
;How to enable ike2?
 +
: For basic configuration enabling ike2 is very simple, just change <var>exchange-mode</var> in peer settings to <b>ike2</b>.
 +
 
 +
; fatal NO-PROPOSAL-CHOSEN notify messsage
 +
: Remote peer sent notify that it cannot accept proposed algorithms, to find exact cause of the problem, look at remote peers debug logs or configuration and verify that both client and server have the same set of algorithms.
 +
 
 +
; I can ping only in one direction.
 +
: Typical problem in such cases is strict firewall, firewall rules allow to create new connections only in one direction. Solution is to recheck firewall rules, or explicitly accept all traffic that should be encapsulated/decapsulated.
 +
 
 +
; Can I allow only encrypted traffic?
 +
: Yes, you can, see examples [[#Allow_only_IPsec_encapsulated_traffic | here]].
  
;How to enable ike2?
+
; I enable IKEv2 REAUTH on StrongSwan and got error 'initiator did not reauthenticate as requested'
: For basic configuration enabling ike2 is very simple, just change <var>exchange-mode</var> in peer settings to <b>ike2</b>
+
: RouterOS does not support rfc4478, reauth must be disabled on StrongSwan.
  
; fatal NO-PROPOSAL-CHOSEN notify messsage
+
{{cont}}
: Remote peer sent notify that it cannot accept proposed algorithms, to find exact cause of the problem, look at remote peers debug logs or configuration and verify that both client and server have the same set of algorithms.
 
  
; I can ping only in one direction.
 
: Typical problem in such cases is strict firewall, firewall rules allow to create new connections only in one direction. Solution is to recheck firewall rules, or explicitly accept all traffic that should be encapsulated/decapsulated.
 
  
; Can I allow on
+
[[Category: Manual|IPSec]]
 +
[[Category: VPN|IPSec]]

Latest revision as of 09:58, 3 October 2019

Version.png

Applies to RouterOS: v6.0 +

Contents

Summary

Sub-menu: /ip ipsec
Package required: security


Internet Protocol Security (IPsec) is a set of protocols defined by the Internet Engineering Task Force (IETF) to secure packet exchange over unprotected IP/IPv6 networks such as Internet.


IPsec protocol suite can be divided in following groups:

  • Internet Key Exchange (IKE) protocols. Dynamically generates and distributes cryptographic keys for AH and ESP.
  • Authentication Header (AH) RFC 4302
  • Encapsulating Security Payload (ESP) RFC 4303

Internet Key Exchange Protocol (IKE)

The Internet Key Exchange (IKE) is a protocol that provides authenticated keying material for Internet Security Association and Key Management Protocol (ISAKMP) framework. There are other key exchange schemes that work with ISAKMP, but IKE is the most widely used one. Together they provide means for authentication of hosts and automatic management of security associations (SA).

Most of the time IKE daemon is doing nothing. There are two possible situations when it is activated:

There is some traffic caught by a policy rule which needs to become encrypted or authenticated, but the policy doesn't have any SAs. The policy notifies IKE daemon about that, and IKE daemon initiates connection to remote host. IKE daemon responds to remote connection. In both cases, peers establish connection and execute 2 phases:

  • Phase 1 - The peers agree upon algorithms they will use in the following IKE messages and authenticate. The keying material used to derive keys for all SAs and to protect following ISAKMP exchanges between hosts is generated also. This phase should match following settings:
    • authentication method
    • DH group
    • encryption algorithm
    • exchange mode
    • hash alorithm
    • NAT-T
    • DPD and lifetime (optional)
  • Phase 2 - The peers establish one or more SAs that will be used by IPsec to encrypt data. All SAs established by IKE daemon will have lifetime values (either limiting time, after which SA will become invalid, or amount of data that can be encrypted by this SA, or both). This phase should match following settings:
    • Ipsec protocol
    • mode (tunnel or transport)
    • authentication method
    • PFS (DH) group
    • lifetime
Icon-note.png

Note: There are two lifetime values - soft and hard. When SA reaches it's soft lifetime treshold, the IKE daemon receives a notice and starts another phase 2 exchange to replace this SA with fresh one. If SA reaches hard lifetime, it is discarded.


Icon-warn.png

Warning: Phase 1 is not re-keyed if DPD is disabled when lifetime expires, only phase 2 is re-keyed. To force phase 1 re-key, enable DPD.


Icon-warn.png

Warning: PSK authentication was known to be vulnerable against Offline attacks in "aggressive" mode, however recent discoveries indicate that offline attack is possible also in case of "main" and "ike2" exchange modes. General recommendation is to avoid using PSK authentication method.


IKE can optionally provide a Perfect Forward Secrecy (PFS), which is a property of key exchanges, that, in turn, means for IKE that compromising the long term phase 1 key will not allow to easily gain access to all IPsec data that is protected by SAs established through this phase 1. It means an additional keying material is generated for each phase 2.

Generation of keying material is computationally very expensive. Exempli gratia, the use of modp8192 group can take several seconds even on very fast computer. It usually takes place once per phase 1 exchange, which happens only once between any host pair and then is kept for long time. PFS adds this expensive operation also to each phase 2 exchange.

Diffie-Hellman Groups

Diffie-Hellman (DH) key exchange protocol allows two parties without any initial shared secret to create one securely. The following Modular Exponential (MODP) and Elliptic Curve (EC2N) Diffie-Hellman (also known as "Oakley") Groups are supported:

Diffie-Hellman GroupNameReference
Group 1768 bit MODP groupRFC 2409
Group 21024 bits MODP groupRFC 2409
Group 3EC2N group on GP(2^155)RFC 2409
Group 4EC2N group on GP(2^185)RFC 2409
Group 51536 bits MODP groupRFC 3526
Group 142048 bits MODP groupRFC 3526
Group 153072 bits MODP groupRFC 3526
Group 164096 bits MODP groupRFC 3526
Group 176144 bits MODP groupRFC 3526
Group 188192 bits MODP groupRFC 3526
Group 19256 bits random ECP groupRFC 5903
Group 20384 bits random ECP groupRFC 5903
Group 21521 bits random ECP groupRFC 5903

More on standards can be found here.

IKE Traffic

To avoid problems with IKE packets hit some SPD rule and require to encrypt it with not yet established SA (that this packet perhaps is trying to establish), locally originated packets with UDP source port 500 are not processed with SPD. The same way packets with UDP destination port 500 that are to be delivered locally are not processed in incoming policy check.


Setup Procedure

To get IPsec to work with automatic keying using IKE-ISAKMP you will have to configure policy, peer and proposal (optional) entries.

Icon-warn.png

Warning: Ipsec is very sensitive to time changes. If both ends of the IpSec tunnel are not synchronizing time equally(for example, different NTP servers not updating time with the same timestamp), tunnels will break and will have to be established again.



EAP Authentication methods

Outer Auth Inner Auth
EAP-GTC
EAP-MD5
EAP-MSCHAPv2
EAP-PEAPv0

EAP-MSCHAPv2
EAP-GPSK
EAP-GTC
EAP-MD5
EAP-TLS

EAP-SIM
EAP-TLS
EAP-TTLS

PAP
CHAP
MS-CHAP
MS-CHAPv2
EAP-MSCHAPv2
EAP-GTC
EAP-MD5
EAP-TLS

EAP-TLS on Windows is called "Smart Card or other certificate".

Authentication Header (AH)

AH is a protocol that provides authentication of either all or part of the contents of a datagram through the addition of a header that is calculated based on the values in the datagram. What parts of the datagram are used for the calculation, and the placement of the header, depends whether tunnel or transport mode is used.


The presence of the AH header allows to verify the integrity of the message, but doesn't encrypt it. Thus, AH provides authentication but not privacy. Another protocol (ESP) is considered superior, it provides data privacy and also its own authentication method.


RouterOS supports the following authentication algorithms for AH:

  • SHA2 (256, 512)
  • SHA1
  • MD5


Transport mode

In transport mode AH header is inserted after IP header. IP data and header is used to calculate authentication value. IP fields that might change during transit, like TTL and hop count, are set to zero values before authentication.


Tunnel mode

In tunnel mode original IP packet is encapsulated within a new IP packet. All of the original IP packet is authenticated.

Encapsulating Security Payload (ESP)

Encapsulating Security Payload (ESP) uses shared key encryption to provide data privacy. ESP also supports its own authentication scheme like that used in AH.

ESP packages its fields in a very different way than AH. Instead of having just a header, it divides its fields into three components:

  • ESP Header - Comes before the encrypted data and its placement depends on whether ESP is used in transport mode or tunnel mode.
  • ESP Trailer - This section is placed after the encrypted data. It contains padding that is used to align the encrypted data.
  • ESP Authentication Data - This field contains an Integrity Check Value (ICV), computed in a manner similar to how the AH protocol works, for when ESP's optional authentication feature is used.

Transport mode

In transport mode ESP header is inserted after original IP header. ESP trailer and authentication value is added to the end of the packet. In this mode only IP payload is encrypted and authenticated, IP header is not secured.

ESP-transport wiki.png

Tunnel mode

In tunnel mode original IP packet is encapsulated within a new IP packet thus securing IP payload and IP header.

ESP-tunnel wiki.png

Encryption algorithms

RouterOS ESP supports various encryption and authentication algorithms.

Authentication:

  • MD5
  • SHA1
  • SHA2 (256-bit, 512-bit)

Encryption:

  • AES - 128-bit, 192-bit and 256-bit key AES-CBC, AES-CTR and AES-GCM algorithms;
  • Blowfish - added since v4.5
  • Twofish - added since v4.5
  • Camellia - 128-bit, 192-bit and 256-bit key Camellia encryption algorithm added since v4.5
  • DES - 56-bit DES-CBC encryption algorithm;
  • 3DES - 168-bit DES encryption algorithm;

Hardware acceleration

Hardware acceleration allows to do faster encryption process by using built-in encryption engine inside CPU.

RouterBoard DES and 3DES AES-CBC AES-CTR AES-GCM
MD5 SHA1 SHA256 SHA512 MD5 SHA1 SHA256 SHA512 MD5 SHA1 SHA256 SHA512 MD5 SHA1 SHA256 SHA512
RBcAPGi-5acD2nD (cAP ac) * noyesyesno noyesyesno noyesyesno nononono
RBD25G-5HPacQD2HPnD (Audience) * noyesyesno noyesyesno noyesyesno nononono
RBD25GR-5HPacQD2HPnD&R11e-LTE6 (Audience LTE6 kit) * noyesyesno noyesyesno noyesyesno nononono
RBD52G-5HacD2HnD (hAP ac2) * noyesyesno noyesyesno noyesyesno nononono
RBDiscG-5acD (DISC Lite5 ac) * noyesyesno noyesyesno noyesyesno nononono
RBLDFG-5acD (LDF 5 ac) * noyesyesno noyesyesno noyesyesno nononono
RBLHGG-5acD (LHG 5 ac) * noyesyesno noyesyesno noyesyesno nononono
RBLHGG-5HPacD2HPnD-XL (LHG XL 52 ac) * noyesyesno noyesyesno noyesyesno nononono
RBLHGG-5acD-XL (LHG XL 5 ac) * noyesyesno noyesyesno noyesyesno nononono
RBLHGG-60ad (Wireless Wire Dish) * noyesyesno noyesyesno noyesyesno nononono
RBM11G **** yesyesyesno yesyesyesno nononono nononono
RBM33G **** yesyesyesno yesyesyesno nononono nononono
RBSXTsqG-5acD (SXTsq 5 ac) * noyesyesno noyesyesno noyesyesno nononono
RBwAPG-60ad (wAP 60G) * noyesyesno noyesyesno noyesyesno nononono
RBwAPG-60ad-A (wAP 60G AP) * noyesyesno noyesyesno noyesyesno nononono
RB450Gx4 * noyesyesno noyesyesno noyesyesno nononono
RB750Gr3 (hEX) **** yesyesyesno yesyesyesno nononono nononono
RB760iGS (hEX S) **** yesyesyesno yesyesyesno nononono nononono
RB850Gx2 ** nononono yesyesyesyes nononono nononono
RB1100AHx2 nononono yesyesyesyes nononono nononono
RB1100AHx4 and RB1100AHx4 Dude Edition yesyesyesyes yesyesyesyes yesyesyesyes yesyesyesyes
RB1200 *** nononono yesyesyesyes yesyesyesyes nononono
RB3011UiAS-RM * noyesyesno noyesyesno noyesyesno nononono
RB4011iGS+RM and RB4011iGS+5HacQ2HnD-IN yesyesyesyes yesyesyesyes yesyesyesyes yesyesyesyes
Cloud Core Router series yesyesyesno yesyesyesno yesyesyesno nononono
x86 (AES-NI) *** nononono yesyesyesyes yesyesyesyes yesyesyesyes

* supported only 128 bit and 256 bit key sizes

** only manufactured since 2016, serial numbers that begin with number 5 and 7

*** AES-CBC and AES-CTR only encryption is accelerated, hashing done in software

**** DES is not supported, only 3DES and AES-CBC

IPsec throughput results of various encryption and hash algorithm combinations are published on MikroTik products page. When testing throughput, please follow the guidelines available in the Traffic Generator manual page

Policies

Sub-menu: /ip ipsec policy


Policy table is used to determine whether security settings should be applied to a packet.


Properties

Property Description
action (discard | encrypt | none; Default: encrypt) Specifies what to do with packet matched by the policy.
  • none - pass the packet unchanged.
  • discard - drop the packet.
  • encrypt - apply transformations specified in this policy and it's SA.
comment (string; Default: ) Short description of the policy.
disabled (yes | no; Default: no) Whether policy is used to match packets.
dst-address (IP/IPv6 prefix; Default: 0.0.0.0/32) Destination address to be matched in packets. Applicable when tunnel mode (tunnel=yes) or template (template=yes) is used.
dst-port (integer:0..65535 | any; Default: any) Destination port to be matched in packets. If set to any all ports will be matched.
group (string; Default: default) Name of the policy group to which this template is assigned.
ipsec-protocols (ah | esp; Default: esp) Specifies what combination of Authentication Header and Encapsulating Security Payload protocols you want to apply to matched traffic.
level (require | unique | use; Default: require) Specifies what to do if some of the SAs for this policy cannot be found:
  • use - skip this transform, do not drop packet and do not acquire SA from IKE daemon;
  • require - drop packet and acquire SA;
  • unique - drop packet and acquire a unique SA that is only used with this particular policy. It is used in setups where multiple clients can sit behind one public IP address (clients behind NAT).
peer (string; Default: ) Name of the peer on which the policy applies.
proposal (string; Default: default) Name of the proposal template that will be sent by IKE daemon to establish SAs for this policy.
protocol (all | egp | ggp| icmp | igmp | ...; Default: all) IP packet protocol to match.
src-address (ip/ipv6 prefix; Default: 0.0.0.0/32) Source address to be matched in packets. Applicable when tunnel mode (tunnel=yes) or template (template=yes) is used.
src-port (any | integer:0..65535; Default: any) Source port to be matched in packets. If set to any all ports will be matched.
template (yes | no; Default: no) Creates a template and assigns it to specified policy group.

Following parameters are used by template:

  • group - name of the policy group to which this template is assigned;
  • src-address, dst-address - Requested subnet must match in both directions(for example 0.0.0.0/0 to allow all);
  • protocol - protocol to match, if set to all, then any protocol is accepted;
  • proposal - SA parameters used for this template;
  • level - useful when unique is required in setups with multiple clients behind NAT.
tunnel (yes | no; Default: no) Specifies whether to use tunnel mode.


Read only properties

Property Description
active (yes | no) Whether this policy is currently in use.
default (yes | no) Whether this is a default system entry.
dynamic (yes | no) Whether this is a dynamically added or generated entry.
invalid (yes | no) Whether this policy is invalid - possible cause is duplicate policy with the same src-address and dst-address.
ph2-count (integer) Number of active phase 2 sessions associated with the policy.
ph2-state (expired | no-phase2 | established) Indication of the progress of key establishing.
sa-dst-address (ip/ipv6 address; Default: ::) SA destination IP/IPv6 address (remote peer).
sa-src-address (ip/ipv6 address; Default: ::) SA source IP/IPv6 address (local peer).


Icon-warn.png

Warning: policy order is important starting form v6.40. Now it works similar as firewall filters where policies are executed from top to bottom (priority parameter is removed).


Icon-note.png

Note: All packets are IPIP encapsulated in tunnel mode, and their new IP header's src-address and dst-address are set to sa-src-address and sa-dst-address values of this policy. If you do not use tunnel mode (id est you use transport mode), then only packets whose source and destination addresses are the same as sa-src-address and sa-dst-address can be processed by this policy. Transport mode can only work with packets that originate at and are destined for IPsec peers (hosts that established security associations). To encrypt traffic between networks (or a network and a host) you have to use tunnel mode.


Statistics

Sub-menu: /ip ipsec statistics


This menu shows various IPsec statistics and errors.


Read only properties

Property Description
in-errors (integer) All inbound errors that are not matched by other counters.
in-buffer-errors (integer) No free buffer.
in-header-errors (integer) Header error.
in-no-states (integer) No state is found i.e. either inbound SPI, address, or IPsec protocol at SA is wrong.
in-state-protocol-errors (integer) Transformation protocol specific error, for example SA key is wrong or hardware accelerator is unable to handle amount of packets.
in-state-mode-errors (integer) Transformation mode specific error.
in-state-sequence-errors (integer) Sequence number is out of window.
in-state-expired (integer) State is expired.
in-state-mismatches (integer) State has mismatched option, for example UDP encapsulation type is mismatched.
in-state-invalid (integer) State is invalid.
in-template-mismatches (integer) No matching template for states, e.g. inbound SAs are correct but SP rule is wrong. Possible cause is mismatched sa-source or sa-destination address.
in-no-policies (integer) No policy is found for states, e.g. inbound SAs are correct but no SP is found.
in-policy-blocked (integer) Policy discards.
in-policy-errors (integer) Policy errors.
out-errors (integer) All outbound errors that are not matched by other counters.
out-bundle-errors (integer) Bundle generation error.
out-bundle-check-errors (integer) Bundle check error.
out-no-states (integer) No state is found.
out-state-protocol-errors (integer) Transformation protocol specific error.
out-state-mode-errors (integer) Transformation mode specific error.
out-state-sequence-errors (integer) Sequence errors, for example sequence number overflow.
out-state-expired (integer) State is expired.
out-policy-blocked (integer) Policy discards.
out-policy-dead (integer) Policy is dead.
out-policy-errors (integer) Policy error.

Proposals

Sub-menu: /ip ipsec proposal


Proposal information that will be sent by IKE daemons to establish SAs for certain policy.


Properties

Property Description
auth-algorithms (md5|null|sha1|sha256|sha512; Default: sha1) Allowed algorithms for authorization. SHA (Secure Hash Algorithm) is stronger, but slower. MD5 uses 128-bit key, sha1-160bit key.
comment (string; Default: )
disabled (yes | no; Default: no) Whether item is disabled.
enc-algorithms (null|des|3des|aes-128-cbc|aes-128-cbc|aes-128gcm|aes-192-cbc|aes-192-ctr|aes-192-gcm|aes-256-cbc|aes-256-ctr|aes-256-gcm|blowfish|camellia-128|camellia-192|camellia-256|twofish; Default: aes-256-cbc,aes-192-cbc,aes-128-cbc) Allowed algorithms and key lengths to use for SAs.
lifetime (time; Default: 30m) How long to use SA before throwing it out.
name (string; Default: )
pfs-group (ec2n155 | ec2n185 | ecp256 | ecp384 | ecp521 | modp768 | modp1024 | modp1536 | modp2048 | modp3072 | modp4096 | modp6144 | modp8192 | none; Default: modp1024) Diffie-Helman group used for Perfect Forward Secrecy.


Read only properties

Property Description
default (yes | no) Whether this is a default system entry.

Groups

Sub-menu: /ip ipsec policy group


In this menu it is possible to create additional policy groups used by policy templates.


Properties

Property Description
name (string; Default: )
comment (string; Default: )

Peers

Sub-menu: /ip ipsec peer


Peer configuration settings are used to establish connections between IKE daemons. This connection then will be used to negotiate keys and algorithms for SAs. Exchange mode is the only unique identifier between the peers, meaning that there can be multiple peer configurations with the same remote-address as long as different exchange-mode is used.


Properties

Property Description
address (IP/IPv6 Prefix; Default: 0.0.0.0/0) If remote peer's address matches this prefix, then the peer configuration is used in authentication and establishment of Phase 1. If several peer's addresses match several configuration entries, the most specific one (i.e. the one with largest netmask) will be used.
comment (string; Default: ) Short description of the peer.
disabled (yes | no; Default: no) Whether peer is used to match remote peer's prefix.
exchange-mode (aggressive | base | main | ike2; Default: main) Different ISAKMP phase 1 exchange modes according to RFC 2408. main mode relaxes rfc2409 section 5.4, to allow pre-shared-key authentication in main mode. ike2 mode enables Ikev2 RFC 7296. Parameters that are ignored by IKEv2 proposal-check, compatibility-options, lifebytes, dpd-maximum-failures, nat-traversal.
local-address (IP/IPv6 Address; Default: ) Routers local address on which Phase 1 should be bounded to.
name (string; Default: )
passive (yes | no; Default: no) When passive mode is enabled will wait for remote peer to initiate IKE connection. Enabled passive mode also indicates that peer is xauth responder, and disabled passive mode - xauth initiator. When passive mode is disabled peer will try to establish not only phase1, but also phase2 automatically, if policies are configured or created during phase1.
port (integer:0..65535; Default: 500) Communication port used (when router is initiator) to connect to remote peer in cases if remote peer uses non-default port.
profile (string; Default: default) Name of the profile template that will be used during IKE negotiation.
send-initial-contact (yes | no; Default: yes) Specifies whether to send "initial contact" IKE packet or wait for remote side, this packet should trigger removal of old peer SAs for current source address. Usually in road warrior setups clients are initiators and this parameter should be set to no. Initial contact is not sent if modecfg or xauth is enabled for ikev1.


Read only properties

Property Description
dynamic (yes | no) Whether this is a dynamically added entry by different service (e.g L2TP).
responder (yes | no) Whether this peer will act as a responder only (listen to incoming requests) and not initiate a connection.


Identities

Identities are configuration parameters that are specific to the remote peer. Main purpose of an identity is to handle authentication and verify peer's integrity.

Properties

Property Description
auth-method (digital-signature | eap | eap-radius | pre-shared-key | pre-shared-key-xauth | rsa-key | rsa-signature-hybrid; Default: pre-shared-key) Authentication method:
  • digital-signature - authenticate using a pair of RSA certificates;
  • eap - IKEv2 EAP authentication for initiator (peer with netmask of /32). Must be used together with eap-methods;
  • eap-radius - IKEv2 EAP RADIUS passthrough authentication for responder (RFC 3579). Server certificate in this case is required. If server certificate is not specified then only clients supporting EAP-only (RFC 5998) will be able to connect. Note that EAP method should be compatible with EAP-only;
  • pre-shared-key - authenticate by a password (pre-shared secret) string shared between the peers (not recommended since offline attack on pre-shared key is possible);
  • rsa-key - authenticate using a RSA key imported in keys menu. Only supported in IKEv1;
  • pre-shared-key-xauth - authenticate by a password (pre-shared secret) string shared between the peers + XAuth username and password. Only supported in IKEv1;
  • rsa-signature-hybrid - responder certificate authentication with initiator XAuth. Only supported in IKEv1.
certificate (string; Default: ) Name of a certificate listed in System/Certificates (signing packets; the certificate must have private key). Applicable if digital signature authentication method (auth-method=digital-signature) or EAP (auth-method=eap) is used.
comment (string; Default: ) Short description of the identity.
disabled (yes | no; Default: no) Whether identity is used to match remote peer.
eap-methods (eap-mschapv2 | eap-peap | eap-tls | eap-ttls; Default: eap-tls) All EAP methods requires whole certificate chain including intermediate and root CA certificates to be present in System/Certificates menu. Also username and password (if required by authentication server) must be specified. Multiple EAP methods may be specified and will be used in specified order. Currently supported EAP methods:
  • eap-mschapv2;
  • eap-peap - also known as PEAPv0/EAP-MSCHAPv2;
  • eap-tls - requires additional client certificate specified under certificate parameter;
  • eap-ttls.
generate-policy (no | port-override | port-strict; Default: no) Allow this peer to establish SA for non-existing policies. Such policies are created dynamically for the lifetime of SA. Automatic policies allows, for example, to create IPsec secured L2TP tunnels, or any other setup where remote peer's IP address is not known at the configuration time.
  • no - do not generate policies;
  • port-override - generate policies and force policy to use any port (old behavior);
  • port-strict - use ports from peer's proposal, which should match peer's policy.
key (string; Default: ) Name of the private key from keys menu. Applicable if RSA key authentication method (auth-method=rsa-key) is used.
match-by (remote-id | certificate; Default: remote-id) Defines the logic used for peer's identity validation.
  • remote-id - will verify the peer's ID according to remote-id setting.
  • certificate will verify the peer's certificate with what is specified under remote-certificate setting.
mode-config (none | *request-only | string; Default: none) Name of the configuration parameters from mode-config menu. When parameter is set mode-config is enabled.
my-id (auto | address | fqdn | user-fqdn | key-id; Default: auto) On initiator, this controls what ID_i is sent to the responder. On responder, this controls what ID_r is sent to the initiator. In IKEv2, responder also expects this ID in received ID_r from initiator.
  • auto - tries to use correct ID automatically: IP for pre-shared key, SAN (DN if not present) for certificate based connections;
  • address - IP address is used as ID;
  • fqdn - fully qualified domain name;
  • key-id - use the specified key ID for the identity;
  • user fqdn - specifies a fully-qualified username string, for example, "user@domain.com".
notrack-chain (string; Default: ) Adds IP/Firewall/Raw rules matching IPsec policy to specified chain. Use together with generate-policy.
password (string; Default: ) XAuth or EAP password. Applicable if pre-shared key with XAuth authentication method (auth-method=pre-shared-key-xauth) or EAP (auth-method=eap) is used.
peer (string; Default: ) Name of the peer on which the identity applies.
policy-template-group (none | string; Default: default) If generate-policy is enabled, traffic selectors are checked against templates from the same group. If none of the templates match, Phase 2 SA will not be established.
remote-certificate (string; Default: ) Name of a certificate (listed in System/Certificates) for authenticating the remote side (validating packets; no private key required). If remote-certificate is not specified then received certificate from remote peer is used and checked against CA in certificate menu. Proper CA must be imported in certificate store. If remote-certificate and match-by=certificate is specified, only the specific client certificate will be matched. Applicable if digital signature authentication method (auth-method=digital-signature) is used.
remote-id (auto | fqdn | user-fqdn | key-id | ignore; Default: auto) This parameter controls what ID value to expect from the remote peer. Note that all types except for ignore will verify remote peer's ID with received certificate. In case when the peer sends certificate name as its ID, it is checked against the certificate, else the ID is checked against Subject Alt. Name.
  • auto - accept all ID's;
  • fqdn - fully qualified domain name. Only supported in IKEv2;
  • user fqdn - a fully-qualified username string, for example, "user@domain.com". Only supported in IKEv2;
  • key-id - specific key ID for the identity. Only supported in IKEv2;
  • ignore - do not verify received ID with certificate (dangerous).
remote-key (string; Default: ) Name of the public key from keys menu. Applicable if RSA key authentication method (auth-method=rsa-key) is used.
secret (string; Default: ) Secret string. If it starts with '0x', it is parsed as a hexadecimal value. Applicable if pre-shared key authentication method (auth-method=pre-shared-key and auth-method=pre-shared-key-xauth) is used.
username (string; Default: ) XAuth or EAP username. Applicable if pre-shared key with XAuth authentication method (auth-method=pre-shared-key-xauth) or EAP (auth-method=eap) is used.


Read only properties

Property Description
dynamic (yes | no) Whether this is a dynamically added entry by different service (e.g L2TP).

Profiles

Profiles defines a set of parameters that will be used for IKE negotiation during Phase 1. These parameters may be common with other peer configurations.

Properties

Property Description
dh-group (modp768 | modp1024 | ec2n155 | ec2n185 | modp1536 | modp2048 | modp3072 | modp4096 | modp6144 | modp8192 | ecp256 | ecp384 | ecp521; Default: modp1024,modp2048) Diffie-Hellman group (cipher strength)
dpd-interval (time | disable-dpd; Default: 2m) Dead peer detection interval. If set to disable-dpd, dead peer detection will not be used.
dpd-maximum-failures (integer: 1..100; Default: 5) Maximum count of failures until peer is considered to be dead. Applicable if DPD is enabled.
enc-algorithm (3des | aes-128 | aes-192 | aes-256 | blowfish | camellia-128 | camellia-192 | camellia-256 | des; Default: aes-128) List of encryption algorithms that will be used by the peer.
hash-algorithm (md5 | sha1 | sha256 | sha512; Default: sha1) Hashing algorithm. SHA (Secure Hash Algorithm) is stronger, but slower. MD5 uses 128-bit key, sha1-160bit key.
lifebytes (Integer: 0..4294967295; Default: 0) Phase 1 lifebytes is used only as administrative value which is added to proposal. Used in cases if remote peer requires specific lifebytes value to establish phase 1.
lifetime (time; Default: 1d) Phase 1 lifetime: specifies how long the SA will be valid.
name (string; Default: )
nat-traversal (yes | no; Default: yes) Use Linux NAT-T mechanism to solve IPsec incompatibility with NAT routers inbetween IPsec peers. This can only be used with ESP protocol (AH is not supported by design, as it signs the complete packet, including IP header, which is changed by NAT, rendering AH signature invalid). The method encapsulates IPsec ESP traffic into UDP streams in order to overcome some minor issues that made ESP incompatible with NAT.
proposal-check (claim | exact | obey | strict; Default: obey) Phase 2 lifetime check logic:
  • claim - take shortest of proposed and configured lifetimes and notify initiator about it
  • exact - require lifetimes to be the same
  • obey - accept whatever is sent by an initiator
  • strict - if proposed lifetime is longer than the default then reject proposal otherwise accept proposed lifetime

Active Peers

Sub-menu: /ip ipsec active-peers


This menu provides various statistics about remote peers that currently have established phase 1 connection.


Read only properties

Property Description
dynamic-address (ip/ipv6 address) Dynamically assigned IP address by mode config
last-seen (time) Duration since last message received by this peer.
local-address (ip/ipv6 address) Local address on the router used by this peer.
natt-peer (yes | no) Whether NAT-T is used for this peer.
ph2-total (integer) Total amount of active IPsec security associations.
remote-address (ip/ipv6 address) Remote peer's ip/ipv6 address.
responder (yes | no) Whether the connection is initiated by remote peer.
rx-bytes (integer) Total amount of bytes received from this peer.
rx-packets (integer) Total amount of packets received from this peer.
side (initiator | responder) Shows which side initiated the Phase1 negotiation.
state (string) State of phase 1 negotiation with the peer. For example when phase1 and phase 2 are negotiated it will show state "established".
tx-bytes (integer) Total amount of bytes transmitted to this peer.
tx-packets (integer) Total amount of packets transmitted to this peer.
uptime (time) How long peers are in established state.


Commands

Property Description
kill-connections () Manually disconnects all remote peers.

Mode configs

Sub-menu: /ip ipsec mode-config


ISAKMP and IKEv2 configuration attributes are configured in this menu.


Properties

Property Description
address-pool (none | string; Default: ) Name of the address pool from which responder will try to assign address if mode-config is enabled.
address-prefix-length (integer [1..32]; Default: ) Prefix length (netmask) of assigned address from the pool.
comment (string; Default: )
name (string; Default: )
responder (yes | no; Default: no) Specifies whether the configuration will work as an initiator (client) or responder (server). Initiator will request for mode-config parameters from responder.
split-include (list of IP prefix; Default: ) List of subnets in CIDR format, which to tunnel. Subnets will be sent to the peer using CISCO UNITY extension, remote peer will create specific dynamic policies.
src-address-list (address list; Default: ) Specifying an address list will generate dynamic source NAT rules. This parameter is only available with responder=no. RoadWarrior client with NAT
static-dns (list of IP; Default: ) Manually specified DNS server's IP address to be sent to the client.
system-dns (yes | no; Default: ) When this option is enabled DNS addresses will be taken from /ip dns.


Read only properties

Property Description
default (yes | no) Whether this is a default system entry.
Icon-note.png

Note: Not all IKE implementations support multiple split networks provided by split-include option.


Icon-note.png

Note: If RouterOS client is initiator, it will always send CISCO UNITY extension, and RouterOS supports only split-include from this extension.


Icon-note.png

Note: It is not possible to use system-dns and static-dns at the same time.


Installed SAs

Sub-menu: /ip ipsec installed-sa


This menu provides information about installed security associations including the keys.


Read only properties

Property Description
AH (yes | no) Whether AH protocol is used by this SA.
ESP (yes | no) Whether ESP protocol is used by this SA.
add-lifetime (time/time) Added lifetime for the SA in format soft/hard:
  • soft - time period after which ike will try to establish new SA;
  • hard - time period after which SA is deleted.
addtime (time) Date and time when this SA was added.
auth-algorithm (md5 | null | sha1 | ...) Currently used authentication algorithm.
auth-key (string) Used authentication key.
current-bytes (64-bit integer) Number of bytes seen by this SA.
dst-address (IP) Destination address of this SA.
enc-algorithm (des | 3des | aes-cbc | ...) Currently used encryption algorithm.
enc-key (string) Used encryption key.
enc-key-size (number) Used encryption key length.
expires-in (yes | no) Time left until rekeying.
hw-aead (yes | no) Whether this SA is hardware accelerated.
replay (integer) Size of replay window in bytes.
spi (string) Security Parameter Index identification tag
src-address (IP) Source address of this SA.
state (string) Shows the current state of the SA ("mature", "dying" etc)


Commands

Property Description
flush () Manually removes all installed security associations.

Keys

Sub-menu: /ip ipsec key


This menu lists all imported public andprivate keys, that can be used for peer authentication. Menu has several commands to work with keys.


Properties

Property Description
name (string; Default: )


Read only properties

Property Description
key-size (1024 | 2048 | 4096) Size of this key.
private-key (yes | no) Whether this is a private key.
rsa (yes | no) Whether this is a RSA key.


Commands

Property Description
export-pub-key (file-name; key) Export public key to file from one of existing private keys.
generate-key (key-size; name) Generate private key. Takes two parameters, name of newly generated key and key size 1024,2048 and 4096.
import (file-name; name) Import key from file.

Settings

Sub-menu: /ip ipsec settings


Property Description
accounting (yes | no; Default: ) Whether to send RADIUS accounting requests to RADIUS server. Applicable if EAP Radius (auth-method=eap-radius) or pre-shared key with XAuth authentication method (auth-method=pre-shared-key-xauth) is used.
interim-update (time; Default: ) Interval between each consecutive RADIUS accounting Interim update. Accounting must be enabled.
xauth-use-radius (yes | no; Default: ) Whether to use Radius client for XAuth users or not.

Application Guides

RoadWarrior client with NAT

Consider setup as illustrated below. RouterOS acts as a RoadWarrior client connected to Office allowing access to its internal resources.

Ipsec-road-warrior-client.png

Tunnel is established, local mode-config IP address is received and a set of dynamic policies are generated.

[admin@pair_r1] > ip ipsec policy print 
Flags: T - template, X - disabled, D - dynamic, I - invalid, A - active, * - default 
 0 T * group=default src-address=::/0 dst-address=::/0 protocol=all proposal=default template=yes 

 1  DA  src-address=192.168.77.254/32 src-port=any dst-address=10.5.8.0/24 dst-port=any protocol=all 
       action=encrypt level=unique ipsec-protocols=esp tunnel=yes sa-src-address=10.155.107.8 
       sa-dst-address=10.155.107.9 proposal=default ph2-count=1 

 2  DA  src-address=192.168.77.254/32 src-port=any dst-address=192.168.55.0/24 dst-port=any protocol=all 
       action=encrypt level=unique ipsec-protocols=esp tunnel=yes sa-src-address=10.155.107.8 
       sa-dst-address=10.155.107.9 proposal=default ph2-count=1 

Currently only packets with source address of 192.168.77.254/32 will match the IPsec policies. For local network to be able to reach remote subnets, it is necessary to change the source address of local hosts to the dynamically assigned mode config IP address. It is possible to generate source NAT rules dynamically. This can be done by creating a new address list which contains of all local networks that NAT rule should be applied. In our case, it is 192.168.88.0/24.

/ip firewall address-list add address=192.168.88.0/24 list=local-RW

By specifying the address list under mode-config initiator configuration, a set of source NAT rules will be dynamically generated.

/ip ipsec mode-config set [ find name="request-only" ] src-address-list=local-RW

When the IPsec tunnel is established, we can see the dynamically created source NAT rules for each network. Now every host in 192.168.88.0/24 is able to access Office's internal resources.

[admin@pair_r1] > ip firewall nat print 
Flags: X - disabled, I - invalid, D - dynamic 
 0  D ;;; ipsec mode-config
      chain=srcnat action=src-nat to-addresses=192.168.77.254 dst-address=192.168.55.0/24 src-address-list=local-RW

 1  D ;;; ipsec mode-config
      chain=srcnat action=src-nat to-addresses=192.168.77.254 dst-address=10.5.8.0/24 src-address-list=local-RW

Simple mutual PSK XAuth configuration

Server side configuration:

/ip ipsec peer
add address=2.2.2.1 auth-method=pre-shared-key-xauth secret="123" passive=yes

/ip ipsec user
add name=test password=345

Client side configuration:

/ip ipsec peer
add address=2.2.2.2 auth-method=pre-shared-key-xauth secret="123" \
  xauth-login=test xauth-password=345


Icon-note.png

Note: On server side it is mandatory to set passive to yes when XAuth is used.


Allow only IPsec encapsulated traffic

There are some scenarios where for security reasons you would like to drop access from/to specific networks if incoming/outgoing packets are not encrypted. For example, if we have L2TP/IPsec setup we would want to drop non encrypted L2TP connection attempts.

There are several ways how to achieve this:

  • Using IPsec policy matcher in firewall;
  • Using generic IPsec policy with action set to drop and lower priority (can be used in Road Warrior setups where dynamic policies are generated);
  • By setting DSCP or priority in mangle and matching the same values in firewall after decapsulation.

IPsec policy matcher

Lets set up IPsec policy matcher to accept all packets that matched any of IPsec policies and drop the rest:

add chain=input comment="ipsec policy matcher" in-interface=WAN \
    ipsec-policy=in,ipsec
add action=drop chain=input comment="drop all" in-interface=WAN log=yes

IPsec policy matcher takes two parameters direction,policy. We used incoming direction and IPsec policy. IPsec policy option allows us to inspect packets after decapsulation, so for example if we want to allow only gre encapsulated packet from specific source address and drop the rest we could set up following rules:

add chain=input comment="ipsec policy matcher" in-interface=WAN \
    ipsec-policy=in,ipsec protocol=gre src=address=192.168.33.1
add action=drop chain=input comment="drop all" in-interface=WAN log=yes

For L2TP rule set would be:

add chain=input comment="ipsec policy matcher" in-interface=WAN \
    ipsec-policy=in,ipsec protocol=udp dst-port=1701
add action=drop chain=input protocol=udp dst-port=1701 comment="drop l2tp" in-interface=WAN log=yes

Using generic IPsec policy

The trick of this method is to add default policy with action drop. Lets assume we are running L2TP/IPsec server on public 1.1.1.1 address and we want to drop all non encrypted L2TP:

/ip ipsec policy
add src-address=1.1.1.1 dst-address=0.0.0.0/0 sa-src-address=1.1.1.1 \
  protocol=udp src-port=1701 tunnel=yes action=discard

Now router will drop any L2TP unencrypted incoming traffic, but after successful L2TP/IPsec connection dynamic policy is created with higher priority than it is on default static rule and packets matching that dynamic rule can be forwarded.

Icon-note.png

Note: Policy order is important! For this to work, make sure the static drop policy is below the dynamic policies. Move it below the policy template if necessary.


[admin@rack2_10g1] /ip ipsec policy> print
Flags: T - template, X - disabled, D - dynamic, I - inactive, * - default
 0 T * group=default src-address=::/0 dst-address=::/0 protocol=all
       proposal=default template=yes

 1  D  src-address=1.1.1.1/32 src-port=1701 dst-address=10.5.130.71/32
       dst-port=any protocol=udp action=encrypt level=require
       ipsec-protocols=esp tunnel=no sa-src-address=1.1.1.1
       sa-dst-address=10.5.130.71

 2     src-address=1.1.1.1/32 src-port=1701 dst-address=0.0.0.0/0
       dst-port=any protocol=udp action=discard level=unique
       ipsec-protocols=esp tunnel=yes sa-src-address=1.1.1.1
       sa-dst-address=0.0.0.0 proposal=default manual-sa=none

Manually specifying local-address parameter under Peer configuration

Using different routing table

IPsec, as any other service in RouterOS, uses main routing table regardless what local-address parameter is used for Peer configuration. It is necessary to apply routing marks to both IKE and IPSec traffic.

Consider the following example. There are two default routes - one in main routing table and another in routing table "backup". It is necessary to use the backup link for IPsec site to site tunnel.

[admin@pair_r1] > /ip route print detail 
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit 
 0 A S  dst-address=0.0.0.0/0 gateway=10.155.107.1 gateway-status=10.155.107.1 reachable via  ether1 distance=1 scope=30 target-scope=10 routing-mark=backup 

 1 A S  dst-address=0.0.0.0/0 gateway=172.22.2.115 gateway-status=172.22.2.115 reachable via  ether2 distance=1 scope=30 target-scope=10 

 2 ADC  dst-address=10.155.107.0/25 pref-src=10.155.107.8 gateway=ether1 gateway-status=ether1 reachable distance=0 scope=10 

 3 ADC  dst-address=172.22.2.0/24 pref-src=172.22.2.114 gateway=ether2 gateway-status=ether2 reachable distance=0 scope=10 

 4 ADC  dst-address=192.168.1.0/24 pref-src=192.168.1.1 gateway=bridge-local gateway-status=ether2 reachable distance=0 scope=10 

[admin@pair_r1] > /ip firewall nat print  
Flags: X - disabled, I - invalid, D - dynamic 
 0    chain=srcnat action=masquerade out-interface=ether1 log=no log-prefix="" 

 1    chain=srcnat action=masquerade out-interface=ether2 log=no log-prefix="" 

IPsec peer and policy configurations are created using the backup link's source address, as well as NAT bypass rule for IPsec tunnel traffic.

/ip ipsec peer
add address=10.155.130.136/32 local-address=10.155.107.8 secret=test
/ip ipsec policy
add sa-src-address=10.155.107.8 src-address=192.168.1.0/24 dst-address=172.16.0.0/24 sa-dst-address=10.155.130.136 tunnel=yes
/ip firewall nat
add action=accept chain=srcnat src-address=192.168.1.0/24 dst-address=172.16.0.0/24 place-before=0

Currently, we see "phase1 negotiation failed due to time up" errors in the log. It is because IPsec tries to reach the remote peer using the main routing table with incorrect source address. It is necessary to mark UDP/500, UDP/4500 and ipsec-esp packets using Mangle.

/ip firewall mangle
add action=mark-connection chain=output connection-mark=no-mark dst-address=10.155.130.136 dst-port=500,4500 \
new-connection-mark=ipsec passthrough=yes protocol=udp
add action=mark-connection chain=output connection-mark=no-mark dst-address=10.155.130.136 new-connection-mark=ipsec \
passthrough=yes protocol=ipsec-esp
add action=mark-routing chain=output connection-mark=ipsec new-routing-mark=backup passthrough=no

Using same routing table with multiple IP addresses

Consider the following example. There are multiple IP addresses from the same subnet on the public interface. Masquerade rule is configured on out-interface. It is necessary to use one of the IP addresses explicitly.

[admin@pair_r1] > /ip address print 
Flags: X - disabled, I - invalid, D - dynamic 
 #   ADDRESS            NETWORK         INTERFACE
 0   192.168.1.1/24     192.168.1.0     bridge-local
 1   172.22.2.1/24      172.22.2.0      ether1
 2   172.22.2.2/24      172.22.2.0      ether1
 3   172.22.2.3/24      172.22.2.0      ether1

[admin@pair_r1] > /ip route print 
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit 
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 1 A S  0.0.0.0/0                          172.22.2.115              1
 3 ADC  172.22.2.0/24      172.22.2.1      ether1                    0
 4 ADC  192.168.1.0/24     192.168.1.1     bridge-local              0

[admin@pair_r1] /ip firewall nat> print 
Flags: X - disabled, I - invalid, D - dynamic 
 0    chain=srcnat action=masquerade out-interface=ether1 log=no log-prefix="" 

IPsec peer and policy configuration is created using one of the public IP addresses.

/ip ipsec peer
add address=10.155.130.136/32 local-address=172.22.2.3 secret=test
/ip ipsec policy
add sa-src-address=172.22.2.3 src-address=192.168.1.0/24 dst-address=172.16.0.0/24 sa-dst-address=10.155.130.136 tunnel=yes
/ip firewall nat
add action=accept chain=srcnat src-address=192.168.1.0/24 dst-address=172.16.0.0/24 place-before=0

Currently the phase 1 connection uses a different source address than we specified and "phase1 negotiation failed due to time up" errors are shown in the logs. This is because masquerade is changing the source address of the connection to match pref-src address of the connected route. Solution is to exclude connections from the public IP address from being masqueraded.

/ip firewall nat
add action=accept chain=srcnat protocol=udp src-port=500,4500 place-before=0

Application Examples

Site to Site IPsec tunnel

Consider setup as illustrated below. Two remote office routers are connected to internet and office workstations are behind NAT. Each office has its own local subnet, 10.1.202.0/24 for Office1 and 10.1.101.0/24 for Office2. Both remote offices needs secure tunnel to local networks behind routers.

Site-to-site-ipsec-example.png

Site 1 configuration

Start off by creating new Phase 1 profile and Phase 2 proposal entries using stronger or weaker encryption parameters that suits your needs. It is advised to create separate entries for each menu so that they are unique for each peer in case it is necessary to adjust any of the settings in the future. These parameters must match between the sites or else the connection will not establish.

/ip ipsec profile
add dh-group=modp2048 enc-algorithm=aes-128 name=ike1-site2
/ip ipsec proposal
add enc-algorithms=aes-128-cbc name=ike1-site2 pfs-group=modp2048

Continue by configuring a peer. Specify the address of the remote router. This address should be reachable through UDP/500 and UDP/4500 ports, so make sure appropriate actions are taken regarding the router's firewall. Specify the name for this peer as well as the newly created profile.

/ip ipsec peer
add address=192.168.80.1/32 name=ike1-site2 profile=ike1-site2

The next step is to create an identity. For a basic pre-shared key secured tunnel, there is nothing much to set except for a strong secret and the peer to which this identity applies.

/ip ipsec identity
add peer=ike1-site2 secret=thisisnotasecurepsk
Icon-warn.png

Warning: If security matters, consider using IKEv2 and a different auth-method.


Lastly, create a policy which controls the networks/hosts between whom traffic should be encrypted.

/ip ipsec policy
add src-address=10.1.202.0/24 src-port=any dst-address=10.1.101.0/24 dst-port=any \
tunnel=yes action=encrypt proposal=default peer=ike1-site2

Site 2 configuration

Office 2 configuration is almost identical as Office 1 with proper IP address configuration. Start off by creating new Phase 1 profile and Phase 2 proposal entries.

/ip ipsec profile
add dh-group=modp2048 enc-algorithm=aes-128 name=ike1-site1
/ip ipsec proposal
add enc-algorithms=aes-128-cbc name=ike1-site1 pfs-group=modp2048

Next is the peer and identity.

/ip ipsec peer
add address=192.168.90.1/32 name=ike1-site1 profile=ike1-site1
/ip ipsec identity
add peer=ike1-site1 secret=thisisnotasecurepsk

When it is done, create a policy:

/ip ipsec policy
add src-address=10.1.101.0/24 src-port=any dst-address=10.1.202.0/24 dst-port=any \
tunnel=yes action=encrypt proposal=default peer=ike1-site1

At this point, the tunnel should be established and two IPsec Security Associations should be created on both routers:

/ip ipsec
remote-peers print
installed-sa print

NAT and Fasttrack Bypass

At this point if you try to send traffic over the IPsec tunnel, it will not work, packets will be lost. This is because both routers have NAT rules (masquerade) that is changing source address before packet is encrypted. Router is unable to encrypt the packet, because source address do not match address specified in policy configuration. For more information see IPsec packet flow example.

To fix this we need to set up IP/Firewall/NAT bypass rule.

Office 1 router:

/ip firewall nat
add chain=srcnat action=accept  place-before=0 \
 src-address=10.1.202.0/24 dst-address=10.1.101.0/24

Office 2 router:

/ip firewall nat
add chain=srcnat action=accept  place-before=0 \
 src-address=10.1.101.0/24 dst-address=10.1.202.0/24
Icon-note.png

Note: If you previously tried to establish an IP connection before NAT bypass rule was added, you have to clear connection table from existing connection or restart both routers.


It is very important that bypass rule is placed at the top of all other NAT rules.

Another issue is if you have IP/Fasttrack enabled, packet bypasses IPsec policies. So we need to add accept rule before FastTrack.

/ip firewall filter
add chain=forward action=accept place-before=1
 src-address=10.1.101.0/24 dst-address=10.1.202.0/24 connection-state=established,related
add chain=forward action=accept place-before=1
 src-address=10.1.202.0/24 dst-address=10.1.101.0/24 connection-state=established,related

However, this can add significant load to router's CPU if there is a fair amount of tunnels and significant traffic on each tunnel.

Solution is to use IP/Firewall/Raw to bypass connection tracking, that way eliminating need of filter rules listed above and reducing load on CPU by approximately 30%.

/ip firewall raw
add action=notrack chain=prerouting src-address=10.1.101.0/24 dst-address=10.1.202.0/24
add action=notrack chain=prerouting src-address=10.1.202.0/24 dst-address=10.1.101.0/24

Road Warrior setup using IKEv2 with RSA authentication

This example explains how to establish a secure IPsec connection between a device connected to the Internet (road warrior client) and a device running RouterOS acting as a server.

Ipsec-road-warrior.png


RouterOS server configuration

Before configuring IPsec, it is required to set up certificates. It is possible to use a separate Certificate Authority for certificate management, however in this example, self signed certificates are generated in RouterOS System/Certificates menu. Some certificate requirements should be met to connect various devices to the server:

  • Common name should contain IP or DNS name of the server;
  • SAN (subject alternative name) should have IP or DNS of the server;
  • EKU (extended key usage) tls-server and tls-client are required.

Considering all requirements above, generate CA and server certificates:

/certificate
add common-name=ca name=ca
sign ca ca-crl-host=2.2.2.2
add common-name=2.2.2.2 subject-alt-name=IP:2.2.2.2 key-usage=tls-server name=server1
sign server1 ca=ca

Now that valid certificates are created on the router, add new Phase 1 profile and Phase 2 proposal entries with pfs-group=none.

/ip ipsec profile
add name=ike2
/ip ipsec proposal
add name=ike2 pfs-group=none

Mode config is used for address distribution from IP/Pools.

/ip pool
add name=ike2-pool ranges=192.168.77.2-192.168.77.254
/ip ipsec mode-config
add address-pool=ike2-pool address-prefix-length=32 name=ike2-conf

Since that the policy template must be adjusted to allow only specific network policies, it is advised to create a separate policy group and template.

/ip ipsec policy group
add name=ike2-policies
/ip ipsec policy
add dst-address=192.168.77.0/24 group=ike2-policies proposal=ike2 src-address=0.0.0.0/0 template=yes

Create a new IPsec peer entry which will listen to all incoming IKEv2 requests.

/ip ipsec peer
add exchange-mode=ike2 name=ike2 passive=yes profile=ike2
Identity configuration

Identity menu allows to match specific remote peers and assign different configuration for each one of them. First, create a default identity, that will accept all peers, but will verify the peer's identity with its certificate.

/ip ipsec identity
add auth-method=digital-signature certificate=server1 generate-policy=port-strict mode-config=ike2-conf peer=ike2 policy-template-group=ike2-policies
Icon-note.png

Note: If peer's ID (ID_i) is not matching with the certificate it sends, the identity lookup will fail. See remote-id in identities section.


For example, we want to assign different mode config for user "A", who uses certificate "rw-client1" to authenticate itself to the server. First of all, make sure a new mode config is created and ready to be applied for the specific user.

/ip ipsec mode-config
add address=192.168.66.2 address-prefix-length=32 name=usr_A split-include=192.168.55.0/24 system-dns=no

It is possible apply this configuration for user "A" by using match-by=certificate parameter and specifying his certificate with remote-certificate.

/ip ipsec identity
add auth-method=digital-signature certificate=server1 generate-policy=port-strict match-by=certificate mode-config=usr_A peer=ike2 policy-template-group=ike2-policies remote-certificate=rw-client1
Split tunnel configuration

Split tunneling is a method which allows road warrior clients to only access a specific secured network and at the same time send the rest of the traffic based on their internal routing table (as opposed to sending all traffic over the tunnel). To configure split tunneling, changes to mode config parameters are needed.

For example we will allow our road warrior clients to only access 10.5.8.0/24 network.

/ip ipsec mode-conf
set [find name="rw-conf"] split-include=10.5.8.0/24

It is also possible to send specific DNS server for the client to use. By default system-dns=yes is used, which sends DNS servers that are configured on the router itself in IP/DNS. We can force the client to use different DNS server by using the static-dns parameter.

/ip ipsec mode-conf
set [find name="rw-conf"] system-dns=no static-dns=10.5.8.1

While it is possible to adjust IPsec policy template to only allow road warrior clients to generate policies to network configured by split-include parameter, this can cause compatibility issues with different vendor implementations (see known limitations). Instead of adjusting the policy template, allow access to secured network in IP/Firewall/Filter and drop everything else.

/ip firewall filter
add action=drop chain=forward src-address=192.168.77.0/24 dst-address=!10.5.8.0/24
Icon-warn.png

Warning: Split networking is not a security measure. The client (initiator) can still request a different Phase 2 traffic selector.


Generating client certificates

To generate a new certificate for the client and sign it with previously created CA.

/certificate
add common-name=rw-client1 name=rw-client1 key-usage=tls-client
sign rw-client1 ca=ca

PKCS12 format is accepted by most of client implementations, so when exporting the certificate, make sure PKCS12 is specified.

/certificate
export-certificate rw-client1 export-passphrase=1234567890 type=pkcs12

A file named cert_export_rw-client1.p12 is now located in the routers System/File section. This file should be securely transported to the client device.

Typically PKCS12 bundle contains also CA certificate, but some vendors may not install this CA, so self-signed CA certificate must be exported separately using PEM format.

/certificate
export-certificate ca type=pem

A file named cert_export_ca.crt is now located in the routers System/File section. This file should also be securely transported to the client device.

PEM is another certificate format for use in client software that do not support PKCS12. Principle is pretty much the same.

/certificate
export-certificate ca
export-certificate rw-client1 export-passphrase=1234567890

Three files are now located in the routers Files section: cert_export_ca.crt, cert_export_rw-client1.crt and cert_export_rw-client1.key which should be securely transported to the client device.

Known limitations

Here is a list of known limitations by popular client software IKEv2 implementations.

  • Windows will always ignore networks received by split-include and request policy with destination 0.0.0.0/0 (TSr). When IPsec-SA is generated, Windows requests DHCP option 249 to which RouterOS will respond with configured split-include networks automatically.
  • Both Apple macOS and iOS will only accept the first split-include network.
  • Both Apple macOS and iOS will use the DNS servers from system-dns and static-dns parameters only when 0.0.0.0/0 split-include is used.
  • While some implementations can make use of different PFS group for phase 2, it is advised to use pfs-grou=none under proposals to avoid any compatibility issues.

RouterOS client configuration

Import a PKCS12 format certificate in RouterOS.

/certificate import file-name=cert_export_RouterOS_client.p12 passphrase=1234567890

There should now be the self-signed CA certificate and the client certificate in Certificate menu. Find out the name of the client certificate.

/certificate print

cert_export_RouterOS_client.p12_0 is the client certificate.

It is advised to create a separate Phase 1 profile and Phase 2 proposal configurations to not interfere with any existing IPsec configuration.

/ip ipsec profile
add name=ike2-rw
/ip ipsec proposal
add name=ike2-rw pfs-group=none

While it is possible to use the default policy template for policy generation, it is better to create a new policy group and template to separate this configuration from any other IPsec configuration.

/ip ipsec policy group
add name=ike2-rw
/ip ipsec policy
add group=ike2-rw proposal=ike2-rw template=yes

Create a new mode config entry with responder=no that will request configuration parameters from the server.

/ip ipsec mode-config
add name=ike2-rw responder=no

Lastly, create peer and identity configurations.

/ip ipsec peer
add address=2.2.2.2/32 exchange-mode=ike2 name=ike2-rw-client
/ip ipsec identity
add auth-method=digital-signature certificate=cert_export_RouterOS_client.p12_0 generate-policy=port-strict mode-config=ike2-rw peer=ike2-rw-client policy-template-group=ike2-rw

Verify that the connection is successfully established.

/ip ipsec
remote-peers print
installed-sa print
Enabling dynamic source NAT rule generation

If we look at the generated dynamic policies, we see that only traffic with a specific (received by mode config) source address will be sent through the tunnel. But a router in most cases will need to route a specific device or network through the tunnel. In such case we can use source NAT to change the source address of packets to match the mode config address. Since the mode config address is dynamic, it is impossible to create static source NAT rule. In RouterOS it is possible to generate dynamic source NAT rules for mode config clients.

Ipsec-road-warrior-client.png

For example, we have a local network 192.168.88.0/24 behind the router and we want all traffic from this network to be sent over the tunnel. First of all, we have to make a new IP/Firewall/Address list which consists of our local network.

/ip firewall address-list
add address=192.168.88.0/24 list=local

When it is done, we can assign newly created IP/Firewall/Address list to mode config configuration.

/ip ipsec mode-config
set [ find name=ike2-rw ] src-address-list=local

Verify correct source NAT rule is dynamically generated when the tunnel is established.

[admin@MikroTik] > /ip firewall nat print 
Flags: X - disabled, I - invalid, D - dynamic 
 0  D ;;; ipsec mode-config
      chain=srcnat action=src-nat to-addresses=192.168.77.254 src-address-list=local dst-address-list=!local
Icon-warn.png

Warning: Make sure dynamic mode config address is not a part of local network.


Windows client configuration

Open PKCS12 format certificate file on the Windows computer. Install the certificate by following the instructions. Make sure you select Local Machine store location.

Ike2v2 cert win.png

You can now proceed to Network and Internet settings -> VPN and add a new configuration. Fill in the Connection name, Server name or address parameters. Select IKEv2 under VPN type. When it is done, it is necessary to select "Use machine certificates". This can be done in Network and Sharing Center by clicking the Properties menu for the VPN connection. The setting is located under Security tab.

Ike2v2 conf win.png

Currently Windows 10 is compatible with the following Phase 1 ( profiles) and Phase 2 ( proposals) proposal sets:

Phase 1
Hash AlgorithmEncryption AlgorithmDH Group
SHA13DESmodp1024
SHA2563DESmodp1024
SHA1AES-128-CBCmodp1024
SHA256AES-128-CBCmodp1024
SHA1AES-192-CBCmodp1024
SHA256AES-192-CBCmodp1024
SHA1AES-256-CBCmodp1024
SHA256AES-256-CBCmodp1024
SHA1AES-128-GCMmodp1024
SHA256AES-128-GCMmodp1024
SHA1AES-256-GCMmodp1024
SHA256AES-256-GCMmodp1024


Phase 2
Hash AlgorithmEncryption AlgorithmPFS Group
SHA1AES-256-CBCnone
SHA1AES-128-CBCnone
SHA13DESnone
SHA1DESnone
SHA1nonenone


macOS client configuration

Open PKCS12 format certificate file on the macOS computer and install the certificate in "System" keychain. It is necessary to mark the CA certificate as trusted manually since it is self-signed. Locate the certificate macOS Keychain Access app under System tab and mark it as Always Trust.

Ikev2 cert macos.png

You can now proceed to System Preferences -> Network and add a new configuration by clicking the + button. Select Interface: VPN, VPN Type: IKEv2 and name your connection. Remote ID must be set equal to common-name or subjAltName of server's certificate. Local ID can be left blank. Under Authentication Settings select None and choose the client certificate. You can now test the connectivity.

Ikev2 conf macos.png

Currently macOS is compatible with the following Phase 1 ( profiles) and Phase 2 ( proposals) proposal sets:

Phase 1
Hash AlgorithmEncryption AlgorithmDH Group
SHA256AES-256-CBCmodp2048
SHA256AES-256-CBCecp256
SHA256AES-256-CBCmodp1536
SHA1AES-128-CBCmodp1024
SHA13DESmodp1024


Phase 2
Hash AlgorithmEncryption AlgorithmPFS Group
SHA256AES-256-CBCnone
SHA1AES-128-CBCnone
SHA13DESnone


iOS client configuration

Typically PKCS12 bundle contains also CA certificate, but iOS does not install this CA, so self-signed CA certificate must be installed separately using PEM format. Open these files on the iOS device and install both certificates by following the instructions. It is necessary to mark the self-signed CA certificate as trusted on the iOS device. This can be done in Settings -> General -> About -> Certificate Trust Settings menu. When it is done, check whether both certificates are marked as "verified" under Settings -> General -> Profiles menu.

Ikev2 cert ios.PNG


You can now proceed to Settings -> General -> VPN menu and add a new configuration. Remote ID must be set equal to common-name or subjAltName of server's certificate. Local ID can be left blank.

Ikev2 conf ios.PNG


Currently iOS is compatible with the following Phase 1 ( profiles) and Phase 2 ( proposals) proposal sets:

Phase 1
Hash AlgorithmEncryption AlgorithmDH Group
SHA256AES-256-CBCmodp2048
SHA256AES-256-CBCecp256
SHA256AES-256-CBCmodp1536
SHA1AES-128-CBCmodp1024
SHA13DESmodp1024


Phase 2
Hash AlgorithmEncryption AlgorithmPFS Group
SHA256AES-256-CBCnone
SHA1AES-128-CBCnone
SHA13DESnone


Icon-note.png

Note: If you are connected to the VPN over WiFi, the iOS device can go into sleep mode and disconnect from the network.



Android (strongSwan) client configuration

Currently there is no IKEv2 native support in Android, however it is possible to use strongSwan from Google Play Store which brings IKEv2 to Android. StrongSwan accepts PKCS12 format certificates, so before setting up the VPN connection in strongSwan, make sure you download the PKCS12 bundle to your Android device. When it is done, create a new VPN profile in strongSwan, type in the server IP and choose "IKEv2 Certificate" as VPN Type. When selecting a User certificate, press Install and follow the certificate extract procedure by specifying the PKCS12 bundle. Save the profile and test the connection by pressing on the VPN profile.

Ikev2 conf android.png


It is possible to specify custom encryption settings in strongSwan by ticking the "Show advanced settings" checkbox. Currently strongSwan by default is compatible with the following Phase 1 ( profiles) and Phase 2 ( proposals) proposal sets:

Phase 1
Hash AlgorithmEncryption AlgorithmDH Group
SHA*AES-*-CBCmodp2048
SHA*AES-*-CBCecp256
SHA*AES-*-CBCecp384
SHA*AES-*-CBCecp521
SHA*AES-*-CBCmodp3072
SHA*AES-*-CBCmodp4096
SHA*AES-*-CBCmodp6144
SHA*AES-*-CBCmodp8192
SHA*AES-*-GCMmodp2048
SHA*AES-*-GCMecp256
SHA*AES-*-GCMecp384
SHA*AES-*-GCMecp521
SHA*AES-*-GCMmodp3072
SHA*AES-*-GCMmodp4096
SHA*AES-*-GCMmodp6144
SHA*AES-*-GCMmodp8192


Phase 2
Hash AlgorithmEncryption AlgorithmPFS Group
noneAES-256-GCMnone
noneAES-128-GCMnone
SHA256AES-256-CBCnone
SHA512AES-256-CBCnone
SHA1AES-256-CBCnone
SHA256AES-192-CBCnone
SHA512AES-192-CBCnone
SHA1AES-192-CBCnone
SHA256AES-128-CBCnone
SHA512AES-128-CBCnone
SHA1AES-128-CBCnone

Linux (strongSwan) client configuration

Download the PKCS12 certificate bundle and move it to /etc/ipsec.d/private directory.

Add exported passphrase for the private key to /etc/ipsec.secrets file where "strongSwan_client.p12" is the file name and "1234567890" is the passphrase.

: P12 strongSwan_client.p12 "1234567890"

Add a new connection to /etc/ipsec.conf file

conn "ikev2"
        keyexchange=ikev2
        ike=aes128-sha1-modp2048
        esp=aes128-sha1
        leftsourceip=%modeconfig
        leftcert=strongSwan_client.p12
        leftfirewall=yes
        right=2.2.2.2
        rightid="CN=2.2.2.2"
        rightsubnet=0.0.0.0/0
        auto=add

You can now restart (or start) the ipsec daemon and initialize the connection

$ ipsec restart
$ ipsec up ikev2

Road Warrior setup with Mode Conf

Consider setup where worker need to access other co-workers (workstations) and local office server remotely. Office has two subnets:

  • 192.168.55.0/24 for workstations
  • 192.168.66.0/24 network that must not be reachable by RoadWarrior clients
  • 10.5.8.0/24 for servers

And access to those networks should be secure.

Ipsec-road-warrior.png

Typically in RoadWarrior setups as this it is impossible to know from which address user will connect, so we need to set up generate-policy parameter on the server side. However this leads to other problems, client can generate any policy and access any network in the office. Even set 0.0.0.0/0 and deny internet access to office workers.

Mode Conf, policy group and policy templates will allow us to overcome these problems.


IPsec Server Config

At first we need a pool from which RoadWarrior will will get an address. Typically in office you set up DHCP server for local workstations, the same DHCP pool can be used.

/ip pool
add name=ipsec-RW ranges=192.168.77.2-192.168.77.254

Next we need to set up what settings to send to the client using Mode Conf.

/ip ipsec mode-config
add address-pool=ipsec-RW name=RW-cfg split-include=\
    10.5.8.0/24,192.168.55.0/24

As you can see we specified from which pool to give out address and two allowed subnets.


Now to allow only specific source/destination address in generated policies we will use policy group and create policy templates:

/ip ipsec policy group
add name=RoadWarrior

/ip ipsec policy
add dst-address=192.168.77.0/24 group=RoadWarrior src-address=10.5.8.0/24 \
    template=yes
add dst-address=192.168.77.0/24 group=RoadWarrior src-address=192.168.55.0/24 \
    template=yes


Now we just add xauth users and peer with enabled Mode Conf and policy group.

/ip ipsec user
add name=user1 password=123
add name=user2 password=234

/ip ipsec peer
add auth-method=pre-shared-key-xauth generate-policy=port-strict mode-config=RW-cfg \
    policy-template-group=RoadWarrior secret=123 passive=yes

Apple iOS (iPhone/iPad) Client

For iOS devices to be able to connect, proposal changes are needed:

  • does not work with 3des encryption algorithm, aes-128/256 works
  • auth algorithm must be sha1
  • PFS group must be none
  • lifetime must be 8 hours

Example of valid proposal configuration for iOS devices:

/ip ipsec proposal
set default enc-algorithms=aes-128-cbc,aes-256-cbc lifetime=8h \
    pfs-group=none
Icon-note.png

Note: Iphone does not work with split-include 0.0.0.0/0. If you set 0.0.0.0/0 for older clients traffic will not be sent over the tunnel, for newer ios clients tunnel will not be established.


Android Client Notes

Android devices are trying to add policy with destination 0.0.0.0/0, so you have to make sure that correct policy template is added.

In our case we need to add:

/ip ipsec policy
add group=RoadWarrior dst-address=192.168.77.0/24 src-address=0.0.0.0/0 template=yes

RouterOS Client Config

/ip ipsec peer
add address=2.2.2.2 auth-method=pre-shared-key-xauth generate-policy=port-strict secret=123 \
     xauth-login=user1 xauth-password=123 mode-config=request-only

Shrew Client Config

n:version:2
n:network-ike-port:500
n:network-mtu-size:1380
n:network-natt-port:4500
n:network-natt-rate:15
n:network-frag-size:540
n:network-dpd-enable:0
n:client-banner-enable:0
n:network-notify-enable:0
n:client-wins-used:0
n:client-wins-auto:1
n:client-dns-used:1
n:client-dns-auto:0
n:client-splitdns-used:1
n:client-splitdns-auto:0
n:phase1-dhgroup:2
n:phase1-life-secs:86400
n:phase1-life-kbytes:0
n:vendor-chkpt-enable:0
n:phase2-life-secs:300
n:phase2-life-kbytes:0
n:policy-nailed:1
n:policy-list-auto:1
n:client-addr-auto:1
s:network-host:2.2.2.2
s:client-auto-mode:pull
s:client-iface:virtual
s:network-natt-mode:disable
s:network-frag-mode:disable
s:auth-method:mutual-psk-xauth
s:ident-client-type:address
s:ident-server-type:address
b:auth-mutual-psk:MTIz
s:phase1-exchange:main
s:phase1-cipher:3des
s:phase1-hash:md5
s:phase2-transform:esp-3des
s:phase2-hmac:sha1
s:ipcomp-transform:disabled
n:phase2-pfsgroup:2
s:policy-level:require

Basic L2TP/IPsec setup

This example demonstrates how to easily setup L2TP/IPsec server on RouterOS for road warrior connections (works with Windows, Android, iOS, macOS and other vendor L2TP/IPsec implementations).

RouterOS server configuration

First step is to enable L2TP server:

/interface l2tp-server server
set enabled=yes use-ipsec=required ipsec-secret=mySecret default-profile=default

use-ipsec is set to required to make sure that only IPsec encapsulated L2TP connections are accepted.

Now what it does is enables L2TP server and creates dynamic IPsec peer with specified secret.

[admin@MikroTik] /ip ipsec peer> print 
 0  D address=0.0.0.0/0 local-address=0.0.0.0 passive=yes port=500 
      auth-method=pre-shared-key secret="123" generate-policy=port-strict 
      exchange-mode=main-l2tp send-initial-contact=yes nat-traversal=yes 
      hash-algorithm=sha1 enc-algorithm=3des,aes-128,aes-192,aes-256 
      dh-group=modp1024 lifetime=1d dpd-interval=2m dpd-maximum-failures=5 
Icon-note.png

Note: Care must be taken if static IPsec peer configuration exists.


Next step is to create VPN pool and add some users.

/ip pool add name=vpn-pool range=192.168.99.2-192.168.99.100

/ppp profile
set default local-address=192.168.99.1 remote-address=vpn-pool

/ppp secret
add name=user1 password=123
add name=user2 password=234

Now router is ready to accept L2TP/IPsec client connections.

RouterOS client configuration

For RouterOS to work as L2TP/IPsec client, it is as simple as adding a new L2TP client.

/interface l2tp-client
add connect-to=1.1.1.1 disabled=no ipsec-secret=mySecret name=l2tp-out1 \
    password=123 use-ipsec=yes user=user1

It will automatically create dynamic IPsec peer and policy configuration.

Site to Site GRE tunnel over IPsec (IKEv2) using DNS

This example explains how it is possible to establish a secure and encrypted GRE tunnel between two RouterOS devices when one or both sites do not have a static IP address. Before making this configuration possible, it is necessary to have a DNS name assigned to one of the devices which will act as a responder (server). For simplicity, we will use RouterOS built in DDNS service IP/Cloud.

Site-to-site-gre-over-ipsec-example.png

Site 1 (server) configuration

This is the side that will listen to incoming connections and act as a responder. We will use mode config to provide an IP address for the second site, but first create a loopback (blank) bridge and assign an IP address to it that will be used later for GRE tunnel establishment.

/interface bridge 
add name=loopback
/ip address
add address=192.168.99.1 interface=loopback

Continuing with the IPsec configuration, start off by creating new Phase 1 profile and Phase 2 proposal entries using stronger or weaker encryption parameters that suits your needs. Note that this configuration example will listen to all incoming IKEv2 requests, meaning the profile configuration will be shared between all other configurations (e.g. RoadWarrior).

/ip ipsec profile
add dh-group=ecp256,modp2048,modp1024 enc-algorithm=aes-256,aes-192,aes-128 name=ike2
/ip ipsec proposal
add auth-algorithms=null enc-algorithms=aes-128-gcm name=ike2-gre pfs-group=none

Next, create new mode config entry with responder=yes. This will provide an IP configuration for the other site as well as the host (loopback address) for policy generation.

/ip ipsec mode-config
add address=192.168.99.2 address-prefix-length=32 name=ike2-gre split-include=192.168.99.1/32 system-dns=no

It is advised to create a new policy group to separate this configuration from any existing or future IPsec configuration.

/ip ipsec policy group
add name=ike2-gre

Now it is time to set up a new policy template that will match the remote peers new dynamic address and the loopback address.

/ip ipsec policy
add dst-address=192.168.99.2/32 group=ike2-gre proposal=ike2-gre src-address=192.168.99.1/32 template=yes

The next step is to create peer configuration that will listen for all IKEv2 requests. If you already have such entry, you can skip this step.

/ip ipsec peer
add exchange-mode=ike2 name=ike2 passive=yes profile=ike2

Lastly, set up an identity that will match our remote peer by pre-shared-key authentication with specific secret.

/ip ipsec identity
add generate-policy=port-strict mode-config=ike2-gre peer=ike2 policy-template-group=ike2-gre secret=test

The server side is now configured and listening to all IKEv2 requests. Please make sure the firewall is not blocking UDP/4500 port.

The last step is to create the GRE interface itself. This can also be done later when IPsec connection is established from the client side.

/interface gre
add local-address=192.168.99.1 name=gre-tunnel1 remote-address=192.168.99.2

Site 2 (client) configuration

Similarly to server configuration, start off by creating new Phase 1 profile and Phase 2 proposal configurations. Since this side will be the initiator, we can use more specific profile configuration to control which exact encryption parameters are used, just make sure they overlap with what is configured on the server side.

/ip ipsec profile
add dh-group=ecp256 enc-algorithm=aes-256 name=ike2-gre
/ip ipsec proposal
add auth-algorithms=null enc-algorithms=aes-128-gcm name=ike2-gre pfs-group=none

Next, create new mode config entry with responder=no. This will make sure the peer requests IP and split-network configuration from the server.

/ip ipsec mode-config
add name=ike2-gre responder=no

It is also advised to create a new policy group to separate this configuration from any existing or future IPsec configuration.

/ip ipsec policy group
add name=ike2-gre

Create a new policy template on the client side as well.

/ip ipsec policy
add dst-address=192.168.99.1/32 group=ike2-gre proposal=ike2-gre src-address=192.168.99.2/32 template=yes

Move on to peer configuration. Now we can specify the DNS name for the server under address parameter. Obviously, you can use an IP address as well.

/ip ipsec peer
add address=n.mynetname.net exchange-mode=ike2 name=p1.ez profile=ike2-gre

Lastly, create an identity for our newly created peer.

/ip ipsec identity
add generate-policy=port-strict mode-config=ike2-gre peer=p1.ez policy-template-group=ike2-gre secret=test

If everything was done properly, there should be a new dynamic policy present.

/ip ipsec policy print 
Flags: T - template, X - disabled, D - dynamic, I - invalid, A - active, * - default 
 0 T * group=default src-address=::/0 dst-address=::/0 protocol=all proposal=default template=yes

 1 T   group=ike2-gre src-address=192.168.99.2/32 dst-address=192.168.99.1/32 protocol=all proposal=ike2-gre template=yes

 2  DA  src-address=192.168.99.2/32 src-port=any dst-address=192.168.99.1/32 dst-port=any protocol=all action=encrypt level=unique ipsec-protocols=esp 
       tunnel=yes sa-src-address=172.17.2.1 sa-dst-address=172.17.2.2 proposal=ike2-gre ph2-count=1 

A secure tunnel is now established between both sites which will encrypt all traffic between 192.168.99.2 <=> 192.168.99.1 addresses. We can use these addresses to create a GRE tunnel.

/interface gre
add local-address=192.168.99.2 name=gre-tunnel1 remote-address=192.168.99.1

IKEv2 EAP between NordVPN and RouterOS

Example available here

Troubleshooting/FAQ

Phase 1 Failed to get valid proposal
[admin@MikroTik] /log> print
(..)
17:12:32 ipsec,error no suitable proposal found. 
17:12:32 ipsec,error 10.5.107.112 failed to get valid proposal. 
17:12:32 ipsec,error 10.5.107.112 failed to pre-process ph1 packet (side: 1, status 1). 
17:12:32 ipsec,error 10.5.107.112 phase1 negotiation failed. 
(..)
Peers are unable to negotiate encryption parameters causing the connection to drop. To solve this issue, enable IPSec debug logs and find out which parameters are proposed by the remote peer and adjust configuration accordingly.
[admin@MikroTik] /system logging> add topics=ipsec,!debug
[admin@MikroTik] /log> print
(..)
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#1):Peer(prop#1:trns#1) = MD5:SHA 
17:21:08 ipsec rejected enctype: DB(prop#1:trns#2):Peer(prop#1:trns#1) = 3DES-CBC:AES-CBC 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#2):Peer(prop#1:trns#1) = MD5:SHA 
17:21:08 ipsec rejected enctype: DB(prop#1:trns#1):Peer(prop#1:trns#2) = AES-CBC:3DES-CBC 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#1):Peer(prop#1:trns#2) = MD5:SHA 
17:21:08 ipsec rejected hashtype: DB(prop#1:trns#2):Peer(prop#1:trns#2) = MD5:SHA 
17:21:08 ipsec,error no suitable proposal found. 
17:21:08 ipsec,error 10.5.107.112 failed to get valid proposal. 
17:21:08 ipsec,error 10.5.107.112 failed to pre-process ph1 packet (side: 1, status 1). 
17:21:08 ipsec,error 10.5.107.112 phase1 negotiation failed. 
(..)
In this example, remote end requires SHA1 to be used as hash algorithm, but MD5 is configured on local router. Setting before the column symbol (:) is configured on the local side, parameter after the column symbol (:) is configured on the remote side.
"phase1 negotiation failed due to time up" what does it mean?
There are communication problems between the peers. Possible causes include - misconfigured Phase 1 IP addresses; firewall blocking UDP ports 500 and 4500; NAT between peers not properly translating IPsec negotiation packets.
This error message can also appear when local-address parameter is not used properly. More information available here.
Random packet drops or connections over the tunnel is very slow, enabling packet sniffer/torch fixes the problem
Problem is that before encapsulation packets are sent to Fasttrack/FastPath, thus bypassing IPsec policy checking.
Solution is to exclude traffic that need to be encapsulated/decaplsulated from Fasttrack, see configuration example here.
How to enable ike2?
For basic configuration enabling ike2 is very simple, just change exchange-mode in peer settings to ike2.
fatal NO-PROPOSAL-CHOSEN notify messsage
Remote peer sent notify that it cannot accept proposed algorithms, to find exact cause of the problem, look at remote peers debug logs or configuration and verify that both client and server have the same set of algorithms.
I can ping only in one direction.
Typical problem in such cases is strict firewall, firewall rules allow to create new connections only in one direction. Solution is to recheck firewall rules, or explicitly accept all traffic that should be encapsulated/decapsulated.
Can I allow only encrypted traffic?
Yes, you can, see examples here.
I enable IKEv2 REAUTH on StrongSwan and got error 'initiator did not reauthenticate as requested'
RouterOS does not support rfc4478, reauth must be disabled on StrongSwan.

[ Top | Back to Content ]