# Overlay Networks in Container Networking | Cycle.io

Canonical URL: https://cycle.io/learn/overlay-networks

## Overlay Networks in Container Networking.

An overlay network is a virtual network that runs on top of an existing physical or logical network. In container environments, an overlay network lets containers on different hosts talk to each other as if they were on the same LAN, by encapsulating their traffic inside packets that the underlying network already knows how to deliver.

This page compares overlay and underlay networks, explains encapsulation and its MTU cost, shows how Docker Swarm and Kubernetes CNI plugins use overlays, and builds a [VXLAN (Virtual Extensible LAN)](https://cycle.io/learn/vxlan-overview) overlay by hand with `ip`, using `tcpdump` to watch the encapsulated packets.

### What is an overlay network?

An overlay network is a virtual network built on top of an existing IP network, called the underlay. Each host wraps (encapsulates) traffic from its containers or VMs inside ordinary packets addressed to another host, so endpoints on different machines share one logical network even when the physical network between them knows nothing about it.

The pieces that make this work:

-   **Underlay:** the real network between hosts. It only has to route packets from one host IP to another.
-   **Tunnel endpoints:** software on each host that encapsulates outgoing traffic and decapsulates incoming traffic. In VXLAN these are called VTEPs (VXLAN tunnel endpoints).
-   **Overlay addresses:** the container, pod or VM IPs. They exist only inside the overlay, and the underlay never routes them.
-   **Control plane:** something has to tell each host which remote host owns which overlay address. That can be static configuration, multicast learning, a gossip protocol (Docker Swarm), or a Kubernetes CNI plugin watching the API server.

Overlay networks abstract the underlying physical network. Containers can be rescheduled to another host and keep their overlay addressing without anyone reconfiguring switches or routers, which is why overlays are common in multi-host container platforms. Overlays are also one of the main building blocks of [software-defined networking](https://cycle.io/learn/introduction-to-software-defined-networking).

### Overlay network vs underlay network

|     | Underlay network | Overlay network |
| --- | --- | --- |
| What it is | Physical or cloud network: NICs, switches, routers, VPC routing | Virtual network built in software on the hosts |
| Addresses it routes | Host (node) IPs | Container, pod or VM IPs |
| Who configures it | Network team or cloud provider | Container platform, CNI plugin or hypervisor |
| How traffic moves | Normal IP routing and switching | Encapsulated in host-to-host packets that cross the underlay |
| MTU | Full link MTU (often 1500, or 9000 with jumbo frames) | Link MTU minus encapsulation overhead (1450 for VXLAN on a 1500-byte underlay) |
| Changes when a container moves | None | Overlay mapping updated by the control plane |
| What `tcpdump` on the host NIC shows | Host-to-host packets | The same packets, with the container packet inside |

The overlay depends on the underlay: if two hosts cannot reach each other on the tunnel port, the overlay between them is down too. The underlay does not need to know anything about the overlay.

#### How encapsulation works

When a container on host A sends a packet to a container on host B over a VXLAN overlay:

1.  The container sends a normal Ethernet frame with an IP packet inside, addressed to the other container's overlay IP.
2.  Host A's tunnel endpoint looks up which host owns that destination (host B).
3.  It wraps the whole frame in a VXLAN header, a UDP header, an outer IP header addressed from host A's IP to host B's IP, and an outer Ethernet header.
4.  The underlay delivers the packet to host B like any other UDP packet.
5.  Host B's tunnel endpoint strips the outer headers and hands the original frame to the destination container.

The outer headers move the packet between hosts, and the inner frame is the container-to-container (or VM-to-VM) traffic. On the wire, a VXLAN packet over IPv4 looks like this:

```
+-----------------+------------------+------------+--------------+----------------------------------+
| Outer Ethernet  | Outer IPv4       | Outer UDP  | VXLAN header | Inner Ethernet frame             |
| (host MACs)     | (host A -> B)    | dst 4789   | 8 bytes,     | (container MACs, container IPs,  |
| 14 bytes        | 20 bytes         | 8 bytes    | 24-bit VNI   |  payload)                        |
+-----------------+------------------+------------+--------------+----------------------------------+
```

The VNI (VXLAN Network Identifier) is a 24-bit field, so one underlay can carry about 16 million separate overlay segments ([RFC 7348](https://www.rfc-editor.org/rfc/rfc7348)).

#### MTU overhead

Encapsulation adds bytes to every packet, and the underlay link MTU does not grow to match. For VXLAN over IPv4, the inner Ethernet header (14), VXLAN header (8), outer UDP (8) and outer IPv4 (20) add 50 bytes. On a 1500-byte underlay, the overlay interface gets an MTU of 1450, which is what Linux sets automatically when a VXLAN device is bound to its underlay interface with `dev`, and what Docker sets inside containers on an overlay network (shown in the Docker and hands-on sections below).

RFC 7348 says VTEPs must not fragment VXLAN packets, so an oversized packet is dropped rather than split. If the overlay MTU is set too high, small requests work but large responses hang. The two fixes are to lower the overlay MTU to fit, or to raise the underlay MTU (for example with jumbo frames; see [MTU, Jumbo Frames, and NIC Tuning](https://cycle.io/learn/mtu-jumbo-frames-and-nic-tuning)) so the overlay can keep 1500.

#### Common overlay encapsulations

| Encapsulation | Transport | Overhead on an IPv4 underlay | Carries | Notes |
| --- | --- | --- | --- | --- |
| VXLAN | UDP, IANA port 4789 | 50 bytes | Ethernet frames | [RFC 7348](https://www.rfc-editor.org/rfc/rfc7348) (2014). The Linux kernel's own default port is 8472, which Flannel and Cilium use. Used by Docker Swarm, Flannel, Calico and Cilium. |
| Geneve | UDP, IANA port 6081 | 50 bytes plus any options | Ethernet frames or other protocols | [RFC 8926](https://www.rfc-editor.org/rfc/rfc8926) (2020, Standards Track). Same 8-byte base header and 24-bit VNI as VXLAN, plus variable-length TLV options for metadata. Cilium tunnel mode can use it. |
| IP-in-IP | IP protocol 4 | 20 bytes | IPv4 packets only | [RFC 2003](https://www.rfc-editor.org/rfc/rfc2003). Smallest overhead, no Ethernet layer, no segment ID. Used by Calico and Flannel's `ipip` backend. |
| GRE | IP protocol 47 | 24 bytes (no options) | Many protocols | See [Configuring GRE Tunnels](https://cycle.io/learn/configuring-gre-tunnels). Less common in container platforms. |
| WireGuard | UDP | At least 60 bytes | IP packets, encrypted | Outer IPv4 (20) + UDP (8) + 16-byte [WireGuard data header](https://www.wireguard.com/protocol/) + 16-byte auth tag, with padding to 16 bytes. Linux gives a new WireGuard interface an MTU of 1420. Flannel has a `wireguard` backend; Calico and Cilium offer WireGuard encryption. See [Configuring WireGuard](https://cycle.io/learn/configuring-wireguard). |

VXLAN and Geneve carry full Ethernet frames, so the overlay behaves like a single layer 2 segment. IP-in-IP and WireGuard carry IP packets, so the overlay is routed. For a deeper look at VXLAN itself, see the [VXLAN overview](https://cycle.io/learn/vxlan-overview).

### Overlay networks in container platforms

Many overlay networks come with integrated service discovery and load balancing, so containers can find each other by name and traffic is spread across the replicas of a service.

#### Docker overlay network (Swarm)

A Docker overlay network uses the built-in `overlay` driver and requires swarm mode (see [Docker Swarm](https://cycle.io/learn/common-orchestrator-docker-swarm)). The data plane is VXLAN, and Docker runs the control plane itself. The [Docker overlay driver docs](https://docs.docker.com/engine/network/drivers/overlay/) list these ports, which must be open between nodes:

| Port | Protocol | Purpose |
| --- | --- | --- |
| 2377 | TCP | Swarm control plane |
| 7946 | TCP and UDP | Communication among nodes (container network discovery) |
| 4789 | UDP | Overlay data traffic (VXLAN). Configurable with `docker swarm init --data-path-port` |

Things to know about Docker overlay networks, as of November 2026:

-   By default only swarm services can join an overlay network. Add `--attachable` so standalone containers started with `docker run` can join as well.
-   Application traffic on an overlay network is not encrypted by default. `docker network create --opt encrypted` turns on IPsec encryption at the VXLAN level. Docker's [swarm setup guide](https://docs.docker.com/engine/swarm/swarm-tutorial/) says that for encrypted overlays, IP protocol 50 (IPsec ESP) must also be allowed between nodes, so check firewalls and cloud security groups. Docker warns that encryption carries a non-negligible performance penalty, and that traffic between Windows containers on an encrypted network is not encrypted.
-   Each overlay gets a /24 subnet by default, carved from the swarm's address pool. You can set the subnet with `docker network create --subnet`, or change the pool and mask length at `docker swarm init` with `--default-addr-pool` and `--default-addr-pool-mask-length`.
-   Swarm also creates an `ingress` overlay for the routing mesh (published service ports) and a `docker_gwbridge` bridge that gives overlay containers a path to the outside world.

A minimal single-node example:

```bash
docker swarm init --advertise-addr 10.0.2.15
docker network create -d overlay --attachable demo-overlay
docker network create -d overlay --opt encrypted --attachable secure-overlay
docker network ls --filter driver=overlay
```

```
NETWORK ID     NAME             DRIVER    SCOPE
s96lsp2bqdcl   demo-overlay     overlay   swarm
zr7thxn3w7e0   ingress          overlay   swarm
2gordgeunsdj   secure-overlay   overlay   swarm
```

Replace `10.0.2.15` with the address other nodes will use to reach this one. Inspecting the network shows the subnet Docker picked and the VXLAN ID it assigned:

```bash
docker network inspect demo-overlay
```

```
[
    {
        "Name": "demo-overlay",
        "Id": "s96lsp2bqdcljxshufxwh1h00",
        "Created": "2026-11-20T18:51:38.78060789Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.1.0/24",
                    "Gateway": "10.0.1.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        ...
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": null
    }
]
```

Attach two containers and they can reach each other by name, using Docker's built-in DNS:

```bash
docker run -d --name c1 --network demo-overlay busybox sleep 3600
docker run -d --name c2 --network demo-overlay busybox sleep 3600
docker exec c1 ip addr show eth0
docker exec c1 ping -c 2 c2
```

```
16: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue
    link/ether 02:42:0a:00:01:02 brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.2/24 brd 10.0.1.255 scope global eth0
       valid_lft forever preferred_lft forever
PING c2 (10.0.1.4): 56 data bytes
64 bytes from 10.0.1.4: seq=0 ttl=64 time=19.108 ms
64 bytes from 10.0.1.4: seq=1 ttl=64 time=1.428 ms
```

The container's `eth0` has an MTU of 1450, the 50 bytes of VXLAN overhead taken off a 1500-byte host link. A container on the encrypted `secure-overlay` network got an MTU of 1424 in the same test, because IPsec adds more overhead. To remove the test setup, delete the containers, then run `docker network rm demo-overlay secure-overlay` and `docker swarm leave --force`.

For firewalling and segmenting these networks, see [Container Network Security](https://cycle.io/learn/container-network-security).

#### Kubernetes CNI plugins: overlay vs native routing

Kubernetes requires that each pod gets its own cluster-wide IP address and that pods can reach each other directly, without NAT ([Kubernetes docs](https://kubernetes.io/docs/concepts/services-networking/)). Kubernetes itself does not build that network. A CNI plugin does, and most popular plugins can do it either with an overlay or with native routing, where pod IPs are routed by the underlay itself.

| CNI plugin | Overlay modes | Native routing mode | Notes (as of November 2026) |
| --- | --- | --- | --- |
| [Flannel](https://github.com/flannel-io/flannel/blob/master/Documentation/backends.md) | `vxlan` (the configured default and the recommended backend), `ipip`, `wireguard` | `host-gw` (needs layer 2 adjacency between nodes) | VXLAN on Linux uses the kernel default port 8472 and VNI 1 unless set. `udp` is for debugging only. |
| [Calico](https://docs.tigera.io/calico/latest/networking/configuring/vxlan-ipip) | IP-in-IP and VXLAN, each set per IP pool to `Always` or `CrossSubnet` | No encapsulation, with routes distributed by BGP | `CrossSubnet` encapsulates only traffic that crosses a subnet boundary. By default, BGP distributes the routes for IP-in-IP pools; VXLAN-only pools do not need BGP. Docs version 3.33. |
| [Cilium](https://docs.cilium.io/en/stable/network/concepts/routing/) | Encapsulation with VXLAN (default, UDP 8472) or Geneve (UDP 6081) | Native routing, which needs a network that can route PodCIDRs, via `auto-direct-node-routes` on a shared L2 network or a BGP daemon | Encapsulation is the mode Cilium runs in when no routing configuration is given. Docs version 1.20. |

Which mode a cluster uses depends on the plugin and how it was installed, so check the CNI pods in `kube-system` and their configuration before you assume there is an overlay. For more on how orchestrators wire this up, see [Kubernetes as a Container Orchestrator](https://cycle.io/learn/common-orchestrator-kubernetes).

Platform Docs

Container Networking

Learn how containers are declaratively networked on the Cycle Platform.

<https://cycle.io/docs/platform/container-networking>

### Hands-on: build a VXLAN overlay network by hand

This example builds the smallest possible overlay on one Linux machine. Two network namespaces, `host-a` and `host-b`, stand in for two hosts. A veth pair between them is the underlay, and a VXLAN interface in each namespace is the overlay. All commands run as root and were tested on Ubuntu 24.04 (kernel 6.8, iproute2 6.1). For the background on namespaces and veth pairs, see [Namespace Isolation](https://cycle.io/learn/namespace-isolation) and [Container Networking Basics](https://cycle.io/learn/container-networking-basics).

#### Step 1: create the underlay

```bash
ip netns add host-a
ip netns add host-b

# Optional: turn off IPv6 so the capture in step 3 only shows IPv4 traffic
ip netns exec host-a sysctl -qw net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1
ip netns exec host-b sysctl -qw net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1

ip link add veth-a type veth peer name veth-b
ip link set veth-a netns host-a
ip link set veth-b netns host-b
ip -n host-a addr add 192.168.100.1/24 dev veth-a
ip -n host-b addr add 192.168.100.2/24 dev veth-b
ip -n host-a link set lo up
ip -n host-b link set lo up
ip -n host-a link set veth-a up
ip -n host-b link set veth-b up
ip netns exec host-a ping -c 2 192.168.100.2
```

```
PING 192.168.100.2 (192.168.100.2) 56(84) bytes of data.
64 bytes from 192.168.100.2: icmp_seq=1 ttl=64 time=11.1 ms
64 bytes from 192.168.100.2: icmp_seq=2 ttl=64 time=0.465 ms
```

The two "hosts" can now reach each other over the underlay on 192.168.100.0/24.

#### Step 2: add a VXLAN interface on each side

```bash
ip -n host-a link add vxlan42 type vxlan id 42 local 192.168.100.1 remote 192.168.100.2 dstport 4789 dev veth-a
ip -n host-b link add vxlan42 type vxlan id 42 local 192.168.100.2 remote 192.168.100.1 dstport 4789 dev veth-b
ip -n host-a addr add 10.42.0.1/24 dev vxlan42
ip -n host-b addr add 10.42.0.2/24 dev vxlan42
ip -n host-a link set vxlan42 up
ip -n host-b link set vxlan42 up
ip -n host-a -d link show vxlan42
```

```
2: vxlan42: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether d6:69:dc:b6:ec:a8 brd ff:ff:ff:ff:ff:ff promiscuity 0  allmulti 0 minmtu 68 maxmtu 65535
    vxlan id 42 remote 192.168.100.2 local 192.168.100.1 dev veth-a srcport 0 0 dstport 4789 ttl auto ageing 300 ...
```

What the options mean:

-   `id 42` is the VNI. Both ends must use the same one.
-   `remote` is the other host's underlay IP. With a single static peer, no multicast or control plane is needed.
-   `dstport 4789` uses the IANA port. If you leave it out, Linux uses its own default (8472), and both ends have to agree.
-   `dev veth-a` ties the VXLAN device to the underlay interface, so the kernel set the MTU to 1450 on its own: the 1500-byte veth MTU minus 50 bytes of VXLAN overhead. Without `dev`, the device starts at 1500 and you have to lower it yourself.

Both namespaces now have an address in the overlay subnet 10.42.0.0/24 on their VXLAN interface, while the veth underlay keeps only its 192.168.100.x addresses.

#### Step 3: ping across the overlay and capture the encapsulated packets

In one terminal, capture on the underlay interface in `host-a`:

```bash
ip netns exec host-a tcpdump -ni veth-a -c 6 udp port 4789
```

In another, ping host B's overlay address:

```bash
ip netns exec host-a ping -c 2 10.42.0.2
```

The capture in the first terminal shows:

```
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on veth-a, link-type EN10MB (Ethernet), snapshot length 262144 bytes
19:21:07.499754 IP 192.168.100.1.56092 > 192.168.100.2.4789: VXLAN, flags [I] (0x08), vni 42
ARP, Request who-has 10.42.0.2 tell 10.42.0.1, length 28
19:21:07.504161 IP 192.168.100.2.56092 > 192.168.100.1.4789: VXLAN, flags [I] (0x08), vni 42
ARP, Reply 10.42.0.2 is-at 16:7d:8d:97:6b:77, length 28
19:21:07.504881 IP 192.168.100.1.60893 > 192.168.100.2.4789: VXLAN, flags [I] (0x08), vni 42
IP 10.42.0.1 > 10.42.0.2: ICMP echo request, id 1056, seq 1, length 64
19:21:07.505773 IP 192.168.100.2.60893 > 192.168.100.1.4789: VXLAN, flags [I] (0x08), vni 42
IP 10.42.0.2 > 10.42.0.1: ICMP echo reply, id 1056, seq 1, length 64
...
6 packets captured
```

Each pair of lines is one packet. The first line is what the underlay sees: a UDP packet between 192.168.100.1 and 192.168.100.2 on port 4789, with a VXLAN header (`vni 42`). The second line is the original packet inside it: first the ARP exchange that resolves 10.42.0.2 to a MAC address, then the ICMP echo request and reply between the overlay addresses. The underlay only ever routes the outer 192.168.100.x addresses. If you capture on `vxlan42` instead of `veth-a`, you see only the inner ARP and ICMP packets, as a container would. For more capture filters, see [TCPDump Basics](https://cycle.io/learn/tcpdump-basics).

#### Step 4: check the overlay MTU

`ping -M do` sets the Don't Fragment bit. 1422 bytes of ICMP payload plus 28 bytes of ICMP and IP headers is exactly 1450:

```bash
ip netns exec host-a ping -c 1 -M do -s 1422 10.42.0.2
ip netns exec host-a ping -c 1 -M do -s 1423 10.42.0.2
```

```
PING 10.42.0.2 (10.42.0.2) 1422(1450) bytes of data.
1430 bytes from 10.42.0.2: icmp_seq=1 ttl=64 time=1.02 ms
...
PING 10.42.0.2 (10.42.0.2) 1423(1451) bytes of data.
ping: local error: message too long, mtu=1450
```

The same test between two real hosts is a quick way to find MTU problems on an overlay network.

#### Step 5: clean up

```bash
ip netns del host-a
ip netns del host-b
```

Deleting the namespaces removes the veth pair and both VXLAN interfaces. To build a VXLAN setup that persists across reboots, with multiple peers or a bridge for containers, see [Configuring VXLAN](https://cycle.io/learn/configuring-vxlan).

### When to use an overlay network, and the trade-offs

An overlay network is a good fit when:

-   **You cannot change the underlay.** In most clouds and shared data centers you cannot add routes for pod or container subnets to the physical network, but host-to-host traffic on one UDP port is easy to allow.
-   **Hosts sit on different subnets or sites.** The overlay only needs IP reachability between hosts, so it works across layer 3 boundaries, regions and providers, including hybrid and multi-cloud setups.
-   **You need many isolated segments.** A 24-bit VNI gives far more segments than the 4,094 usable VLAN IDs, and creating one needs no switch change. See [Network Segmentation Basics](https://cycle.io/learn/network-segmentation-basics).
-   **Workloads move.** Containers can be rescheduled to another host and keep their overlay addressing.

Native routing (pod IPs routed by the underlay, usually with BGP or cloud VPC routes) is often the better choice when you control the network, need the highest throughput or lowest latency, or want packet captures and flow logs that show real workload IPs.

The trade-offs to plan for:

-   **Encapsulation overhead.** Every packet carries 20 to 60 or more extra bytes and goes through encapsulation on both hosts. NIC offloads for VXLAN and Geneve can reduce the CPU cost. Measure on your own hardware before choosing between an overlay and native routing for a throughput-sensitive workload.
-   **MTU problems.** The overlay MTU must be smaller than the underlay MTU. When it doesn't, small packets pass but large ones are dropped, which shows up as connections that hang. Step 4 above shows how to find the limit with a don't-fragment ping.
-   **Harder troubleshooting.** There are two networks to debug. A failure can be in the underlay (host reachability, a blocked UDP port, ESP filtered by a security group) or in the overlay (wrong peer mapping, wrong VNI, MTU). Capture on both the host NIC and the overlay interface. See [Troubleshooting Linux Networking](https://cycle.io/learn/troubleshooting-linux-networking).
-   **Firewall rules.** The tunnel port (4789, 8472 or 6081, depending on the platform) and any control-plane ports must be open between every pair of hosts.
-   **Security.** An overlay isolates traffic logically, but plain VXLAN, Geneve and IP-in-IP are not encrypted. Anyone who can capture underlay traffic can read the inner packets. Use an encrypted option (Docker's `--opt encrypted`, WireGuard or IPsec in the CNI plugin, or [IPsec](https://cycle.io/learn/configuring-ipsec) between hosts) when the underlay is not trusted, and budget for the extra overhead.

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
