Tunnels · Topic 2 of 3
Configuring and Monitoring GRE and IP-IP Tunnels
Configure Junos GRE and IP-IP tunnel interfaces with source, destination and key, route traffic over them, and verify with show interfaces and ping.
- 7 min
- Configure
interfaces gr-fpc/pic/port unit 0 tunnel sourceanddestination, thenfamily inet address. - IP-IP uses
ip-fpc/pic/portwith the same structure; the optional key is GRE only. - The two ends mirror each other.
What it is
A Junos tunnel is configured as a logical unit on a tunnel interface. The unit holds the outer source and destination addresses and the inner address used for routing. The two routers each get the mirror image of the other's configuration.
After the tunnel interface is configured, traffic uses it only if a route points to it. That route can be static, or learned from a routing protocol running over the tunnel.
How it works
Tunnel services
On platforms where tunnel interfaces rely on dedicated hardware, enable tunnel services first. On an MX Series router:
user@router# set chassis fpc 0 pic 0 tunnel-services bandwidth 1g
The gr-0/0/10 and ip-0/0/10 interfaces then exist for use. On platforms where the tunnel interfaces exist without this step, skip it. Do not guess the interface name: check with show interfaces terse | match "gr-|ip-".
GRE configuration
Router R1 has outer address 192.0.2.1 and R2 has 198.51.100.1.
user@R1# set interfaces gr-0/0/10 unit 0 tunnel source 192.0.2.1
user@R1# set interfaces gr-0/0/10 unit 0 tunnel destination 198.51.100.1
user@R1# set interfaces gr-0/0/10 unit 0 family inet address 10.0.0.1/30
user@R1# commit
R2 uses the mirror:
user@R2# set interfaces gr-0/0/10 unit 0 tunnel source 198.51.100.1
user@R2# set interfaces gr-0/0/10 unit 0 tunnel destination 192.0.2.1
user@R2# set interfaces gr-0/0/10 unit 0 family inet address 10.0.0.2/30
IP-IP configuration
The only differences are the interface name and the missing key option.
user@R1# set interfaces ip-0/0/10 unit 0 tunnel source 192.0.2.1
user@R1# set interfaces ip-0/0/10 unit 0 tunnel destination 198.51.100.1
user@R1# set interfaces ip-0/0/10 unit 0 family inet address 10.0.1.1/30
Optional tunnel statements
| Statement | Effect |
|---|---|
tunnel key 100 | GRE only; a number that both ends must match, used to tell tunnels apart |
tunnel routing-instance destination NAME | Looks up the tunnel destination in another routing instance instead of the default table |
tunnel ttl 64 | Sets the TTL of the outer header |
family inet mtu 1476 | Sets the inner packet MTU so that traffic with the overhead fits the physical link |
tunnel allow-fragmentation | Lets the router fragment the outer packet |
tunnel do-not-fragment | Sets the Do not Fragment bit on the outer packet |
Keep the optional statements the same on both ends where they affect packet format, in particular the key. A key set on one side only causes the far end to discard the packets.
Subtract the overhead yourself. On a 1500 byte physical link, set the inner MTU to 1476 for GRE and to 1480 for IP-IP.
Routing over the tunnel
A tunnel does nothing until traffic is routed to it. Two common choices:
user@R1# set routing-options static route 10.2.0.0/24 next-hop 10.0.0.2
user@R1# set protocols ospf area 0.0.0.0 interface gr-0/0/10.0
The static route sends the remote LAN through the tunnel by using the far inner address as the next hop. The OSPF example forms an adjacency across the tunnel, so remote prefixes are learned dynamically. GRE can carry the multicast hello packets, so OSPF works over it.
The route to the tunnel destination itself must use the physical interfaces, so make sure it is not learned through the tunnel.
Verifying the tunnel
Start with the interface and then follow the traffic.
user@R1> show interfaces gr-0/0/10 terse
Interface Admin Link Proto Local Remote
gr-0/0/10 up up
gr-0/0/10.0 up up inet 10.0.0.1/30
user@R1> show interfaces gr-0/0/10.0
Logical interface gr-0/0/10.0 (Index 332) (SNMP ifIndex 560)
Flags: Up Point-To-Point SNMP-Traps 0x4000 IP-Header 198.51.100.1:192.0.2.1:47:df:64:0000000000000000 Encapsulation: GRE-NULL
Input packets : 1205
Output packets: 1198
Protocol inet, MTU: 1476
Local: 10.0.0.1, Broadcast: Unspecified
The IP-Header line shows the outer header: destination, source, protocol 47 for GRE (it would show 4 for IP-IP), the Do not Fragment flag and the TTL. This is the quickest place to read the real tunnel configuration. The packet counters should rise in both directions when the tunnel is working.
| Command | What it confirms |
|---|---|
show interfaces gr-0/0/10 terse | Interface and unit are up, and the inner address is set |
show interfaces gr-0/0/10.0 | Outer addresses, protocol, MTU and packet counters |
show route 10.2.0.0/24 | The route uses the tunnel as the next hop interface |
show route 198.51.100.1 | The tunnel destination uses a physical interface |
ping 10.0.0.2 | The far end of the tunnel answers over the inner address |
show ospf neighbor | A protocol adjacency is up across the tunnel |
user@R1> ping 10.0.0.2 count 3
PING 10.0.0.2 (10.0.0.2): 56 data bytes
64 bytes from 10.0.0.2: icmp_seq=0 ttl=64 time=1.8 ms
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=1.7 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=1.7 ms
A firewall filter that blocks IP protocol 47 (protocol 4 for IP-IP) on the physical interface stops the tunnel.
Do not read up and up on the tunnel interface as success. Without keepalives, only counters and ping show whether the tunnel passes traffic.
Common mistakes
Not mirroring source and destination. If R1 uses its own address as destination, packets never reach R2.
Missing route into the tunnel. The interface is configured and up, but no route points to it, so the traffic takes the default route instead.
Learning the destination through the tunnel. This causes recursive routing.
What to remember for the exam
- Configure
interfaces gr-fpc/pic/port unit 0 tunnel sourceanddestination, thenfamily inet address. - IP-IP uses
ip-fpc/pic/portwith the same structure; the optional key is GRE only. - The two ends mirror each other.
- Tunnel services must be enabled first on platforms that need them, for example MX.
- Traffic uses the tunnel only when a static route or a protocol points to it.
show interfaces gr-0/0/10.0shows the outer header, protocol and counters.- A tunnel interface stays up without the far end, so test with ping.
- Set the inner MTU lower than the physical MTU by 24 for GRE or 20 for IP-IP.
Check yourself
Which statements hold the outer addresses of a GRE tunnel?
The
tunnel sourceandtunnel destinationstatements under the logical unit of thegr-interface.The tunnel interface is up and up but ping to the far inner address fails. Name two causes.
The two ends do not mirror each other, or there is no route or a filter in the way for protocol 47; a GRE key mismatch is another.
Where do you look to see the real outer header of a tunnel?
In
show interfaces gr-0/0/10.0, which prints the IP-Header line with destination, source and protocol.
Topic 2 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.