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 the Internet.
IPsec protocol suite can be divided into the following groups:
The Internet Key Exchange (IKE) is a protocol that provides authenticated keying material for the 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 the IKE daemon about that, and the IKE daemon initiates a connection to a remote host. IKE daemon responds to remote connection. In both cases, peers establish a connection and execute 2 phases:
There are two lifetime values - soft and hard. When SA reaches its soft lifetime threshold, the IKE daemon receives a notice and starts another phase 2 exchange to replace this SA with a fresh one. If SA reaches a hard lifetime, it is discarded. |
Phase 1 is not re-keyed if DPD is disabled when the lifetime expires, only phase 2 is re-keyed. To force phase 1 re-key, enable DPD. |
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. A general recommendation is to avoid using the 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.
The generation of keying material is computationally very expensive. Exempli Gratia, the use of the modp8192 group can take several seconds even on a 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 a long time. PFS adds this expensive operation also to each phase 2 exchange.
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 Group | Name | Reference |
---|---|---|
Group 1 | 768 bits MODP group | RFC 2409 |
Group 2 | 1024 bits MODP group | RFC 2409 |
Group 3 | EC2N group on GP(2^155) | RFC 2409 |
Group 4 | EC2N group on GP(2^185) | RFC 2409 |
Group 5 | 1536 bits MODP group | RFC 3526 |
Group 14 | 2048 bits MODP group | RFC 3526 |
Group 15 | 3072 bits MODP group | RFC 3526 |
Group 16 | 4096 bits MODP group | RFC 3526 |
Group 17 | 6144 bits MODP group | RFC 3526 |
Group 18 | 8192 bits MODP group | RFC 3526 |
Group 19 | 256 bits random ECP group | RFC 5903 |
Group 20 | 384 bits random ECP group | RFC 5903 |
Group 21 | 521 bits random ECP group | RFC 5903 |
More on standards can be found here.
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 checks.
To get IPsec to work with automatic keying using IKE-ISAKMP you will have to configure policy, peer, and proposal (optional) entries.
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. |
Outer Auth | Inner Auth |
---|---|
EAP-GTC | |
EAP-MD5 | |
EAP-MSCHAPv2 | |
EAP-PEAPv0 | EAP-MSCHAPv2 |
EAP-SIM | |
EAP-TLS | |
EAP-TTLS | PAP |
EAP-TLS on Windows is called "Smart Card or other certificates".
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 on 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:
In transport mode, the AH header is inserted after the 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.
In tunnel mode, the original IP packet is encapsulated within a new IP packet. All of the original IP packets are authenticated.
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:
In transport mode, the ESP header is inserted after the original IP header. ESP trailer and authentication value are added to the end of the packet. In this mode only the IP payload is encrypted and authenticated, the IP header is not secured.
In tunnel mode, an original IP packet is encapsulated within a new IP packet thus securing IP payload and IP header.
RouterOS ESP supports various encryption and authentication algorithms.
Authentication:
Encryption:
Hardware acceleration allows doing a faster encryption process by using a built-in encryption engine inside the 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) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBD23UGS-5HPacD2HnD-NM (NetMetal ac²) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBD25G-5HPacQD2HPnD (Audience) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBD25GR-5HPacQD2HPnD&R11e-LTE6 (Audience LTE6 kit) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBD52G-5HacD2HnD (hAP ac2) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBDiscG-5acD (DISC Lite5 ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBLDFG-5acD (LDF 5 ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBLHGG-5acD (LHG 5 ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBLHGG-5HPacD2HPnD-XL (LHG XL 52 ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBLHGG-5acD-XL (LHG XL 5 ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBLHGG-60ad (Wireless Wire Dish) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBLtAP-2HnD (LtAP) | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBLtAP-2HnD&R11e-LTE (LtAP LTE kit) | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBLtAP-2HnD&R11e-4G (LtAP 4G kit) | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBLtAP-2HnD&R11e-LTE6 (LtAP LTE6 kit) | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBM11G | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBM33G | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBSXTsqG-5acD (SXTsq 5 ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBwAPG-60ad (wAP 60G) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBwAPG-60ad-A (wAP 60G AP) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBwAPGR-5HacD2HnD (wAP R ac) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBwAPGR-5HacD2HnD&R11e-LTE (wAP ac LTE kit) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBwAPGR-5HacD2HnD&R11e-4G (wAP ac 4G kit) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RBwAPGR-5HacD2HnD&R11e-LTE6 (wAP ac LTE6 kit) | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RB450Gx4 | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RB750Gr3 (hEX) | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB760iGS (hEX S) | yes**** | yes**** | yes**** | no | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB850Gx2 | no | no | no | no | yes** | yes** | yes** | yes** | no | no | no | no | no | no | no | no |
RB1100AHx2 | yes | yes | yes | no | yes | yes | yes | yes | no | no | no | no | no | no | no | no |
RB1100AHx4 and RB1100AHx4 Dude Edition | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes |
RB1200 | no | no | no | no | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | no | no | no | no |
RB3011UiAS-RM | no | yes | yes | no | no | yes* | yes* | no | no | yes* | yes* | no | no | no | no | no |
RB4011iGS+RM and RB4011iGS+5HacQ2HnD-IN | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes |
Cloud Core Router series | yes | yes | yes | no | yes | yes | yes | no | yes | yes | yes | no | no | no | no | no |
x86 (AES-NI) | no | no | no | no | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** | yes*** |
* 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 the MikroTik products page.
The 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 the packet matched by the policy.
|
comment (string; Default: ) | Short description of the policy. |
disabled (yes | no; Default: no) | Whether a 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:
|
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 a specified policy group. Following parameters are used by template:
|
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 - the possible cause is a duplicate policy with the same src-address and dst-address. |
ph2-count (integer) | A 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). |
Policy order is important starting from v6.40. Now it works similarly to firewall filters where policies are executed from top to bottom (priority parameter is removed). |
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. |
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 the number of packets. |
in-state-mode-errors (integer) | Transformation mode-specific error. |
in-state-sequence-errors (integer) | A sequence number is out of a window. |
in-state-expired (integer) | The state is expired. |
in-state-mismatches (integer) | The state has a mismatched options, for example, the UDP encapsulation type is mismatched. |
in-state-invalid (integer) | The state is invalid. |
in-template-mismatches (integer) | No matching template for states, e.g. inbound SAs are correct but the SP rule is wrong. A possible cause is a 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) | The state is expired. |
out-policy-blocked (integer) | Policy discards. |
out-policy-dead (integer) | The policy is dead. |
out-policy-errors (integer) | Policy error. |
Proposal information that will be sent by IKE daemons to establish SAs for certain policies.
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 a 128-bit key, sha1-160bit key. |
comment (string; Default: ) | |
disabled (yes | no; Default: no) | Whether an 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) | The diffie-Helman group used for Perfect Forward Secrecy. |
Read-only properties
Property | Description |
---|---|
default (yes | no) | Whether this is a default system entry. |
In this menu, it is possible to create additional policy groups used by policy templates.
Properties
Property | Description |
---|---|
name (string; Default: ) | |
comment (string; Default: ) |
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 a different exchange-mode is used.
Properties
Property | Description |
---|---|
address (IP/IPv6 Prefix; Default: 0.0.0.0/0) | If the 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 the largest netmask) will be used. |
comment (string; Default: ) | Short description of the peer. |
disabled (yes | no; Default: no) | Whether peer is used to matching remote peer's prefix. |
exchange-mode (aggressive | base | main | ike2; Default: main) | Different ISAKMP phase 1 exchange modes according to RFC 2408. the main mode relaxes rfc2409 section 5.4, to allow pre-shared-key authentication in the 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 a passive mode is enabled will wait for a remote peer to initiate an IKE connection. The enabled passive mode also indicates that the peer is xauth responder, and disabled passive mode - xauth initiator. When a passive mode is a disabled peer will try to establish not only phase1 but also phase2 automatically, if policies are configured or created during the phase1. |
port (integer:0..65535; Default: 500) | Communication port used (when a router is an initiator) to connect to remote peer in cases if remote peer uses the 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 the 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 a 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 are configuration parameters that are specific to the remote peer. The main purpose of identity is to handle authentication and verify the 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:
|
certificate (string; Default: ) | Name of a certificate listed in System/Certificates (signing packets; the certificate must have the 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 peers. |
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, the username and password (if required by the authentication server) must be specified. Multiple EAP methods may be specified and will be used in a specified order. Currently supported EAP methods:
|
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.
|
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.
|
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.
|
notrack-chain (string; Default: ) | Adds IP/Firewall/Raw rules matching IPsec policy to a 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 a remote-certificate is not specified then the received certificate from a remote peer is used and checked against CA in the certificate menu. Proper CA must be imported in a 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 ignoring will verify remote peer's ID with a received certificate. In case when the peer sends the certificate name as its ID, it is checked against the certificate, else the ID is checked against Subject Alt. Name.
|
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 a different service (e.g L2TP). |
Profiles define 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 between IPsec peers. This can only be used with ESP protocol (AH is not supported by design, as it signs the complete packet, including the 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:
|
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 an IP address by mode config |
last-seen (time) | Duration since the 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) | The total amount of active IPsec security associations. |
remote-address (ip/ipv6 address) | The remote peer's ip/ipv6 address. |
responder (yes | no) | Whether the connection is initiated by a remote peer. |
rx-bytes (integer) | The total amount of bytes received from this peer. |
rx-packets (integer) | The 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) | The total amount of bytes transmitted to this peer. |
tx-packets (integer) | The total amount of packets transmitted to this peer. |
uptime (time) | How long peers are in an established state. |
Commands
Property | Description |
---|---|
kill-connections () | Manually disconnects all remote peers. |
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 the responder will try to assign address if mode-config is enabled. |
address-prefix-length (integer [1..32]; Default: ) | Prefix length (netmask) of the 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). The initiator will request for mode-config parameters from the 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 the CISCO UNITY extension, a 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. A 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. |
Not all IKE implementations support multiple split networks provided by the split-include option. |
If RouterOS client is initiator, it will always send CISCO UNITY extension, and RouterOS supports only split-include from this extension. |
It is not possible to use system-dns and static-dns at the same time. |
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:
|
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) | A number of bytes seen by this SA. |
dst-address (IP) | The 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) | The 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. |
This menu lists all imported public and private 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 an 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 a private key. Takes two parameters, name of the newly generated key and key size 1024,2048 and 4096. |
import (file-name; name) | Import key from file. |
Property | Description |
---|---|
accounting (yes | no; Default: ) | Whether to send RADIUS accounting requests to a 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: ) | The 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. |
Consider setup as illustrated below. RouterOS acts as a RoadWarrior client connected to Office allowing access to its internal resources.
A tunnel is established, a local mode-config IP address is received and a set of dynamic policies are generated.
[admin@mikrotik] > 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 a source address of 192.168.77.254/32 will match the IPsec policies. For a 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 that contains all local networks that the 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 the 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@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 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 |
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 nonencrypted L2TP connection attempts.
There are several ways how to achieve this:
Let's set up an IPsec policy matcher to accept all packets that matched any of the 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 a specific source address and drop the rest we could set up the 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 |
The trick of this method is to add a default policy with an action drop. Let's assume we are running an L2TP/IPsec server on a public 1.1.1.1 address and we want to drop all nonencrypted 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 a 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.
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 |
IPsec, as any other service in RouterOS, uses the main routing table regardless of 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 the main routing table and another in the routing table "backup". It is necessary to use the backup link for the 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 the 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 an 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 |
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 the pref-src address of the connected route. The 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 |
Consider setup as illustrated below. Two remote office routers are connected to the 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 need secure tunnels to local networks behind routers.
Site 1 configuration
Start off by creating a new Phase 1profileand Phase 2proposalentries using stronger or weaker encryption parameters that suit 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 |
If security matters, consider using IKEv2 and a different auth-method. |
Lastly, create a policy that 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=ike1-site2 peer=ike1-site2 |
Site 2 configuration
Office 2 configuration is almost identical to Office 1 with proper IP address configuration. Start off by creating a 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=ike1-site1 peer=ike1-site1 |
At this point, the tunnel should be established and two IPsec Security Associations should be created on both routers:
/ip ipsec active-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 are changing source addresses before a packet is encrypted. A router is unable to encrypt the packet because the source address does not match address specified in policy configuration. For more information see the 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 |
If you previously tried to establish an IP connection before the NAT bypass rule was added, you have to clear the connection table from the existing connection or restart both routers. |
It is very important that the bypass rule is placed at the top of all other NAT rules.
Another issue is if you have IP/Fasttrack enabled, the 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 a significant load to the router's CPU if there is a fair amount of tunnels and significant traffic on each tunnel.
The solution is to use IP/Firewall/Raw to bypass connection tracking, that way eliminating the need for filter rules listed above and reducing the 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 |