manual ip ipsec

17
Manual:IP/IPsec 1 Manual:IP/IPsec Applies to RouterOS: v5.0 + Summary Sub-menu: /ip ipsec Package required: security Standards: RFC 4301 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: Authentication Header (AH) RFC 4302 Encapsulating Security Payload (ESP) RFC 4303 Internet Key Exchange (IKE) protocols. Dynamically generates and distributes cryptographic keys for AH and ESP. 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 used to provide encryption). RouterOS supports the following authentication algorithms for AH: 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 Encapsulating Security Payload (ESP) uses shared key encryption to provide data privacy. ESP also supports its own authentication scheme like that used in AH, or can be used in conjunction with 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:

Upload: abdullah-al-mahmud

Post on 14-Apr-2015

74 views

Category:

Documents


5 download

DESCRIPTION

Ip configuration for voip

TRANSCRIPT

Page 1: Manual IP IPsec

Manual:IP/IPsec 1

Manual:IP/IPsecApplies to RouterOS: v5.0 +

SummarySub-menu: /ip ipsecPackage required: securityStandards: RFC 4301Internet Protocol Security (IPsec) is a set of protocols defined by the Internet Engineering Task Force (IETF) tosecure packet exchange over unprotected IP/IPv6 networks such as Internet.IpSec protocol suite can be divided in following groups:• Authentication Header (AH) RFC 4302• Encapsulating Security Payload (ESP) RFC 4303• Internet Key Exchange (IKE) protocols. Dynamically generates and distributes cryptographic keys for AH and

ESP.

Authentication Header (AH)AH is a protocol that provides authentication of either all or part of the contents of a datagram through the additionof a header that is calculated based on the values in the datagram. What parts of the datagram are used for thecalculation, 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, AHprovides authentication but not privacy (Another protocol ESP is used to provide encryption).RouterOS supports the following authentication algorithms for AH:•• SHA1•• MD5

Transport modeIn 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 modeIn tunnel mode original IP packet is encapsulated within a new IP packet. All of the original IP packet isauthenticated.

Encapsulating Security PayloadEncapsulating Security Payload (ESP) uses shared key encryption to provide data privacy. ESP also supports its ownauthentication scheme like that used in AH, or can be used in conjunction with AH.ESP packages its fields in a very different way than AH. Instead of having just a header, it divides its fields intothree components:

Page 2: Manual IP IPsec

Manual:IP/IPsec 2

• ESP Header - Comes before the encrypted data and its placement depends on whether ESP is used in transportmode or tunnel mode.

• ESP Trailer - This section is placed after the encrypted data. It contains padding that is used to align theencrypted data.

• ESP Authentication Data - This field contains an Integrity Check Value (ICV), computed in a manner similar tohow the AH protocol works, for when ESP's optional authentication feature is used.

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

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

Encryption algorithmsRouterOS ESP supports various encryption and authentication algorithms.Authentication:•• SHA1•• MD5Encryption:• DES - 56-bit DES-CBC encryption algorithm;• 3DES - 168-bit DES encryption algorithm;• AES - 128, 192 and 256-bit key AES-CBC encryption algorithm;• Blowfish - added since v4.5• Twofish - added since v4.5• Camellia - 128, 192 and 256-bit key Camellia encryption algorithm added since v4.5

Hardware encryptionHardware encryption allows to do faster encryption process by using built-in encryption engine inside CPU. AES isthe only algorithm that will be accelerated in hardware.List of RouterBoards with enabled hardware support:•• RB1000•• RB1100AHx2For comparison RB1000 with enabled HW support can forward up to 550Mbps encrypted traffic. When HW supportis disabled it can forward only 150Mbps encrypted traffic in AES-128 mode.Some configuration advices on how to get maximum ipsec throughput on multicore RB1100AHx2:•• Avoid using ether12 and ethet13. Since these prots are pci-x they will be slowest ones.•• Fastest forwarding is from switch chip ports (ether1-ether10) to ether11 (directly connected to CPU) and vice

versa.•• Set hardware queue on all interfaces

/queue interface set [find] queue=only-hardware-queue

•• Disable RPS:

/system resource irq rps disable [find]

Page 3: Manual IP IPsec

Manual:IP/IPsec 3

