Virtualization · Topic 3 of 4

GRE and IPsec Tunnels

Configure and verify GRE tunnels and IPsec protection on Cisco IOS XE: tunnel source and destination, IKE and ESP basics, transform sets, show commands.

  • 6 min
  • Includes a diagram
In a nutshell
  • GRE is IP protocol 47. It does not encrypt.
  • A GRE tunnel needs a tunnel source, a tunnel destination and a tunnel IP address.
  • GRE carries multicast and routing protocols. Plain IPsec does not.

What it is

A tunnel carries one network's packets inside another network's packets, so two distant sites can act as if they were connected directly.

GRE builds the tunnel and can carry many kinds of traffic, but it adds no security. IPsec adds encryption and integrity, but on its own it is more limited in what it carries. The two are often combined, so that GRE provides the flexibility and IPsec provides the protection.

Site ALAN 10.1.0.0/16original packetRouter AGRE then IPsecacross the internetRouter Bdecryptsoriginal packetSite BLAN 10.2.0.0/16

How it works

GRE first, then IPsec on top of it.

GRE basics

Site A and Site B LANs sit behind routers R1 and R2 across the internet. A GRE tunnel from Tunnel0 on R1 to 203.0.113.2 on R2 is protected by IPsec. Generic Routing Encapsulation (GRE) is IP protocol 47. A GRE tunnel is a point to point virtual interface on each router. The original packet gets a GRE header and a new outer IP header.

R1(config)# interface Tunnel0
R1(config-if)# ip address 172.16.0.1 255.255.255.252
R1(config-if)# tunnel source GigabitEthernet0/0
R1(config-if)# tunnel destination 203.0.113.2

R2 mirrors this, with its own tunnel address and with the source and destination swapped. The tunnel interface comes up once the source is up and the destination is reachable through the routing table.

GRE can carry multicast and routing protocol traffic, such as OSPF and EIGRP, across the tunnel. Plain IPsec cannot do that on its own, which is the main reason to combine them.

FeatureGREIPsec
EncryptionNoneYes
Carries multicast and routing protocolsYesNot by itself
IP protocol or portProtocol 47ESP is protocol 50
StandardCisco origin, RFC basedIETF

The tunnel adds header bytes, so the effective MTU is smaller than the physical one. You can lower it on the tunnel interface to avoid fragmentation.

R1(config-if)# ip mtu 1400
R1(config-if)# ip tcp adjust-mss 1360

Recursive routing

A tunnel can fail if the router learns the tunnel destination through the tunnel itself. This is called recursive routing, and the router reports it and takes the tunnel down. Use a route to the tunnel destination that points out of the physical interface, and do not advertise the underlay networks over the tunnel.

IPsec basics

IPsec is a framework that protects IP packets. It has two stages.

  • IKE (Internet Key Exchange) authenticates the peers and builds a secure channel. IKE uses UDP port 500, and UDP port 4500 when NAT traversal is needed.
  • IPsec SA protects the data. It uses ESP (protocol 50), which encrypts and authenticates, or AH (protocol 51), which authenticates but does not encrypt.

IKE has two versions. IKEv2 is the newer one and is preferred, though IKEv1 is still in use.

Two modes decide how much of the packet is wrapped. Tunnel mode encrypts the whole original packet and adds a new IP header. Transport mode keeps the original IP header and protects only the payload.

Tunnel mode is the usual choice between sites.

Protecting a GRE tunnel

A simple, widely used approach is an IPsec profile applied to the tunnel interface. This IOS XE example uses IKEv1 style commands, and the exact commands depend on the software release.

R1(config)# crypto isakmp policy 10
R1(config-isakmp)# encryption aes 256
R1(config-isakmp)# hash sha256
R1(config-isakmp)# authentication pre-share
R1(config-isakmp)# group 14
R1(config)# crypto isakmp key MYSECRET address 203.0.113.2
R1(config)# crypto ipsec transform-set TSET esp-aes 256 esp-sha256-hmac
R1(cfg-crypto-trans)# mode tunnel
R1(config)# crypto ipsec profile PROF
R1(ipsec-profile)# set transform-set TSET
R1(config)# interface Tunnel0
R1(config-if)# tunnel protection ipsec profile PROF

Both ends need matching policy: the same encryption, hash, authentication method, group and transform set. Newer software supports IKEv2 with its own proposal, policy, keyring and profile, but the idea is the same.

You can also use the tunnel itself as an IPsec tunnel with tunnel mode ipsec ipv4, which is called a virtual tunnel interface. The commands available depend on the software release.

Verifying

R1# show interfaces tunnel 0
R1# show crypto isakmp sa
R1# show crypto ipsec sa
R1# show ip route

show interfaces tunnel 0 should show the interface up. show crypto isakmp sa should show the peer in the active state.

show crypto ipsec sa shows the counters of encrypted and decrypted packets. If the encrypt counter rises but the decrypt counter does not, the problem is at the far end or in the path back.

Check tunnelshow interfaces tunnel 0upCheck IKEshow crypto isakmp saactiveCheck IPsecshow crypto ipsec sacounters riseWorkingtraffic protected

What to remember for the exam

Eight facts cover most questions on this topic.

  • GRE is IP protocol 47. It does not encrypt.
  • A GRE tunnel needs a tunnel source, a tunnel destination and a tunnel IP address.
  • GRE carries multicast and routing protocols. Plain IPsec does not.
  • ESP is protocol 50 and encrypts. AH is protocol 51 and does not encrypt.
  • IKE uses UDP port 500, and UDP port 4500 for NAT traversal.
  • Tunnel mode encrypts the whole original packet. Transport mode protects only the payload.
  • tunnel protection ipsec profile NAME applies IPsec to a tunnel interface.
  • show crypto ipsec sa shows encrypt and decrypt counters.
Exam tip

Both ends must agree on the IKE policy and the transform set. A mismatch is the most common reason for a tunnel that will not come up.

Common mistakes

These four mistakes appear often.

Assuming GRE is secure. GRE has no encryption, so anyone on the path can read the traffic.

Routing the tunnel destination over the tunnel. This causes recursive routing, and the tunnel goes down.

Forgetting the MTU. The extra headers can cause fragmentation or drops of large packets.

Mixing IKE settings. If the two ends differ in hash, group or authentication, negotiation fails.

Watch out

A GRE tunnel can be up while the IPsec part is down. Check the crypto commands as well as the tunnel interface.

Check yourself

Work through these three questions.

  • Why combine GRE with IPsec?

    GRE carries multicast and routing protocols but does not encrypt, and IPsec adds encryption.

  • Which IP protocol numbers do GRE and ESP use?

    GRE is protocol 47 and ESP is protocol 50.

  • What does it mean if the encrypt counter rises but the decrypt counter does not in show crypto ipsec sa?

    Packets are leaving protected, but nothing valid is returning, so the problem is at the far end or in the path back.

Topic 3 of 4 in Virtualization

Test yourself on Virtualization

The full Cisco CCNP 350-401 ENCOR question bank has 854 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.