Manual:IP/IPsec
Applies to RouterOS: v6.0 +
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
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.
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.
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 Group | Name | Reference |
---|---|---|
Group 1 | 768 bit 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.
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.
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-SIM | |
EAP-TLS | |
EAP-TTLS |
PAP |
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.
Tunnel mode
In tunnel mode original IP packet is encapsulated within a new IP packet thus securing IP payload and IP header.
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 | AES-CBC | AES-CTR | AES-GCM | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
MD5 | SHA1 | SHA256 | SHA512 | MD5 | SHA1 | SHA256 | SHA512 | MD5 | SHA1 | SHA256 | SHA512 | |
RBcAPGi-5acD2nD (cAP ac) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBD52G-5HacD2HnD (hAP ac2) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBDiscG-5acD (DISC Lite5 ac) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBLDFG-5acD (LDF 5 ac) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBLHGG-5acD (LHG 5 ac) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBLHGG-5acD-XL (LHG XL 5 ac) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBLHGG-60ad (Wireless Wire Dish) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBM11G | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBM33G | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBSXTsqG-5acD (SXTsq 5 ac) * | no | yes | yes | no | no | no | no | no | no | no | no | no |
RBwAPG-60ad (wAP 60G) * | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RBwAPG-60ad-A (wAP 60G AP) * | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB450Gx4 * | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB750Gr3 (hEX) | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB760iGS (hEX S) | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB850Gx2 ** | yes | yes | yes | yes | no | no | no | no | no | no | no | no |
RB1100AHx2 | yes | yes | yes | no | no | no | no | no | no | no | no | no |
RB1100AHx4 | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes |
RB1200 *** | yes | yes | yes | yes | yes | yes | yes | yes | no | no | no | no |
CCR series | yes | yes | yes | no | yes | yes | yes | no | no | no | no | no |
x86 (AES-NI) *** | 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
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.
|
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. |
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:
|
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. |
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). |
src-address (ip/ipv6 prefix; Default: 0.0.0.0/32) | Source address to be matched in packets. |
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:
|
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. |
priority () | Shows kernel priority. |
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).
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. |
Policy 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. |
auth-method (eap-radius | pre-shared-key | pre-shared-key-xauth | rsa-signature | rsa-key | rsa-signature-hybrid; Default: pre-shared-key) | Authentication method:
|
certificate (string; Default: ) | Name of a certificate listed in certificate table (signing packets; the certificate must have private key). Applicable if RSA signature authentication method (auth-method=rsa-signature) is used. |
comment (string; Default: ) | Short description of the peer. |
compatibility-options (skip-peer-id-validation; Default: ) | Compatibility options to work with peers not following RFC guidelines. |
disabled (yes | no; Default: no) | Whether peer is used to match remote peer's prefix. |
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. |
exchange-mode (aggressive | base | main | main-l2tp | ike2; Default: main) | Different ISAKMP phase 1 exchange modes according to RFC 2408. Do not use other modes then main unless you know what you are doing. main-l2tp 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. |
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 key from key menu. Applicable if auth-method=rsa-key. |
local-address (IP/IPv6 Address; Default: ) | Routers local address on which Phase 1 should be bounded to. |
mode-config (none | request-only | string; Default: none) | Name of the mode config parameters from mode-config menu. When parameter is set mode-config is enabled.
|
my-id (auto | fqdn | user-fqdn | key-id; Default: auto) | This parameter sets IKE ID to specified mode. It is possible to manually set two modes FQDN and USER_FQDN.
|
nat-traversal (yes | no; Default: no) | 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. |
notrack-chain (string; Default: ) | Adds raw firewall rules matching ipsec policy to specified chain. |
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. |
policy-template-group (none | string; Default: ) | If generate-policy is enabled, responder checks against templates from the same group. If none of the templates match, Phase2 SA will not be established. |
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. |
proposal (string; Default: default) | Name of the proposal template that will be used during IKE negotiation. |
remote-certificate (string; Default: ) | Name of a certificate (listed in certificate table) for authenticating the remote side (validating packets; no private key required). Applicable if RSA signature authentication method is used. If remote-certificate is not specified then received certificate from remote peer is used and checked against CA in certificate store. Proper CA must be imported in certificate store. |
secret (string; Default: ) | Secret string (in case pre-shared key authentication is used). If it starts with '0x', it is parsed as a hexadecimal value |
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. |
xauth-login (string; Default: ) | initiator (client) XAuth username |
xauth-password (string; Default: ) | initiator (client) XAuth password |
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. |
Note: exchange modes main and l2tp-main are treated the same, so these modes cannot be used select config between multiple peers.
Note: 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.
Peer Proposals
Peer proposal defines a set of parameters that will be used for IKE negotiation during Phase 1.
Properties
Property | Description |
---|---|
dh-group (ec2n155 | ec2n185 | modp1024 | modp1536 | modp2048 | modp3072 | modp4096 | modp6144 | modp768; Default: modp1024) | Diffie-Hellman group (cipher strength) |
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: ) | |
proposal-check (claim | exact | obey | strict; Default: obey) | Phase 2 lifetime check logic:
|
Remote Peers
Sub-menu: /ip ipsec remote-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. |
remote-address (ip/ipv6 address) | Remote peer's ip/ipv6 address. |
responder (yes | no) | Whether the connection is initiated by remote 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". |
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. |
Note: Not all IKE implementations support multiple split networks provided by split-include option.
Note: If RouterOS client is initiator, it will always send CISCO UNITY extension, and RouterOS supports only split-include from this extension.
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:
|
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. |
Users
Sub-menu: /ip ipsec user
The menu consists of list of allowed XAuth users.
Property | Description |
---|---|
address (IP; Default: ) | IP address assigned to the client. If not set dynamic address is used allocated from the address-pool defined in Mode config menu. |
name (string; Default: ) | Username. |
password (string; Default: ) | Password. |
Settings
Sub-menu: /ip ipsec user settings
Property | Description |
---|---|
xauth-use-radius (yes | no; Default: ) | Whether to use Radius client for XAuth users or not. |
Note: Radius accounting currently is not supported by IPsec, only authentication.
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.
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
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.
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 1 configuration
Start off by configuring IPsec peer. It is enough to configure address, auth-method and secret parameters and leaving everything else as default. However, it is possible to set additional Peer properties as long as they are identical between both sites.
/ip ipsec peer add address=192.168.80.1/32 auth-method=pre-shared-key secret="test"
For the next steps, it is important that proposed authentication and encryption algorithms match on both routers. In this example we can use predefined "default" proposal. To verify Proposal settings:
[admin@MikroTik] /ip ipsec proposal print Flags: X - disabled, * - default 0 * name="default" auth-algorithms=sha1 enc-algorithms=aes-256-cbc,aes-192-cbc,aes-128-cbc lifetime=30m pfs-group=modp1024
It is possible to create a new proposal entry for our tunnel and specify it when creating policy, however in this example, the default proposal is used:
/ip ipsec policy add src-address=10.1.202.0/24 src-port=any dst-address=10.1.101.0/24 dst-port=any \ sa-src-address=192.168.90.1 sa-dst-address=192.168.80.1 \ tunnel=yes action=encrypt proposal=default
Site 2 configuration
Office 2 configuration is almost identical as Office 1 with proper IP address configuration.
/ip ipsec peer add address=192.168.90.1/32 auth-method=pre-shared-key secret="test"
Continue with verifying that proposal parameters are matching between the sites:
[admin@MikroTik] /ip ipsec proposal print Flags: X - disabled, * - default 0 * name="default" auth-algorithms=sha1 enc-algorithms=aes-256-cbc,aes-192-cbc,aes-128-cbc lifetime=30m pfs-group=modp1024
When it is done, create an IPsec 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 \ sa-src-address=192.168.80.1 sa-dst-address=192.168.90.1 \ tunnel=yes action=encrypt proposal=default
At this point, the tunnel should be established and two 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 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
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 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 CPU if there is a fair amount of tunnels and significant traffic on each tunnel.
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%.
/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 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.
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
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
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 (RoadWarrior client) and a device running RouterOS acting as a server.
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, IPsec can be configured. Mode config is used for address distribution from IP pool and DNS configuration. 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. For compatibility, a new proposal is created with PFS group set to none.
/ip pool add name=rw-pool ranges=192.168.77.2-192.168.77.254 /ip ipsec proposal add name=rw-proposal pfs-group=none /ip ipsec mode-conf add name=rw-conf system-dns=yes address-pool=rw-pool address-prefix=32 /ip ipsec policy group add name=rw-policies add template=yes dst-address=192.168.77.0/24 group=rw-policies proposal=rw-proposal
Lastly, create a new IPsec peer configuration.
/ip ipsec peer add auth-method=rsa-signature certificate=server1 generate-policy=port-strict \ mode-config=rw-conf passive=yes remote-certificate=none exchange-mode=ike2 \ policy-template-group=rw-policies
Note: Windows uses point-to-point links so specifying any prefix other than 32 in Mode config settings will do nothing
Note: Currently RouterOS does not support any of EAP authentication methods
Note: Most commonly available IKEv2 client software does not support Mode config split-network option
RouterOS client configuration
Generate a new certificate for the client and sign it with previously created CA. Export the client certificate in PKCS12 format.
/certificate add common-name=RouterOS_client name=RouterOS_client key-usage=tls-client sign RouterOS_client ca=ca export-certificate RouterOS_client export-passphrase=1234567890 type=pkcs12
A file named cert_export_RouterOS_client.p12 is now located in the routers Files section. Transfer the file to the RouterOS client device and import it.
/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. Usually the client certificate is imported first, but lets double check which is it.
/put [/certificate get [find common-name=RouterOS_client] name]
cert_export_RouterOS_client.p12_0 is the client certificate. Now we can create the peer configuration.
/ip ipsec peer add address=2.2.2.2 auth-method=rsa-signature certificate=cert_export_RouterOS_client.p12_0 mode-config=request-only exchange-mode=ike2 generate-policy=port-strict
Verify that the connection is successfully established.
/ip ipsec remote-peers print installed-sa print
Windows client configuration
Generate a new certificate for the client and sign it with previously created CA. Export the client certificate in PKCS12 format.
/certificate add common-name=Windows_client name=Windows_client key-usage=tls-client sign Windows_client ca=ca export-certificate Windows_client export-passphrase=1234567890 type=pkcs12
A file named cert_export_Windows_client.p12 is now located in the routers Files section. Download and open the certificate file on the Windows computer. Install the certificate by following the instructions. Make sure you select Local Machine store location.
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.
Currently Windows 10 is compatible with the following Phase 1 (Peer) and Phase 2 (Proposal) proposal sets:
Phase 1 | ||
---|---|---|
Hash Algorithm | Encryption Algorithm | DH Group |
SHA1 | 3DES | modp1024 |
SHA256 | 3DES | modp1024 |
SHA1 | AES-128-CBC | modp1024 |
SHA256 | AES-128-CBC | modp1024 |
SHA1 | AES-192-CBC | modp1024 |
SHA256 | AES-192-CBC | modp1024 |
SHA1 | AES-256-CBC | modp1024 |
SHA256 | AES-256-CBC | modp1024 |
SHA1 | AES-128-GCM | modp1024 |
SHA256 | AES-128-GCM | modp1024 |
SHA1 | AES-256-GCM | modp1024 |
SHA256 | AES-256-GCM | modp1024 |
Phase 2 | ||
---|---|---|
Hash Algorithm | Encryption Algorithm | PFS Group |
SHA1 | AES-256-CBC | none |
SHA1 | AES-128-CBC | none |
SHA1 | 3DES | none |
SHA1 | DES | none |
SHA1 | none | none |
Warning: Phase 2 (/ip ipsec proposal) PFS Group must be set to 'none' for rekeying to work properly.
Android Client Notes
Native Android client does not support ikev2 at the moment. StrongSwan client from Play Store can be used to connect to ikev2 server. 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:
Now you can pick them in profile configuration.
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.
When connecting Android StrongSwan clients, make sure that on RouterOS proposal settings DH group is disabled, otherwise phase2 will fail.
macOS client configuration
Generate a new certificate for the client and sign it with previously created CA. Export the client certificate in PKCS12 format.
/certificate add common-name=macOS_client name=macOS_client key-usage=tls-client sign macOS_client ca=ca export-certificate macOS_client export-passphrase=1234567890 type=pkcs12
A file named cert_export_macOS_client.p12 is now located in the routers Files section. Download and open the 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.
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.
Currently macOS is compatible with the following Phase 1 (Peer) and Phase 2 (Proposal) proposal sets:
Phase 1 | ||
---|---|---|
Hash Algorithm | Encryption Algorithm | DH Group |
SHA256 | AES-256-CBC | modp2048 |
SHA256 | AES-256-CBC | ecp256 |
SHA256 | AES-256-CBC | modp1536 |
SHA1 | AES-128-CBC | modp1024 |
SHA1 | 3DES | modp1024 |
Phase 2 | ||
---|---|---|
Hash Algorithm | Encryption Algorithm | PFS Group |
SHA256 | AES-256-CBC | none |
SHA1 | AES-128-CBC | none |
SHA1 | 3DES | none |
Warning: Phase 2 (/ip ipsec proposal) PFS Group must be set to 'none' for rekeying to work properly.
iOS client configuration
Generate a new certificate for the client and sign it with previously created CA.
/certificate add common-name=iOS_client name=iOS_client key-usage=tls-client sign iOS_client ca=ca
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.
/certificate export-certificate ca type=pem export-certificate iOS_client type=pkcs12 export-passphrase=1234567890
Two files are now located in the routers Files section: cert_export_ca.crt and cert_export_iOS_client.p12. 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.
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.
Currently iOS is compatible with the following Phase 1 (Peer) and Phase 2 (Proposal) proposal sets:
Phase 1 | ||
---|---|---|
Hash Algorithm | Encryption Algorithm | DH Group |
SHA256 | AES-256-CBC | modp2048 |
SHA256 | AES-256-CBC | ecp256 |
SHA256 | AES-256-CBC | modp1536 |
SHA1 | AES-128-CBC | modp1024 |
SHA1 | 3DES | modp1024 |
Phase 2 | ||
---|---|---|
Hash Algorithm | Encryption Algorithm | PFS Group |
SHA256 | AES-256-CBC | none |
SHA1 | AES-128-CBC | none |
SHA1 | 3DES | none |
Warning: Phase 2 (/ip ipsec proposal) PFS Group must be set to 'none' for rekeying to work properly.
Note: If you are connected to the VPN over WiFi, the iOS device can go into sleep mode and disconnect from the network.
strongSwan client configuration
Generate a new certificate for the client and sign it with previously created CA. Export both client and CA certificates in PEM format.
/certificate add common-name=strongSwan_client name=strongSwan_client key-usage=tls-client sign strongSwan_client ca=ca export-certificate ca export-certificate strongSwan_client export-passphrase=1234567890
Three files are now located in the routers Files section: cert_export_ca.crt, cert_export_strongSwan_client.crt and cert_export_strongSwan_client.key. strongSwan accepts either PEM or DER format certificates and it is possible to just change the certificate extensions. The private key must be in PKCS1 format - it will need to be converted. We can do this with OpenSSL. Rename the certificates for a more convenient look.
$ mv cert_export_ca.crt ca.pem $ mv cert_export_strongSwan_client.crt strongSwan_client.pem $ openssl rsa -in cert_export_strongSwan_client.key -out strongSwan_clientKey.pem
Download the certificates and the key to strongSwan client device and move the files to their appropriate directory. By default /etc/ipsec.d/ is used for certificate storage.
$ mv ca.pem /etc/ipsec.d/cacerts/ca.pem $ mv strongSwan_client.pem /etc/ipsec.d/certs/strongSwan_client.pem $ mv strongSwan_clientKey.pem /etc/ipsec.d/private/strongSwan_client.pem
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.pem leftfirewall=yes right=2.2.2.2 rightid="CN=2.2.2.2" rightsubnet=0.0.0.0/0 auto=add
Add exported passphrase for the private key to /etc/ipsec.secrets file
: RSA strongSwan_client.pem "1234567890"
You can now restart (or start) the ipsec daemon and initialize the connection
$ ipsec restart $ ipsec up ikev2
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
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.
Connecting with Shrew Client and allowing only Encrypted traffic
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 ]