IPSEC Tunnel Config and Explain
IPSEC Tunnel Config and Explain
IPSEC Tunnel Config and Explain
and servers. Here are some examples how you can use it:
1.Between two routers to create a site-to-site VPN that “bridges” two LANs
together.
2.Between a firewall and windows host for remote access VPN.
3.Between two linux servers to protect an insecure protocol like telnet.
To establish an IPsec tunnel, we use a protocol called IKE (Internet Key Exchange).
1. IKE phase 1 (This is also called the ISAKMP tunnel or IKE phase 1 tunnel)
2. IKE phase 2 (IKE phase 2 tunnel or IPsec tunnel)
IKE Phase 1:
1. In IKE phase 1, two peers will negotiate about the encryption, authentication,
hashing and other protocols that they want to use and some other parameters that
are required.
In this phase, an ISAKMP (Internet Security Association and Key Management
Protocol) session is established. This is also called the ISAKMP tunnel or IKE
phase 1 tunnel.
2. The collection of parameters that the two devices will use is called a SA
(Security Association).
3. The IKE phase 1 tunnel is only used for management traffic. We use this tunnel
as a secure method to establish the second tunnel called the IKE phase 2 tunnel or
IPsec tunnel and
for management traffic like keepalives.
IKE phase 2:
1. IKE phase 2 tunnel (or IPsec tunnel) that we can use to protect our user data.
This user data will be sent through the IKE phase 2 tunnel:
2. IKE builds the tunnels for us but it doesn’t authenticate or encrypt user data.
We use two other protocols for this:
A. AH (Authentication Header)
B. ESP (Encapsulating Security Payload)
3. AH and ESP both offer authentication and integrity but only ESP supports
encryption. Because of this, ESP is the most popular choice nowadays.
Commands:
crypto ikev1 policy 5
authentication pre-share
encryption aes-256
hash sha
group 5
lifetime 3600
Create a tunnel-group and configure the peer IP address alongside the tunnel pre-
shared key (PSK). Please note that the PSKs should match on both sides
Commands:
tunnel-group 201.85.10.1 (peer outside interface ip) type ipsec-l2l
tunnel-group 201.85.10.1 ipsec-attributes
ikev1 pre-shared-key Cisco123
Command:
crypto ipsec ikev1 transform-set AES-HMAC esp-aes-256 esp-sha-hmac
Commands:
access-list BRANCH-TO-HO extended permit tcp object user-subnet object ho-server-
subnet
A. Configure a Crypto Map and apply it to the outside interface. A crypto map
defines an IPSec policy that includes an ACL to identify the interesting traffic,
peer IP and IKEv1 transform-set that we created in the previous step.
B. If there is already a crypto map applied on the ASA, you only need to add a new
entry with the same crypto map name and increment the number instead of creating a
new crypto map.
Commands:
crypto map VPN-MAP interface OUTSIDE.
8. NAT exemption.
A. As we discussed before, any traffic that is initiated from the user subnet going
out to the Internet is NATed to the outside interface's public IP.
B. However, we want the traffic from the branch office to the headquarters to be
exempted from the dynamic PAT.
C. So, we need to tell the ASA that if the traffic is initiated from 10.10.60.0/24
and is going out to 192.168.10.0/24, the IP address shouldn't be NAted.
The following command just does that.
Command:
Last step is, Generate the traffic from any allowed machine to build an Tunnel.
otherwise tuneel won't generate.
Key Points:
1. The name of the transform set or the crypto map name doesn't need to match on
both peers. Only the protocols and methods within them should match.
2. Use " show crypto isakmp sa "to verify the currently active phase - 1 tunnels.
As you can see below, branch office ASA initiated the tunnel. Role: initiator using
IKEv1.
3. use " show crypto ipsec sa " command to check the status of the phase - 2 IPSec
tunnels
4. In the Above output, #pkts encrypt and #pkts decrypt are a very good indicator
if you run into any issues.
5. If you see the number of packets encrypted increasing but the number of packets
decrypted stays the same then the issue is with receiving the packets,
more likely an issue on the other side.
6. If you see the 'number of packets encrypted' stays the same then our side of the
ASA is not sending any traffic through the tunnel.
7. IKEv2 has many new features that make it more reliable and secure but there are
many companies that still use IKEv1. One of the benefits of IKEv2 is that it
exchanges fewer messages to establish a tunnel compare to IKEv1.
IKEv2 uses four messages whereas IKEv1 uses either nine messages (in the main
mode) or six messages (in aggressive mode).
Step 1: Negotiation
Hashing: we use a hashing algorithm to verify the integrity, we use MD5 or SHA
for this.
Authentication: each peer has to prove who he is. Two commonly used options are
a pre-shared key or digital certificates.
DH (Diffie Hellman) group: the DH group determines the strength of the key that
is used in the key exchange process. The higher group numbers are more secure but
take longer to compute.
Lifetime: how long does the IKE phase 1 tunnel stand up? the shorter the
lifetime, the more secure it is because rebuilding it means we will also use new
keying material.
Each vendor uses a different lifetime, a common default value is 86400 seconds
(1 day).
Encryption: what algorithm do we use for encryption? For example, DES, 3DES or
AES.
Step 3: Authentication
The last step is that the two peers will authenticate each other using the
authentication method that they agreed upon on in the negotiation.
When the authentication is successful, we have completed IKE phase 1.
9. The three steps above can be completed using two different modes:
Main mode
Aggressive mode
Main mode uses six messages while aggressive mode only uses three messages. Main
mode is considered more secure.
10. Phase 2 Tuneel process:
The IKE phase 2 tunnel (IPsec tunnel) will be actually used to protect user
data. There is only one mode to build the IKE phase 2 tunnel which is called quick
mode.
Just like in IKE phase 1, our peers will negotiate about a number of items: