3. IPSec tunnel

3.1. Configuration

We'll create an IPSec tunnel between R1 and R3. This means that we will no longer see the 10.128.x.x traffic on R2, if everything goes as planned.

The Internet Key Exchange must be enabled first on the routers R1 and R3. Remember that with Cisco, there is no real distinction between ISAKMP and IKE.

(config)#crypto isakmp enable

So, next we'll take the following steps:

  • Establish an ISAKMP policy
  • Configure pre-shared keys
  • Configure the IPsec transform set
  • Define interesting traffic
  • Apply the crypto map to interfaces

For both routers, we use the following ISAKMP policy:

 config t
  crypto isakmp policy 10
  hash sha
  authentication pre-share
  group 14
  lifetime 3600
  encryption aes 256

crypto isakmp policy 10 creates a policy with a priority of 10. 1 is the highest priority, and 10 seems to be a more or less standard priority. As a hashing agorithm, we'll use SHA. That means SHA-1, which is not considered fit for use in the outside world. But this is only a demo environment. We'll use pre-shared keys for the initial set-up. group 14 means 2048-bit Diffie-Hellman group. And the rest is easy to understand.

The set-up is easy to verify:

R1# show crypto isakmp policy
Global IKE policy
Protection suite of priority 10
        encryption algorithm:  AES - Advanced Encryption Standard (256 bit keys).
        hash algorithm:        Secure Hash Standard
        authentication method: Pre-Shared Key
        Diffie-Hellman group:  #14 (2048 bit)
        lifetime:              3600 seconds, no volume limit

The next step is to configure the pre-shared keys. IRL, you would not use test123 as key, ofcourse. Both sides must have the same key. For R1, that would be:

 crypto isakmp key test123 address

and for R3:

 crypto isakmp key test123 address

Next is the transform set. A transform is a single IPSec security protocol (either AH or ESP) with its corresponding security algorithms and mode.

The AH (Authentication Header) is mainly used for authentication. In addition, AH provides data integrity, data origin authentication, and an optional replay protection service. Data integrity is ensured by using a message digest that is generated by an algorithm such as HMAC-SHA that we use here. Data origin authentication is ensured by using a shared secret key to create the message digest. Replay protection is provided by using a sequence number field with the AH header. AH authenticates IP headers and their payloads, with the exception of certain header fields that can be legitimately changed in transit, such as the Time To Live (TTL) field.

The ESP (Encapsulating Security Payload) protocol provides data confidentiality (encryption) and authentication (data integrity, data origin authentication, and replay protection). ESP can be used with confidentiality only, authentication only, or both confidentiality and authentication. When ESP provides authentication functions, it uses the same algorithms as AH, but the coverage is different. AH-style authentication authenticates the entire IP packet, including the outer IP header, while the ESP authentication mechanism authenticates only the IP datagram portion of the IP packet.

Either protocol can be used alone to protect an IP packet, or both protocols can be applied together to the same IP packet

We'll use ESP in this case. We define the transform set on both routers with:

crypto ipsec transform-set 50 esp-aes 256 esp-sha-hmac

Next step: define interesting traffic, that is, what traffic should go through the tunnel. Whenever Cisco defines something about traffic, it is always done with an ACL. So here too, we'll create an ACL. For R1:

 access-list 101 permit ip

and for R3:

 access-list 101 permit ip

A crypto map is a configuration entity that combines:

  • Selection data flows that need security processing.
  • Definition the policy for these flows and the crypto peer to which that traffic needs to go.

We define it as follows (for R1):

 crypto map CMAP 10 ipsec-isakmp
 match address 101
 set peer
 set pfs group14
 set transform-set 50
 set security-association lifetime seconds 900

The CMAP is the name of the crypto map and 10 its sequence number. The ipsec-isakmp is the type for this crypto map. The selection of the addresses is done with the ACL that we defined (101). The peer is R3.

PFS, or Perfect Forward Security, ensures will force a new key every set-up, and a Diffie-Hellman key exchange.

No longer recommended
No longer recommended
No longer recommended
elliptic curve DH (ECDH)

The transform-set is defined previously. The lifetime is, at this point quite arbitrary.

And finaly, we apply the crypto map to the outgoing interface of the router:

 int f0/0
 crypto map CMAP

For R3, the only difference is the set peer (R1 is the peer here).

3.2. Analysis

And after a ping fron xenial1 to xenial2, the tunnel is up before we can fire-up wireshark. Which is good, but does not allow us to examine what is happening. So we just reload R3 (be sure to wr to save the configuration!). After some OSPF packets, we see the ISAKMP:


We'll try to match that with the protocol as we know it from text books:


Our first packet contains ISAKMP headers and the SA proposal. It is an UDPs 500 packet from R3 (the initiator) to R2.

Frame 159: 206 bytes on wire (1648 bits), 206 bytes captured (1648 bits) on interface 0
Ethernet II, Src: ca:02:52:6d:00:08 (ca:02:52:6d:00:08), Dst: ca:01:52:6d:00:06 (ca:01:52:6d:00:06)
Internet Protocol Version 4, Src:, Dst:
User Datagram Protocol, Src Port: 500 (500), Dst Port: 500 (500)
    Source Port: 500
    Destination Port: 500
    Length: 172
    Checksum: 0x8da5 [validation disabled]
    [Stream index: 0]

The protocol is ISAKMP. To focus on specific lines, I've removed some lines that are less interesting at this point.

Internet Security Association and Key Management Protocol
    Initiator SPI: 9e8a87000c6619ff
    Responder SPI: 0000000000000000
    Next payload: Security Association (1)
    Type Payload: Proposal (2) # 1
        Proposal transforms: 1
            Type Payload: Transform (3) # 1
            Next payload: NONE / No Next Payload  (0)
            Payload length: 36
            Transform number: 1
            Transform ID: KEY_IKE (1)
            Transform IKE Attribute Type (t=1,l=2) Encryption-Algorithm : AES-CBC
            Transform IKE Attribute Type (t=14,l=2) Key-Length : 256
            Transform IKE Attribute Type (t=2,l=2) Hash-Algorithm : SHA
            Transform IKE Attribute Type (t=4,l=2) Group-Description : 2048 bit MODP group
            Transform IKE Attribute Type (t=3,l=2) Authentication-Method : PSK
            Transform IKE Attribute Type (t=11,l=2) Life-Type : Seconds
            Transform IKE Attribute Type (t=12,l=2) Life-Duration : 3600
            Type Payload: Vendor ID (13) : RFC 3947 Negotiation of NAT-Traversal in the IKE
    Next payload: Vendor ID (13)

Here we see the result of our IOS configs:

crypto isakmp policy 10
hash sha
Hash-Algorithm : SHA
authentication pre-share
Authentication-Method : PSK
group 14
Group-Description : 2048 bit MODP group
lifetime 3600
Life-Duration : 3600
encryption aes 256
Encryption-Algorithm : AES-CBC Key-Length : 256

Frame 160, the reply to this, has basically the same information.

Next, in packets 161 and 162, we see a nonce being exchanged, and the remainder of the packets just contain encrypted data.

After the ISAKMP, there are a number of ESP packets. These are all encrypted, so it is impossible to see from the network waht is in those packets.