•• Assign one CPU core to ether11 and other CPU core to everything else. Forwarding over ether11 requires moreCPU that is why we are giving one core only for that interface (in IRQ setting ether11 is listed as ether12 tx,rxand error).

/system resource irq

set [find] cpu=1

set [find users="eth12 tx"] cpu=0

set [find users="eth12 rx"] cpu=0

set [find users="eth12 error"] cpu=0

•• disable connection trackingWith all above recommendations it is possible to forward 820Mbps (1470byte packets two streams).With enabled connection tracking 700Mbps (1470 byte packets two streams).

Internet Key Exchange ProtocolThe Internet Key Exchange (IKE) is a protocol that provides authenticated keying material for Internet SecurityAssociation and Key Management Protocol (ISAKMP) framework. There are other key exchange schemes that workwith ISAKMP, but IKE is the most widely used one. Together they provide means for authentication of hosts andautomatic 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 policydoesn't have any SAs. The policy notifies IKE daemon about that, and IKE daemon initiates connection to remotehost. 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 isgenerated 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 byIKE daemon will have lifetime values (either limiting time, after which SA will become invalid, or amount ofdata 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

Page 4: Manual IP IPsec

Manual:IP/IPsec 4

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

IKE can optionally provide a Perfect Forward Secrecy (PFS), which is a property of keyexchanges, 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 anadditional keying material is generated for each phase 2.Generation of keying material is computationally very expensive. Exempli gratia, the use of modp8192 group cantake several seconds even on very fast computer. It usually takes place once per phase 1 exchange, which happensonly once between any host pair and then is kept for long time. PFS adds this expensive operation also to each phase2 exchange.

Diffie-Hellman GroupsDiffie-Hellman (DH) key exchange protocol allows two parties without any initial shared secret to create onesecurely. 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

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

Setup ProcedureTo get IPsec to work with automatic keying using IKE-ISAKMP you will have to configure policy, peer andproposal (optional) entries.

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

Page 5: Manual IP IPsec

Manual:IP/IPsec 5

Peer configurationSub-menu: /ip ipsec peerPeer configuration settings are used to establish connections between IKE daemons ( phase 1 configuration). Thisconnection then will be used to negotiate keys and algorithms for SAs.

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 authenticationand establishment of Phase 1. If several peer's addresses match several configuration entries, themost specific one (i.e. the one with largest netmask) will be used.

auth-method (pre-shared-key |rsa-signature; Default: pre-shared-key)

Authentication method:

• pre-shared-key - authenticate by a password (secret) string shared between the peers• rsa-signature - authenticate using a pair of RSA certificates• rsa-key - authenticate using a RSA key imported in Ipsec key menu.

certificate (string; Default: ) Name of a certificate listed in certificate table (signing packets; the certificate must have privatekey). Applicable if RSA signature authentication method (auth-method=rsa-signature) is used.

comment (string; Default: ) Short description of the peer.

dh-group (ec2n155 | ec2n185 | modp1024 |modp1536 | modp2048 | modp3072 | modp4096| modp6144 | modp768; Default: modp1024)

Diffie-Hellman group (cipher strength)

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.

enc-algorithm (3des | aes-128 | aes-192 |aes-256 | blowfish | camellia-128 | camellia-192| camellia-256 | des; Default: 3des)

Encryption algorithm.

exchange-mode (aggressive | base | main |main-l2tp; Default: main)

Different ISAKMP phase 1 exchange modes according to RFC 2408. Do not use other modesthen main unless you know what you are doing. main-l2tp mode relaxes rfc2409 section 5.4, toallow pre-shared-key authentication in main mode.

generate-policy (yes | no; Default: no) Allow this peer to establish SA for non-existing policies. Such policies are created dynamicallyfor the lifetime of SA. Automatic policies allows, for example, to create IPsec secured L2TPtunnels, or any other setup where remote peer's IP address is not known at the configuration time.

hash-algorithm (md5 | sha1; Default:md5)

Hashing algorithm. SHA (Secure Hash Algorithm) is stronger, but slower.

key (string; Default: ) Name of the key from key menu. Applicable if auth-method=rsa-key.

lifebytes (Integer: 0..4294967295; Default:0)

Phase 1 lifetime: specifies how much bytes can be transferred before SA is discarded. If set to 0,SA will not be discarded due to byte count excess.

