GRE (Generic Routing Encapsulation)
What it is for
Two private networks need to reach each other, but only the public internet lies between them, and private addresses (10.x) are not routable there.
GRE treats the whole private packet as a payload and adds a publicly routable IP header outside it. Internet routers read only the outer header; the inner packet is carried unchanged to the far end of the tunnel and decapsulated there.
GRE can also carry non-IP protocols, which is why the GRE header has a protocol-type field.
Using GRE with IPsec
GRE does not encrypt: it only delivers the packet to the far end of the tunnel and does not protect the contents.
So production networks commonly use GRE over IPsec: GRE handles encapsulation (it can carry multicast and routing protocols) and IPsec handles encryption.
IPsec is not used alone because an IPsec tunnel cannot carry multicast, or routing protocols that use multicast, while GRE can. Running OSPF inside a tunnel requires GRE.
Common misconceptions
GRE is an unencrypted tunnel: a capture shows the inner packet. If GRE is used as a VPN, the data crosses the public internet in plaintext.
Prevent recursive routing when configuring a tunnel: if the route to the tunnel's far-end address points through the tunnel itself, the tunnel encapsulates itself repeatedly and eventually goes down. The route to the far-end address must use a physical interface.
GRE overhead: 24 bytes (20 of new IP plus 4 of GRE), so the MTU drops to 1476; with IPsec added, the overhead is 50-80 bytes.