Course contentsShow
← Linux
Lesson 1127 of 1,81910. Network Administration and Kernel StacksFree lesson

Tunneling Concepts and GRE

Encapsulate traffic between sites using Generic Routing Encapsulation.

In this lesson, you will learn how to use Generic Routing Encapsulation (GRE) to transparently transport isolated network traffic between two remote sites over an existing IP infrastructure.

Understanding GRE Tunneling

At its core, tunneling is the process of wrapping one network packet inside another. GRE is a tunneling protocol that allows you to take an entire IP packet (the "payload") and encapsulate it within a new IP header (the "delivery" header).

Think of it like a mailing system: normally, your letter travels directly to the destination. With GRE, you put your letter inside an additional envelope addressed to a specific "post office" (the remote tunnel endpoint). The intermediate routers only see the outer envelope; they have no idea what the original payload is. Once the outer envelope reaches the destination, the remote Linux kernel strips it away and routes the original packet to its actual destination inside the private network.

Practical Implementation

In Linux, GRE tunnels are created using the ip tool. Imagine you have two sites with public IPs 1.1.1.1 and 2.2.2.2, and you want to connect their internal networks via a virtual link.

On the first site, you would run:

# Create the GRE tunnel interface
ip tunnel add gre1 mode gre remote 2.2.2.2 local 1.1.1.1 ttl 255

# Bring the interface up
ip link set gre1 up

# Assign an internal IP to the tunnel
ip addr add 10.0.0.1/30 dev gre1

By repeating a mirrored configuration on the second site (swapping the remote and local IPs), you establish a logical point-to-point connection. Any traffic you route to 10.0.0.2 (the other end of the tunnel) will be automatically encapsulated in GRE and sent to the remote public IP.

Because GRE is stateless and adds a small overhead (typically 24 bytes), it is highly efficient for site-to-site communication, though it does not provide encryption by itself. It simply provides the "pipe" through which your internal traffic can flow across the public internet.

Key Takeaway: GRE creates a virtual point-to-point link by encapsulating packets, allowing you to bridge geographically separate networks as if they were directly connected.