GRE (Generic Routing Encapsulation) is the oldest still-relevant Linux tunnel type — it pre-dates IPsec, MPLS, and every overlay protocol that came after. It is unencrypted, lightweight, and supports carrying L3 (ip gre) or L2 (ip gretap) payloads. Most modern workloads use WireGuard or VXLAN instead, but GRE remains the right answer for a handful of cases: site-to-site links over a private circuit, integration with vendor gear that speaks little else, and overlay protocols layered on top (DMVPN, NHRP). This article walks through configuration with iproute2, the MTU math that catches everyone the first time, and the operational habits that keep a GRE link healthy.
How to verify
Inspect tunnel state and traffic:
ip tunnel show
ip -d link show gre1
ip route show dev gre1
tcpdump -ni eth0 proto 47 -c 5
ping -M do -s 1472 10.20.0.2
ip -s link show gre1
proto 47 is the GRE IP protocol number — tcpdump filters on that to see the outer packets. The -M do -s 1472 ping is a path MTU probe (1472 bytes payload + 28 bytes ICMP/IP = 1500); if it fails but smaller pings succeed, the MTU is set wrong.
What’s happening
GRE wraps an inner packet in a new IP header plus a 4-byte GRE header (8 with the optional checksum/key fields). The outer IP header has protocol number 47. The encapsulated payload can be IPv4, IPv6, MPLS, or Ethernet — the GRE protocol field declares which.
There are two Linux tunnel types you will see in practice:
ip gre— carries L3 (IPv4 or IPv6) payloads. Routes are added directly on the tunnel interface; no L2 broadcasts traverse.ip gretap— carries L2 frames. The tunnel appears as a normal Ethernet device that can be added to a bridge, which is how you build cross-site L2 overlays.
Two MTU rules matter. First, every byte of overhead — 20 (outer IPv4) + 4 (GRE) = 24 bytes minimum, up to 28 with the GRE key/seq option enabled — comes out of the inner MTU. On a 1500-byte underlay you get an inner MTU of 1476 (or 1472 with key). Second, GRE does not negotiate MTU — both ends must agree, and intermediate routers must not silently fragment.
GRE is not encrypted. If the tunnel traverses any untrusted network, it must be wrapped in IPsec transport mode, WireGuard, or another encrypted underlay.
The procedure
-
Create the tunnel on both ends. Host A (
203.0.113.10) to Host B (198.51.100.20):# On Host A ip tunnel add gre1 mode gre remote 198.51.100.20 local 203.0.113.10 ttl 255 ip link set gre1 up mtu 1476 ip addr add 10.20.0.1/30 dev gre1 # On Host B (mirror) ip tunnel add gre1 mode gre remote 203.0.113.10 local 198.51.100.20 ttl 255 ip link set gre1 up mtu 1476 ip addr add 10.20.0.2/30 dev gre1 -
Add routes through the tunnel.
# Host A: reach Host B's site network ip route add 10.50.0.0/24 dev gre1 # Host B: reach Host A's site network ip route add 10.40.0.0/24 dev gre1 -
Persist with systemd-networkd. Two files per tunnel —
gre1.netdevandgre1.network:# /etc/systemd/network/10-gre1.netdev [NetDev] Name=gre1 Kind=gre MTUBytes=1476 [Tunnel] Local=203.0.113.10 Remote=198.51.100.20 TTL=255# /etc/systemd/network/10-gre1.network [Match] Name=gre1 [Network] Address=10.20.0.1/30 [Route] Destination=10.50.0.0/24 -
Allow GRE through the firewall. Both ends need
iptables -A INPUT -p 47 -s <peer-ip> -j ACCEPT. If conntrack is enabled, GRE flows are tracked using a synthetic 5-tuple — but the conntrack modulenf_conntrack_proto_gremust be loaded (modprobe nf_conntrack_proto_gre) for PPTP-style GRE with keys. -
Lower TCP MSS to avoid PMTU black holes. Many networks silently drop ICMP Fragmentation-Needed packets, which breaks path-MTU discovery. The portable fix is to clamp MSS on the tunnel:
iptables -t mangle -A FORWARD -o gre1 -p tcp --tcp-flags SYN,RST SYN \ -j TCPMSS --clamp-mss-to-pmtuFor a 1476-MTU tunnel, the resulting MSS is 1436.
-
Add a keepalive. Native GRE has no keepalive; on Linux the workaround is a userspace probe or a routing daemon. The minimal version is a cron-driven ping that flips a route metric when the tunnel goes dead:
#!/bin/bash # /usr/local/bin/gre-keepalive.sh if ! ping -W 2 -c 1 10.20.0.2 >/dev/null; then logger -t gre-keepalive "gre1 down — flipping to backup" ip route replace 10.50.0.0/24 dev wg-backup fi
Operational notes
- PMTUd often fails through GRE. Networks that filter ICMP type 3 code 4 (Frag-Needed) break path-MTU discovery; clamping MSS on the tunnel is the safe default rather than the exception.
- GRE has no replay protection or authentication beyond the optional 32-bit key, which is in cleartext. Treat the underlay as the trust boundary.
mode grevsmode ip6grematter for the outer header. A GRE tunnel with an IPv4 outer header carries v4 or v6 payload; anip6greouter header is for v6 underlays. Mismatched ends fail to come up.- NAT-T does not work for GRE. If one end is behind NAT, you need IPsec NAT-T or a UDP-encapsulated alternative (such as FOU or WireGuard).
- Counters live on the tunnel interface.
ip -s link show gre1exposes RX/TX bytes per tunnel — useful in capacity planning when several site-to-site links share a physical egress.
In the engagements we run, GRE is the right answer when we need a quick L3 (or L2 via gretap) overlay between two sites that already have a private circuit and want to avoid the operational weight of IPsec. For anything traversing the public internet we use WireGuard instead; the patterns share enough vocabulary that an engineer comfortable with one is at home in the other. The hand-rolled keepalive is one of the standard small services the managed-operations practice ships on every gateway.