Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrating application guides

...

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

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

EAP-SIM
EAP-TLS
EAP-TTLS

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

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

Authentication Header (AH)

...

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


Properties

PropertyDescription
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

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

Groups

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

...

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

PropertyDescription
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

PropertyDescription
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.

...

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


Read only properties

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

Profiles

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.

...

PropertyDescription
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:
  • claim - take shortest of proposed and configured lifetimes and notify initiator about it
  • exact - require lifetimes to be the same
  • obey - accept whatever is sent by an initiator
  • strict - if the proposed lifetime is longer than the default then reject the proposal otherwise accept a proposed lifetime

Active Peers

...

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

...

PropertyDescription
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)Total The total amount of active IPsec security associations.
remote-address (ip/ipv6 address)Remote The remote peer's ip/ipv6 address.
responder (yes | no)Whether the connection is initiated by a remote peer.
rx-bytes (integer)Total The total amount of bytes received from this peer.
rx-packets (integer)Total 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)Total The total amount of bytes transmitted to this peer.
tx-packets (integer)Total The total amount of packets transmitted to this peer.
uptime (time)How long peers are in an established state.


Commands

...

PropertyDescription
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. RoadWarrior client 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.

...

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


Read-only properties

PropertyDescription
AH (yes | no)Whether AH protocol is used by this SA.
ESP (yes | no)Whether ESP protocol is used by this SA.
add-lifetime (time/time)Added lifetime for the SA in format soft/hard:
  • soft - time period after which
ike
  • IKE will try to establish new SA;
  • hard - time period after which SA is deleted.
addtime (time)Date and time when this SA was added.
auth-algorithm (md5 | null | sha1 | ...)Currently used authentication algorithm.
auth-key (string)Used authentication key.
current-bytes (64-bit integer)
Number
A number of bytes seen by this SA.
dst-address (IP)
Destination
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)
Source
The source address of this SA.
state (string)Shows the current state of the SA ("mature", "dying" etc)


Commands

PropertyDescription
flush ()Manually removes all installed security associations.

Keys

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

PropertyDescription
name (string; Default: )


Read-only properties

PropertyDescription
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
an RSA key.


Commands

PropertyDescription
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.

Settings


PropertyDescription
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: )
Interval
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.


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 A tunnel is established, a local mode-config IP address is received and a set of dynamic policies are generated.

Code Block
languageros
[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 which that contains of all local networks that the NAT rule should be applied. In our case, it is 192.168.88.0/24.

...

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

...

Code Block
languageros
[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

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 nonencrypted 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

Let's set up an IPsec policy matcher to accept all packets that matched any of the IPsec policies and drop the rest:

Code Block
languageros
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:

Code Block
languageros
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:

Code Block
languageros
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 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:

Code Block
languageros
/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.

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.


Code Block
languageros
[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 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.

Code Block
languageros
[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.

Code Block
languageros
/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:

Code Block
languageros
/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 the 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.

Code Block
languageros
[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.

Code Block
languageros
/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.

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