Tunnels · Topic 1 of 2

Tunneling Applications and Considerations

Learn tunneling for the JN0-364: why providers use tunnels, GRE and IP-IP headers, 24 byte GRE overhead, MTU, recursive routing and no encryption.

  • 5 min
In a nutshell
  • A tunnel adds an outer header addressed to the tunnel endpoint; the core forwards by the outer header only.
  • GRE is IP protocol 47 and uses gr- interfaces; IP-IP is protocol 4 and uses ip- interfaces.
  • GRE over IPv4 adds 24 bytes: 20 outer IP plus 4 GRE; a key adds 4 more.

What it is

A tunnel carries a packet inside another packet. The router at one end, the tunnel source, adds an outer header addressed to the router at the other end, the tunnel destination. The network in between forwards only by the outer header and never looks at the packet inside.

Generic routing encapsulation (GRE) is the most common tunnel type on Junos routers. It wraps almost any payload, IPv4, IPv6, MPLS and more, inside an IPv4 or IPv6 packet with a small GRE header in between. It is simple and widely supported, but it adds overhead and provides no security of its own.

Site Aprivate addressinginner packetTunnel sourceadds outer headerrouted by outer headerTunnel destinationremoves outer headerinner packetSite B

How it works

Why providers use tunnels

ApplicationWhat the tunnel solves
Connect sites over a network that does not route their addressesPrivate or customer addresses travel inside public outer addresses
Carry IPv6 across an IPv4-only networkThe outer header is IPv4; the inner packet is IPv6
Carry multicast or routing protocols across a unicast-only pathGRE carries OSPF hellos and multicast traffic between the endpoints, so an IGP adjacency can form across the tunnel
Carry MPLS across a non-MPLS segmentA GRE interface with family mpls carries labeled packets
Steer trafficTraffic routed into the tunnel follows the path to the tunnel destination, whatever its own destination is

GRE and IP-IP compared

GREIP-IP
IP protocol number of the outer header474
Junos interface typegr-ip-
Extra header4 byte GRE header (more if optional fields are used)None
Overhead over IPv424 bytes (20 IP plus 4 GRE)20 bytes
PayloadsMany: IPv4, IPv6, MPLS and others, identified by the GRE protocol type fieldIP only

The basic GRE header holds flag bits, a version field and a protocol type field that names the inner payload, using EtherType values. Optional fields add a checksum, a key and a sequence number, 4 bytes each, which raise the overhead above 24 bytes.

Outer IPv4 header20 bytes protocol 47thenGRE header4 bytesthenInner packetIPv4 IPv6 or MPLS

Consideration 1: overhead and MTU

Every tunneled packet grows by the tunnel overhead. With a physical MTU of 1500 bytes, the largest inner IPv4 packet that fits in one GRE packet is 1476 bytes.

Physical IP MTUGRE overheadLargest inner packet without fragmentation
1500241476
150028 (with key)1472

If a larger inner packet has the don't fragment (DF) bit set, it is dropped and the sender should get an ICMP "fragmentation needed" message. When those messages are filtered somewhere, small packets work but large transfers stall, a classic tunnel symptom. Options include lowering the MTU on the tunnel interface, adjusting TCP MSS on the hosts or edge, or clearing the DF bit with clear-dont-fragment-bit on the tunnel unit so the packet can be fragmented.

Consideration 2: recursive routing

The tunnel destination must be reached through the physical network, never through the tunnel itself. If a routing protocol running across the tunnel advertises the route to the tunnel destination, the router tries to send the outer packet into the tunnel. The tunnel then flaps or stops forwarding.

Route to tunnel destinationlearned via physical linkTunnel stableRoute to tunnel destinationlearned via the tunnelRecursive looptunnel fails

Prevent it by keeping the tunnel endpoint addresses out of the protocol that runs over the tunnel, or by using a static route or a separate routing instance for the endpoints.

Consideration 3: no security

GRE provides no encryption and no authentication. Anyone on the path can read the inner packet. When privacy is needed, the traffic must be protected with IPsec, either instead of GRE or around it.

Consideration 4: state and failure detection

GRE is stateless. By default, a gr- interface comes up as soon as it is configured and stays up while its tunnel source address is valid, even if the far end is down or not configured. GRE keepalives, configured under protocols oam gre-tunnel, let the router detect a dead far end and mark the tunnel down.

Consideration 5: platform and operations

TopicPoint to remember
MX hardwareGRE runs in tunnel services on a PIC, which must be enabled with tunnel-services before gr- interfaces appear
BandwidthTunnel services have a configured bandwidth, so heavy tunnel traffic competes for it
Firewall filtersFilters along the path must allow IP protocol 47 between the endpoints
TroubleshootingA traceroute through a tunnel shows the tunnel as one hop, hiding the routers in between
Exam tip

When small pings through a tunnel succeed but large ones with the DF bit set fail, think MTU and the 24 byte GRE overhead before anything else.

Common mistakes

Thinking GRE is encrypted. It is not. Use IPsec when confidentiality is needed.

Forgetting the overhead. A tunnel over a 1500 byte link cannot carry 1500 byte inner packets without fragmentation.

Routing the tunnel destination through the tunnel. This causes recursive routing and a failing tunnel.

Expecting the tunnel to go down when the far end fails. Without keepalives, the local gr- interface usually stays up.

Watch out

IP-IP adds 20 bytes and carries only IP. GRE adds 24 bytes and carries many protocol types. Exam options often swap the two numbers.

What to remember for the exam

  • A tunnel adds an outer header addressed to the tunnel endpoint; the core forwards by the outer header only.
  • GRE is IP protocol 47 and uses gr- interfaces; IP-IP is protocol 4 and uses ip- interfaces.
  • GRE over IPv4 adds 24 bytes: 20 outer IP plus 4 GRE; a key adds 4 more.
  • GRE carries IPv4, IPv6, MPLS and multicast, so IGPs can run across it.
  • GRE has no encryption; combine it with IPsec for security.
  • Avoid recursive routing: reach the tunnel destination outside the tunnel.
  • GRE is stateless; keepalives under protocols oam gre-tunnel detect a dead far end.

Check yourself

  • How many bytes does a basic GRE tunnel over IPv4 add to each packet?

    24 bytes, a 20 byte outer IPv4 header plus a 4 byte GRE header.

  • A GRE tunnel flaps after you enable OSPF across it. What is a likely cause?

    Recursive routing: OSPF learned the route to the tunnel destination through the tunnel itself.

  • Does GRE protect the confidentiality of the traffic it carries?

    No. GRE provides no encryption, so IPsec is needed for confidentiality.

Topic 1 of 2 in Tunnels

Test yourself on Tunnels

The full Juniper JNCIS-SP JN0-364 question bank has 860 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 Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.