Generic Routing Encapsulation (GRE) is a tunneling protocol that encapsulates one network layer protocol inside another, creating virtual point-to-point links between routers. GRE tunnels are widely used for connecting separated network segments, building overlay networks, transporting multicast traffic, and extending layer 2 domains across layer 3 infrastructure.
In this guide, we compare three approaches to self-hosted GRE tunnel management: Linux Kernel GRE (ip tunnel), Open vSwitch (OVS) GRE, and GRETAP (Layer 2 GRE) — covering configuration, Docker deployment, performance, and use cases.
What Is GRE Tunneling?
GRE (RFC 2784, RFC 2890) is a lightweight tunneling protocol that wraps packets from one network inside packets of another network. The outer header routes the packet through the transport network, while the inner header reaches the final destination after decapsulation.
Key use cases for GRE tunnels:
- Site-to-site connectivity: Connect remote office networks over the internet
- Overlay networks: Build virtual networks on top of physical infrastructure
- Multicast transport: Carry multicast traffic across unicast-only networks
- Protocol translation: Transport non-IP protocols (IPv6 over IPv4, IPX, AppleTalk)
- Layer 2 extension: Extend Ethernet segments across routed networks (GRETAP)
Unlike IPsec, GRE does not encrypt traffic — it only encapsulates it. For secure tunnels, GRE is often combined with IPsec (GRE-over-IPsec or IPsec-transport-mode GRE).
Comparison: Linux GRE vs Open vSwitch vs GRETAP
| Feature | Linux Kernel GRE | Open vSwitch GRE | GRETAP |
|---|---|---|---|
| Type | Layer 3 (IP-in-IP) | Layer 2/3 tunnel | Layer 2 (Ethernet-in-IP) |
| Kernel Module | ip_gre | openvswitch | ip_gre (type gretap) |
| Configuration Tool | iproute2 (ip tunnel) | ovs-vsctl | iproute2 (ip link) |
| Key/Sequence Support | Yes (RFC 2890) | Yes | Yes |
| Checksum Support | Yes | Yes | Yes |
| MTU Overhead | 24 bytes | 24 bytes | 38 bytes |
| Multicast Support | Yes | Yes | Yes |
| VXLAN Integration | No | Native (same OVS) | No |
| Flow-Based Tunneling | No | Yes | No |
| Docker Support | Via host network | Official images | Via host network |
| Performance | Kernel-native (fastest) | Userspace/kernel hybrid | Kernel-native |
| Management Complexity | Low | Medium | Low |
| GitHub Stars (OVS) | — | 3,951+ | — |
| License | GPL-2.0 | Apache-2.0 | GPL-2.0 |
Linux Kernel GRE — Simple and Fast
The Linux kernel includes native GRE support through the ip_gre module. It’s the simplest and most performant option for basic point-to-point tunnels.
Key Features
- Zero overhead: Runs entirely in the kernel with no userspace daemon
- iproute2 integration: Configured with standard
ip tunnelcommands - Key support: Optional 32-bit key for multiplexing multiple tunnels
- Checksum and sequencing: Optional integrity checking per RFC 2890
- Point-to-multipoint: Supports point-to-multipoint configurations
Docker Compose Deployment
GRE tunnels require host network access. Use a Docker container with network_mode: "host" and configure tunnels via init scripts:
| |
setup-gre.sh:
| |
Native Configuration
| |
Persistent configuration (Debian/Ubuntu /etc/network/interfaces):
| |
Persistent configuration (RHEL/CentOS /etc/sysconfig/network-scripts/ifcfg-gre0):
| |
Open vSwitch GRE — Programmable and Feature-Rich
Open vSwitch (OVS) provides a programmable virtual switch with native GRE tunnel support. It’s the most flexible option for complex network topologies, especially when combined with VXLAN or other overlay protocols.
Key Features
- Flow-based tunneling: Use OpenFlow rules to dynamically direct traffic to GRE tunnels
- Multi-protocol support: GRE, VXLAN, Geneve, STT in a single switch
- OVSDB management: Centralized configuration via OVSDB protocol
- Integration with SDN controllers: Works with OpenDaylight, ONOS, Ryu
- Hardware offload: Supports NIC offloading for GRE encapsulation on compatible hardware
- Monitoring: Built-in statistics and port mirroring
Docker Compose Deployment
| |
Native Configuration
| |
GRE with Flow-Based Tunneling
| |
GRETAP — Layer 2 Over IP
GRETAP is a variant of GRE that encapsulates full Ethernet frames (Layer 2) instead of IP packets (Layer 3). This allows you to extend Ethernet segments across routed networks — useful for VM migration, stretched VLANs, and connecting bridge domains.
Key Features
- Layer 2 transport: Carries full Ethernet frames, not just IP packets
- Transparent bridging: End hosts see a single broadcast domain
- VM migration support: Enables live VM migration across data centers
- VLAN passthrough: Preserves 802.1Q tags across the tunnel
- Simple configuration: Uses the same
ip linktools as regular GRE
Native Configuration
| |
MTU consideration: GRETAP adds 38 bytes of overhead (24 GRE + 14 Ethernet). If your physical interface has MTU 1500, set the tunnel MTU to 1462:
| |
Persistent Configuration (NetworkManager)
| |
Choosing the Right GRE Approach
Choose Linux Kernel GRE when:
- You need simple point-to-point tunnels with minimal overhead
- You want the fastest performance (kernel-native, zero userspace)
- You’re connecting two sites with a straightforward topology
- You don’t need programmability or SDN integration
- You want to use standard iproute2 tools
Choose Open vSwitch GRE when:
- You need flow-based tunneling with dynamic path selection
- You’re building overlay networks with multiple tunnel types
- You want SDN controller integration (OpenDaylight, ONOS)
- You need centralized management via OVSDB
- You’re running virtualized environments (KVM, containers)
- You need hardware offload on compatible NICs
Choose GRETAP when:
- You need Layer 2 extension across routed networks
- You’re enabling live VM migration between data centers
- You want to stretch VLANs across sites
- You need to transport non-IP protocols over IP
- You’re building stretched Layer 2 domains for clustering
GRE Tunnel Best Practices
- Set proper MTU: Account for 24-byte GRE overhead. If physical MTU is 1500, tunnel MTU should be 1476
- Use tunnel keys: Keys prevent accidental misconfiguration and allow multiplexing
- Enable checksums: For critical links, enable GRE checksums to detect corruption
- Monitor tunnel state: Use
ip -s linkorovs-vsctl list interfaceto monitor packet counts - Combine with IPsec: For untrusted networks, wrap GRE in IPsec for encryption
- Use PMTUD: Enable Path MTU Discovery to avoid fragmentation issues
- Consider alternatives: For new deployments, evaluate VXLAN or Geneve for richer feature sets
Why Self-Host GRE Tunnels?
GRE tunneling infrastructure gives you the ability to connect distributed networks without depending on third-party VPN services or managed overlay providers. With open-source tools, you can:
- Build site-to-site connectivity using commodity hardware
- Create overlay networks for multi-tenant environments
- Transport multicast traffic across unicast-only infrastructure
- Extend Layer 2 domains for VM migration and clustering
- Integrate with SDN controllers for programmable networking
For VXLAN overlay networks, see our VXLAN tunneling guide. If you need WireGuard mesh connectivity, check our WireGuard mesh networking article. For L2TP/IPsec alternatives, our L2TP IPsec VPN guide covers those options.
For VXLAN overlay networks as an alternative to GRE, see our VXLAN tunneling guide. If you need WireGuard mesh connectivity for secure tunneling, check our WireGuard mesh networking article. For L2TP/IPsec as an encrypted tunneling alternative, our L2TP IPsec VPN guide covers those options.
FAQ
What is the difference between GRE and GRETAP?
GRE (Generic Routing Encapsulation) operates at Layer 3, encapsulating IP packets inside IP packets. GRETAP operates at Layer 2, encapsulating full Ethernet frames inside IP packets. Use GRE for routing between subnets; use GRETAP when you need transparent Layer 2 bridging across sites (e.g., for VM migration or stretched VLANs).
How much overhead does GRE add?
Standard GRE adds 24 bytes of overhead: 4 bytes for the GRE header and 20 bytes for the outer IPv4 header. If you enable keys and checksums (RFC 2890), add 4 more bytes for a total of 28 bytes. GRETAP adds 38 bytes total (24 GRE + 14 Ethernet frame header).
Can GRE carry multicast traffic?
Yes, GRE can transport multicast traffic across unicast-only networks. This is one of GRE’s key advantages over IPsec transport mode. Both Linux kernel GRE and Open vSwitch GRE support multicast forwarding. Configure ip tunnel add gre0 mode gre ... and add multicast routes as needed.
Should I use GRE or VXLAN for overlay networks?
For new overlay deployments, VXLAN is generally preferred over GRE because it supports multi-tenancy (VNI), has better ecosystem support (OVS, Kubernetes CNI plugins), and offers hardware offload on modern NICs. GRE is simpler and sufficient for basic point-to-point tunnels. Geneve is the newest option with extensible headers.
Is GRE secure?
GRE does not provide encryption or authentication by itself. It only encapsulates packets. For secure communication, combine GRE with IPsec (GRE-over-IPsec or IPsec transport mode with GRE payloads). Alternatively, use WireGuard or OpenVPN if you need built-in encryption.
Can I run GRE tunnels in Docker containers?
Yes, but the container needs network_mode: "host", NET_ADMIN, and NET_RAW capabilities. The GRE tunnel is created in the host kernel namespace, so the container can configure it via iproute2. For production, consider running a dedicated routing container (FRR, BIRD) with host networking.
What is the maximum MTU for a GRE tunnel?
The tunnel MTU should be the physical interface MTU minus the GRE overhead. For standard Ethernet (MTU 1500): GRE MTU = 1500 - 24 = 1476. GRETAP MTU = 1500 - 38 = 1462. If using jumbo frames (MTU 9000): GRE MTU = 8976, GRETAP MTU = 8962.