lifetime (time; Default: 1d) Phase 1 lifetime: specifies how long the SA will be valid.

my-id-user-fqdn (string; Default: ) By default IP address is used as ID. This parameter replaces ID with specified value. Can beused, for example, in cases if DNS name as ID is required.

nat-traversal (yes | no; Default: no) Use Linux NAT-T mechanism to solve IPsec incompatibility with NAT routers inbetween IPsecpeers. This can only be used with ESP protocol (AH is not supported by design, as it signs thecomplete packet, including IP header, which is changed by NAT, rendering AH signatureinvalid). The method encapsulates IPsec ESP traffic into UDP streams in order to overcome someminor issues that made ESP incompatible with NAT.

port (integer:0..65535; Default: 500) Communication port used for ipsec traffic.

Page 6: Manual IP IPsec

Manual:IP/IPsec 6

proposal-check (claim | exact | obey |strict; Default: obey)

Phase 2 lifetime check logic:

• claim - take shortest of proposed and configured lifetimes and notify initiator about it• exact - require lifetimes to be the same• obey - accept whatever is sent by an initiator• strict - if proposed lifetime is longer than the default then reject proposal otherwise accept

proposed lifetime

remote-certificate (string; Default: ) Name of a certificate (listed in certificate table) for authenticating the remote side (validatingpackets; no private key required). Applicable if RSA signature authentication method is used

secret (string; Default: ) Secret string (in case pre-shared key authentication is used). If it starts with '0x', it is parsed as ahexadecimal value

send-initial-contact (yes | no; Default:yes)

Specifies whether to send initial IKE information or wait for remote side.

