Tunnels · Topic 1 of 3
Tunneling Applications, GRE and IP-IP
Learn why Junos networks use tunnels, how GRE and IP-IP encapsulation work, the 24 and 20 byte overhead, MTU and recursive routing considerations.
- 6 min
- Includes a diagram
- A tunnel encapsulates one packet inside another and is routed using only the outer header.
- GRE is protocol 47 with 24 bytes of overhead and an optional key.
- IP-IP is protocol 4 with 20 bytes of overhead, carrying IPv4 unicast.
What it is
A tunnel is a virtual point-to-point link between two routers. The sending router wraps the original packet in a new IP header addressed to the other tunnel end. The routers in between forward the packet using only that outer header. At the far end, the router removes the outer header and forwards the original packet.
Junos OS supports two basic IP tunnel types without any additional protocol: GRE and IP-IP. Both use a logical interface, and both are stateless. Neither one encrypts anything.
How it works
Why tunnels are used
| Application | Reason |
|---|---|
| Connect private networks across a transit network | The transit network only needs to route the outer addresses |
| Carry traffic the transit cannot route | For example private addresses, or multicast over a unicast only network |
| Run a routing protocol between remote sites | An IGP or BGP session runs across the tunnel as if it were a direct link |
| Build an overlay for a VPN | A tunnel is the base, and encryption such as IPsec can be added on top |
| Steer traffic in a controlled way | A route can point to the tunnel to send traffic through a chosen path |
A tunnel is not a security feature. GRE and IP-IP do no encryption and no authentication of the packet contents.
GRE
Generic Routing Encapsulation is IP protocol number 47. The router adds an outer IPv4 header (20 bytes) and a GRE header (4 bytes), a total of 24 bytes of overhead. GRE can carry many payload types, including IPv4, IPv6 and multicast, and it supports an optional key to separate tunnels between the same two endpoints.
On Junos the tunnel interface is named gr-fpc/pic/port, for example gr-0/0/10.
IP-IP
IP-IP is IP protocol number 4. It adds only an outer IPv4 header, so the overhead is 20 bytes. It carries IPv4 unicast traffic inside IPv4 and has no key and no extra header fields. The Junos interface is ip-fpc/pic/port, for example ip-0/0/10.
GRE compared with IP-IP
| GRE | IP-IP | |
|---|---|---|
| IP protocol number | 47 | 4 |
| Overhead | 24 bytes | 20 bytes |
| Junos interface | gr- | ip- |
| Payloads | Several, including multicast | IPv4 unicast |
| Optional key | Yes | No |
| Typical use | General purpose, runs routing protocols | Simple, lowest overhead |
Tunnel endpoints
Each tunnel has a source and a destination address. The source is an address on the local router, and the destination is an address on the far router that is reachable through the transport network. The far router uses the mirror configuration: its source is your destination and its destination is your source. If the two sides do not mirror each other, packets are discarded.
The tunnel interface itself also gets an address, for example 10.0.0.1/30. This inner address is used for the routing protocol or static route that runs over the tunnel. It is separate from the outer source and destination.
user@router# show interfaces gr-0/0/10
unit 0 {
tunnel {
source 192.0.2.1;
destination 198.51.100.1;
}
family inet {
address 10.0.0.1/30;
}
}
Design considerations
MTU and fragmentation. The outer header makes every packet larger. If the packet plus overhead exceeds the physical interface MTU, the router must fragment it, or drop it when the Do not Fragment bit is set. Set the tunnel interface MTU lower than the physical MTU by at least the overhead, for example 1476 for GRE on a 1500 byte link.
Recursive routing. The route to the tunnel destination must be learned through the physical network. If the router learns that destination through the tunnel itself, packets to the far end are sent into the tunnel, and the tunnel goes down. This loop is called recursive routing.
Tunnel services. On some Junos platforms, tunnel interfaces need a hardware resource or tunnel services to be enabled. On MX Series routers you enable tunnel services on a PIC or MPC with set chassis fpc 0 pic 0 tunnel-services bandwidth 1g, and the gr- and ip- interfaces then appear under that location.
No keepalives by default. GRE and IP-IP are stateless, and Junos runs no tunnel keepalive unless you configure one (some platforms offer GRE keepalives through OAM). The tunnel interface can show up even though the far end is unreachable or down.
Extra processing. Each tunneled packet is encapsulated and decapsulated, so tunnels cost forwarding capacity and a little added delay.
A tunnel interface stays up even when the far end is down. Do not use the interface state as proof that the tunnel works. Test with ping across it.
When a tunnel carries a routing protocol, a recursive route can make the neighbor flap every few minutes. Learn the tunnel destination from the IGP or a static route over the physical link, never from the tunnel.
Common mistakes
Mismatched tunnel ends. Source and destination must be mirrored on the two routers. A typo leaves the interface up and passing no traffic.
Ignoring MTU. Small packets such as ping work, while large transfers stall. The cause is overhead pushing packets past the link MTU.
Mixing up the numbers. GRE is 24 bytes and protocol 47, IP-IP is 20 bytes and protocol 4.
Using the tunnel to reach its own destination. This is the recursive routing problem.
What to remember for the exam
- A tunnel encapsulates one packet inside another and is routed using only the outer header.
- GRE is protocol 47 with 24 bytes of overhead and an optional key.
- IP-IP is protocol 4 with 20 bytes of overhead, carrying IPv4 unicast.
- Interfaces are
gr-fpc/pic/portandip-fpc/pic/port, with a tunnel source and destination underunit 0 tunnel. - The two ends must mirror each other, and the destination must be reachable over the physical network.
- Tunnels are stateless and have no keepalive by default, so the interface can be up while the far end is down.
- Lower the tunnel MTU by the overhead, and avoid recursive routing.
- Tunnels give no encryption.
Check yourself
How many bytes does GRE add, and how many does IP-IP add?
GRE adds 24 bytes (outer IP of 20 plus GRE of 4); IP-IP adds 20 bytes.
Why can a tunnel interface be up when the far router is down?
GRE and IP-IP are stateless and have no keepalive by default, so the interface state does not reflect the far end.
What is recursive routing in a tunnel?
The router learns the route to the tunnel destination through the tunnel itself, so the tunnel traffic loops into the tunnel and the tunnel fails.
Topic 1 of 3 in Tunnels
Test yourself on Tunnels
The full Juniper JNCIS-ENT JN0-352 question bank has 846 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.