Note: IPSec phases information is erased, when /ip ipsec peer configuration is modified on the fly, howeverpackets are being encrypted/decrypted because of installed-sa (for example remote-peers information iserased, when peer configuration is modified.

KeysSub-menu: /ip ipsec keyThis submenu list all imported public/private keys, that can be used for peer authentication. Submenu also hasseveral commands to work with keys.For example print below shows two imported 1024-bit keys, one public and one private.

[admin@PoETik] /ip ipsec key> print

Flags: P - private-key, R - rsa

# NAME KEY-SIZE

0 PR priv 1024-bit

1 R pub 1024-bit

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

import (file-name; name) Import key from file.

Page 7: Manual IP IPsec

Manual:IP/IPsec 7

PolicySub-menu: /ip ipsec policyPolicy table is used to determine whether security settings should be applied to a packet.

Property Description

action (discard | encrypt | none; Default:encrypt)

Specifies what to do with packet matched by the policy.

• none - pass the packet unchanged• discard - drop the packet• encrypt - apply transformations specified in this policy and it's SA

comment (string; Default: ) Short description of the policy

disabled (yes | no; Default: no) Whether policy is used to match packets.

dst-address (IP/IPv6 prefix; Default:0.0.0.0/32)

Destination address to be matched in packets.

dst-port (integer:0..65535 | any; Default: any) Destination port to be matched in packets. If set to any all ports will be matched

ipsec-protocols (ah | esp; Default: esp) Specifies what combination of Authentication Header and Encapsulating Security Payloadprotocols you want to apply to matched traffic

level (require | unique | use; Default: require) Specifies what to do if some of the SAs for this policy cannot be found:

• use - skip this transform, do not drop packet and do not acquire SA from IKE daemon• require - drop packet and acquire SA• unique - drop packet and acquire a unique SA that is only used with this particular

policy

manual-sa (string | none; Default: none) Name of the manual SA template

priority (integer:-2147483646..2147483647;Default: 0)

Policy ordering classificator (signed integer). Larger number means higher priority.

proposal (string; Default: default) Name of the proposal template that will be sent by IKE daemon to establish SAs for thispolicy.

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 IP prefix

src-port (any | integer:0..65535; Default: any) Source Port of the packet

tunnel (yes | no; Default: no) Specifies whether to use tunnel mode

Note: All packets are IPIP encapsulated in tunnel mode, and their new IP header's src-address and dst-addressare set to sa-src-address and sa-dst-address values of this policy. If you do not use tunnel mode (id est you usetransport mode), then only packets whose source and destination addresses are the same as sa-src-address andsa-dst-address can be processed by this policy. Transport mode can only work with packets that originate atand 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.

Page 8: Manual IP IPsec

Manual:IP/IPsec 8

Policy StatsCommand /ip ipsec policy print stats will show current status of the policy. Additional read-onlyparameters will be printed.

Property Description

in-accepted (integer) How many incoming packets were passed by the policy without an attempt to decrypt.

in-dropped (integer) How many incoming packets were dropped by the policy without an attempt to decrypt

in-transformed (integer) How many incoming packets were decrypted (ESP) and/or verified (AH) by the policy

out-accepted (integer) How many outgoing packets were passed by the policy without an attempt to encrypt.

out-dropped (integer) How many outgoing packets were dropped by the policy without an attempt to encrypt.

out-transformed (integer) How many outgoing packets were encrypted (ESP) and/or verified (AH) by the policy.

ph2-state (expired | no-phase2 | established) Indication of the progress of key establishing.

Dumping PoliciesIt is possible to dump policies installed into the kernel for debugging purposes with command:

/ip ipsec policy dump-kernel-policies

After executing this command check the logs to see the result, there should be three policies in the kernel: forward,in and out.

[admin@test-host] >/log print

07:28:34 ipsec,debug,packet policy ipsec fwd: 10.5.101.9[0] - 10.5.101.13[0]

07:28:34 ipsec,debug,packet policy ipsec in: 10.5.101.9[0] - 10.5.101.13[0]

07:28:34 ipsec,debug,packet policy ipsec out: 10.5.101.13[0] - 10.5.101.9[0]

Proposal settingsSub-menu: /ip ipsec proposalProposal information that will be sent by IKE daemon to establish SAs for this policy ( Phase 2). Configuredproposals are set in policy configuration.

Property Description

auth-algorithms (md5|sha1|null; Default: sha1) Allowed algorithms forauthorization. sha1 is stronger, butslower algorithm.

comment (string; Default: ) Short description of an item.

disabled (yes | no; Default: no) Whether item is disabled.

enc-algorithms

(null|des|3des|aes-128|aes-192|aes-256|blowfish|camellia-128|camellia-192|camellia-256|twofish; Default:3des)

Allowed algorithms and keylengths to use for SAs.

lifetime (time; Default: 30m) How long to use SA beforethrowing it out.

name (string; Default: ) Name of the proposal template,that will be identified in otherparts of ipsec configuration.

pfs-group (ec2n155 | ec2n185 | modp1024 | modp1536 | modp2048 | modp3072 | modp4096 | modp6144 |modp768 | none; Default: modp1024)

Diffie-Helman group used forPerfect Forward Secrecy.

Page 9: Manual IP IPsec

Manual:IP/IPsec 9

Manual SASub-menu: /ip ipsec manual-saMenu is used to configure SAs manually. Created SA template then can be used in policy configuration.

Property Description

ah-algorithm (in/outin,out = md5|null|sha1; Default: null)

Authentication Header encryption algorithm.

ah-key (string/string; Default: ) Incoming-authentication-key/outgoing-authentication-key

ah-spi (0x100..FFFFFFFF/0x100..FFFFFFFF; Default: 0x100) Incoming-SA-SPI/outgoing-SA-SPI

disabled (yes | no; Default: no) Defines whether item is ignored or used

esp-auth-algorithm (in/outin,out = md5|null|sha1; Default: null)

Encapsulating Security Payload authentication encryption algorithm

esp-auth-key (string/string; Default: ) Incoming-authentication-key/outgoing -authentication-key

esp-enc-algorithm (in/outin,out = 3des | aes-128 | aes-192 | aes-256 | des | ...; Default: null)

Incoming-encryption-algorithm

esp-enc-key (string/string; Default: ) Incoming-encryption-key/outgoing-encryption-key

esp-spi (0x100..FFFFFFFF/0x100..FFFFFFFF; Default: 0x100) Incoming-SA-SPI/outgoing-SA-SPI

lifetime (time; Default: 0s) Lifetime of this SA

name (string; Default: ) Name of the item for reference from policies

Installed SASub-menu: /ip ipsec installed-saThis facility provides information about installed security associations including the keys.

Property Description

AH (yes | no)

ESP (yes | no)

add-lifetime (time/time) Added lifetime for the SA in format soft/hard

•• soft - time period after which ike will try to establish new SA•• hard - time period after which SA is deleted

addtime (time) Date and time when this SA was added.

auth-algorithm (sha1 | md5) Shows currently used authentication algorithm

auth-key (string) Shows used authentication key

current-bytes (integer) Shows number of bytes seen by this SA.

dst-address (IP)

enc-algorithm (des | 3des | aes ...) Shows currently used encryption algorithm

pfs (yes | no)

replay (integer)

spi (string)

src-address (IP)

Page 10: Manual IP IPsec

Manual:IP/IPsec 10

state (string) Shows the current state of the SA ("mature", "dying" etc)

Flushing SAsSometimes after incorrect/incomplete negotiations took place, it is required to flush manually the installed SA tableso that SA could be renegotiated. This option is provided by the /ip ipsec installed-sa flushcommand.This command accepts only one property:

Property Description

sa-type (ah | all | esp; Default: all) Specifies SA types to flush:

• ah - delete AH protocol SAs only• esp - delete ESP protocol SAs only• all - delete both ESP and AH protocols SAs

Remote PeersSub-menu: /ip ipsec remote-peersThis submenu provides you with various statistics about remote peers that currently have established phase 1connections with this router. Note that if peer doesn't show up here, it doesn't mean that no IPsec traffic is beingexchanged with it.Read only properties:

Property Description

local-address (ip/ipv6address)

Local ISAKMP SA address on the router used by the peer

remote-address (ip/ipv6address)

Remote peer's ip/ipv6 address

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 showstate "established".

established (time) How long peers are in established state.

Closing all IPsec connectionsMenu has a command to quickly close all established ipsec connections. This command will clear all installed SAs(Phase2) and remove all entries from remote-peers menu (Phase1).Usage:

/ip ipsec remote-peers kill-connections

StatisticsSub-menu: /ip ipsec statisticsThis menu shows various ipsec statistics

Page 11: Manual IP IPsec

Manual:IP/IPsec 11

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

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

Page 12: Manual IP IPsec

Manual:IP/IPsec 12

Application Examples

Site to Site IpSec TunnelConsider setup as illustrated below

Two remote office routers are connected to internet and office workstations behind routers are NATed. Each officehas its own local subnet, 10.1.202.0/24 for Office1 and 10.1.101.0/24 for Office2. Both remote offices needs securetunnel to local networks behind routers.

IP Connectivity

On both routers ether1 is used as wan port and ether2 is used to connect workstations. Also NAT rules are set tumasquerade local networks.Office1 router:

/ip address

add address=192.168.90.1/24 interface=ether1

add address=10.1.202.1/24 interface=ether2

/ip route

add gateway=192.168.90.254

/ip firewall nat

add chain=srcnat out-interface=ether1 action=masquerade

Office2 router:

/ip address

add address=192.168.80.1/24 interface=ether1

add address=10.1.101.1/24 interface=ether2

/ip route

add gateway=192.168.80.254

Page 13: Manual IP IPsec

Manual:IP/IPsec 13

/ip firewall nat

add chain=srcnat out-interface=ether1 action=masquerade

IpSec Peer's config

Next step is to add peer's configuration. We need to specify peers address and port and pre-shared-key. Otherparameters are left to default values.Office1 router:

/ip ipsec peer

add address=192.168.80.1/32 port=500 auth-method=pre-shared-key secret="test"

Office2 router:

/ip ipsec peer

add address=192.168.90.1/32 port=500 auth-method=pre-shared-key secret="test"

Policy and proposal

It is important that proposed authentication and encryption algorithms match on both routers. In this example we canuse predefined "default" proposal

[admin@MikroTik] /ip ipsec proposal> print

Flags: X - disabled

0 name="default" auth-algorithms=sha1 enc-algorithms=3des lifetime=30m

pfs-group=modp1024

As we already have proposal as a next step we need correct IpSec policy. We want to encrypt traffic coming form10.1.202.0/24 to 10.1.101.0/24 and vice versa.Office1 router:

/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

Office2 router:

/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

Note that we configured tunnel mode instead of transport, as this is site to site encryption.

Page 14: Manual IP IPsec

Manual:IP/IPsec 14

NAT Bypass

At this point if you will try to establish IpSec tunnel it will not work, packets will be rejected. This is because bothrouters have NAT rules that is changing source address after packet is encrypted. Remote router reiceves encryptedpacket but is unable to decrypt it because source address do not match address specified in policy configuration. Formore information see packet flow ipsec example.To fix this we need to set up NAT bypass rule.Office1 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

Office2 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

It is very important that bypass rule is placed at the top of all other NAT rules.Note: If you previously tried to establish tunnel before NAT bypass rule was added, you have to clearconnection table from existing connection or restart the routers

Ipsec/L2TP behind NAT

Consider setup as illustrated below

Client needs secure connection to the office with public address 1.1.1.1, but server does not know what will be thesource address from which client connects. It is so called road-warrior setup. Our client will also be located behindthe router with enabled NAT.For the setup RouterOS router will be used as the client device behind NAT (it can be any device: Windows PC,Smartphone, Linux PC, etc.)

Page 15: Manual IP IPsec

Manual:IP/IPsec 15

IP Connectivity

On the server:

/ip address

add address=1.1.1.1/24 interface=ether1

/ip route

add gateway=1.1.1.2

On the clients router:

/ip address

add address=2.2.2.2/24 interface=ether1

add address=10.5.8.0/24 interface=ether2

/ip route

add gateway=2.2.2.1

/ip firewall net

add chain=srcnat action=masquerade out-interface=ether1

On the client:

/ip address

add address=10.5.8.120/24 interface=ether1

L2TP Config

On the server:

/interface l2tp-server

set enabled=yes profil=default

/ip pool

add name=l2tp-pool ranges=192.168.1.2-192.168.1.20

/ppp profile

set default local-address=192.168.1.1 remote-address=l2tp-pool

/ppp secret

add name=l2tp-test password=test123456

On the client:

/interface l2tp-client

add connect-to=1.1.1.1 disabled=no name=l2tp-out1 password=password user=l2tp-test

Page 16: Manual IP IPsec

Manual:IP/IPsec 16

IpSec Config

On server side:

/ip ipsec proposal

set [ find default=yes ] enc-algorithms=3des,aes-128,aes-192,aes-256

/ip ipsec peer

add generate-policy=yes hash-algorithm=sha1 nat-traversal=yes secret=test123456 \

send-initial-contact=no

RouterOS as client:

/ip ipsec proposal

set [ find default=yes ] enc-algorithms=aes-128

/ip ipsec peer

add address=1.1.1.1/32 hash-algorithm=sha1 nat-traversal=yes secret=test123456

/ip ipsec policy

add dst-address=1.1.1.1/32 protocol=udp sa-dst-address=1.1.1.1 \

sa-src-address=10.5.8.120 src-address=10.5.8.120/32

Notice that nat-traversal is enabled. This option is required because Ipsec connection will be establishedthrough the NAT router otherwise Ipsec will not be able to establish phase2.

Note: Only one L2TP/ipsec connection can be established through the NAT. Which means that only oneclient can connect to the sever located behind the same router.

Connecting with Shrew Client and allowing only Encrypted traffic

•• See example here

[ Top | Back to Content ]

Page 17: Manual IP IPsec

Article Sources and Contributors 17

Article Sources and ContributorsManual:IP/IPsec  Source: http://wiki.mikrotik.com/index.php?oldid=24791  Contributors: Eep, Eugene, Janisk, Marisb, Normis, SacXs2, Sergejs, SergejsB

Image Sources, Licenses and ContributorsImage:Version.png  Source: http://wiki.mikrotik.com/index.php?title=File:Version.png  License: unknown  Contributors: NormisImage:Icon-note.png  Source: http://wiki.mikrotik.com/index.php?title=File:Icon-note.png  License: unknown  Contributors: Marisb, RouteImage:Icon-warn.png  Source: http://wiki.mikrotik.com/index.php?title=File:Icon-warn.png  License: unknown  Contributors: Marisb, Routefile:site-to-site-ipsec-example.png  Source: http://wiki.mikrotik.com/index.php?title=File:Site-to-site-ipsec-example.png  License: unknown  Contributors: Marisbfile:ipsec-l2tp-example.png  Source: http://wiki.mikrotik.com/index.php?title=File:Ipsec-l2tp-example.png  License: unknown  Contributors: Marisb