Loopback, MTU and Tunnels: GRE, VXLAN and WireGuard
The loopback interface and 127.0.0.0/8, what the MTU and path MTU are and what happens when a packet is too big, how tunnels such as IP-in-IP, GRE, VXLAN and WireGuard wrap packets and what each costs, links that work in only one direction, and the classic attacks on the link layer.
kvi5hnuCode Sprout team member19 min readOn this page
This article collects several link-layer topics that every network engineer runs into: the loopback interface, which isn't a real link at all; the MTU, which limits every real one; tunnels, which build virtual links on top of IP; and the ways attackers abuse the link layer.
Loopback
Every host has a loopback interface, lo on Linux. Packets sent to it never reach any hardware: the kernel hands them straight back to its own receive path. Clients and servers on the same machine use it to talk to each other, and it works even with no network connected at all. In the output below, LOOPBACK marks the interface type, its "MAC address" is all zeros because there's no hardware, and scope host means the addresses are valid only inside this machine:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host proto kernel_lo
valid_lft forever preferred_lft forever
In IPv4, the whole block 127.0.0.0/8 is reserved for loopback (article 11), and on Linux every address in it answers, not only 127.0.0.1. IPv6 has just one loopback address, ::1:
PING 127.1.2.3 (127.1.2.3) 56(84) bytes of data.
64 bytes from 127.1.2.3: icmp_seq=1 ttl=64 time=0.031 ms
PING ::1 (::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.022 ms
ping: connect: Network is unreachable
The first two pings worked. The last line is the attempt to ping ::2: it isn't a loopback address, and with no other network configured there's no route to it. The kernel handles loopback with local routes in a separate routing table (ip route show table local). A route of type local means "deliver to this host", and 127.0.0.0/8 is one route covering the whole block:
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
local ::1 dev lo proto kernel metric 0 pref medium
Some points that often surprise people:
- Packets to the host's own addresses also go through loopback. If your machine is
192.0.2.10, a connection to192.0.2.10never appears on the Ethernet. A capture oneth0won't see it, but one onlowill. - A router must never forward a packet with a
127.x.x.xsource or destination, and hosts must drop such packets if they arrive from outside. - The loopback MTU is large (65536 on Linux) because there's no physical limit, which makes local transfers fast.
- Not every system behaves like Linux here. Windows also answers the whole block, but macOS configures only
127.0.0.1onlo0, so another127.xaddress must be added first (for examplesudo ifconfig lo0 alias 127.0.0.2).
The MTU and path MTU
Every link technology has a maximum payload per frame, the maximum transmission unit (MTU): 1500 bytes for standard Ethernet, 1492 for PPPoE (article 19), up to about 9000 for jumbo frames in data centers, and 65536 for loopback. The MTU counts the IP packet, not the link-layer header.
A packet crossing several links is limited by the smallest MTU on its path, the path MTU. In IPv4, a router that must forward a packet larger than the next link's MTU can fragment it (article 46), unless the sender set the don't fragment (DF) bit. Then the router drops the packet and returns an ICMP (Internet Control Message Protocol, IP's error-reporting companion, article 39) "fragmentation needed" error with the next hop's MTU. IPv6 routers never fragment and always send "packet too big". Senders use these errors for Path MTU Discovery (article 47). Because those ICMP errors are often filtered, current stacks don't rely on them alone: TCP can probe the path itself (packetization-layer PMTUD, RFC 4821), and QUIC (the UDP-based transport under HTTP/3, article 86) always does, with the datagram version from RFC 8899.
The lab built a path a → r → s where the link from r to s has an MTU of 1400:
a eth0: mtu 1500
r e1 (toward s): mtu 1400
a sent a 1500-byte ping with DF set (-M do):
PING 198.51.100.20 (198.51.100.20) 1472(1500) bytes of data.
From 192.0.2.1 icmp_seq=1 Frag needed and DF set (mtu = 1400)
ping: sendmsg: Message too long
--- 198.51.100.20 ping statistics ---
The router dropped it and answered with an ICMP error naming the MTU, as the capture on a shows. (length 1480 is the ICMP message alone: the 1500-byte packet minus its 20-byte IPv4 header.)
IP 192.0.2.10 > 198.51.100.20: ICMP echo request, id 76, seq 1, length 1480
IP 192.0.2.1 > 192.0.2.10: ICMP 198.51.100.20 unreachable - need to frag (mtu 1400), length 556
a's kernel stored the learned path MTU for that destination for about 10 minutes, and now refused locally to send anything bigger:
198.51.100.20 via 192.0.2.1 dev eth0 src 192.0.2.10
cache expires 596sec mtu 1400
1380 bytes from 198.51.100.20: icmp_seq=1 ttl=63 time=0.202 ms
ping: sendmsg: Message too long
A 1372-byte payload plus 8 bytes of ICMP header and 20 of IPv4 header is exactly 1400 bytes. One byte more no longer fits. Path MTUs aren't fixed: routes can change, and with them the smallest link, so the learned value expires.
Tunnels
A tunnel carries packets of one network inside packets of another. The sender wraps (encapsulates) each packet in a new outer header addressed to the far end of the tunnel. The routers in between see only the outer header, and the far end unwraps the packet and forwards it as if the two tunnel endpoints were directly connected. Tunnels connect sites across the Internet (VPNs, virtual private networks), carry IPv6 over IPv4-only networks, stretch a LAN across a data center, or isolate tenants' traffic from each other.
On Linux, a tunnel appears as a virtual interface with its own addresses and routes. The lab connected two hosts over one Ethernet link (the underlay, 192.0.2.1 and 192.0.2.2) and built six tunnels between them, each with its own small inner subnet (the overlay). The diagram below lines up the headers each tunnel type adds in front of the original packet. Keep it in mind: those extra bytes are what the MTU table later in this section measures.

IP-in-IP and GRE
IP-in-IP (RFC 2003) is the simplest: a new IPv4 header with protocol number 4 in front of the original packet. It carries only IPv4 (Linux's sit and ip6tnl tunnel types handle the IPv6 cases).
Generic Routing Encapsulation (GRE, RFC 2784), IP protocol 47, adds a small header between the outer IP header and the payload. Its protocol type field uses EtherType values, so GRE can carry IPv4, IPv6, MPLS (Multiprotocol Label Switching, which providers use to forward on short labels instead of IP addresses) or whole Ethernet frames (0x6558, "transparent Ethernet bridging", which Linux calls gretap). Optional fields, from RFC 2890, add a key, which identifies one of several tunnels between the same endpoints, a sequence number and a checksum. Here is a ping over the lab's GRE tunnel with key 7:
Internet Protocol Version 4, Src: 192.0.2.1, Dst: 192.0.2.2
Protocol: Generic Routing Encapsulation (47)
Source Address: 192.0.2.1
Destination Address: 192.0.2.2
Generic Routing Encapsulation (IP)
Flags and Version: 0x2000
..1. .... .... .... = Key Bit: Yes
...0 .... .... .... = Sequence Number Bit: No
Key: 0x00000007
Internet Protocol Version 4, Src: 198.51.100.13, Dst: 198.51.100.14
Protocol: ICMP (1)
Source Address: 198.51.100.13
Destination Address: 198.51.100.14
Internet Control Message Protocol
The outer header goes from 192.0.2.1 to 192.0.2.2 with protocol 47. The GRE header has the key bit set and key 7, and inside is the original packet between the overlay addresses 198.51.100.13 and 198.51.100.14.
GRE was also the base of PPTP, an old Microsoft VPN protocol whose authentication (MS-CHAPv2) and encryption (MPPE) are broken. Don't use it. L2TP (RFC 2661, version 3 in RFC 3931) carries PPP sessions (article 19) over UDP port 1701 and is used between broadband providers. As a VPN, it's normally combined with IPsec, because L2TP itself doesn't encrypt.
GRE and IP-in-IP have no encryption or authentication of their own. Anyone on the path can read the inner packets, and anyone who can send packets to an endpoint with the right outer addresses can inject packets into the tunnel. Use them inside a trusted network, or protect them with IPsec.
VXLAN
VXLAN (RFC 7348) carries Ethernet frames inside UDP, to port 4789, with an 8-byte header containing a 24-bit VXLAN network identifier (VNI). Sixteen million VNIs replace the 4094 VLANs (article 15), and because it's ordinary UDP, it crosses any routed IP network. Data centers use it to give each tenant or application its own Layer 2 segment on top of a routed leaf-spine fabric, usually with BGP EVPN (Ethernet VPN routes carried by BGP, the Internet's routing protocol between networks) distributing MAC addresses (article 17).
Ethernet II
Internet Protocol Version 4
Source Address: 192.0.2.1
Destination Address: 192.0.2.2
User Datagram Protocol, Src Port: 41011, Dst Port: 4789
Virtual eXtensible Local Area Network
VXLAN Network Identifier (VNI): 42
Ethernet II
Internet Protocol Version 4
Source Address: 198.51.100.21
Destination Address: 198.51.100.22
Ethernet II
The outer UDP source port varies from flow to flow. It's derived from a hash of the inner headers, so routers that balance traffic over equal-cost paths by port spread VXLAN flows too. Geneve (RFC 8926) is a newer, extensible format on UDP port 6081 that cloud and virtualization platforms use for the same purpose.
WireGuard
WireGuard is a VPN protocol built into Linux since version 5.6 (2020) and available on all major platforms. Each peer has a Curve25519 key pair (public-key cryptography based on elliptic curves, article 79), peers are configured with each other's public keys, and the protocol runs over UDP. It encrypts and authenticates every packet with ChaCha20-Poly1305, a modern cipher that also adds a tag proving the packet wasn't altered:
192.0.2.1 → 192.0.2.2 WireGuard 170 Transport Data, receiver=0x8C36F234, counter=8, datalen=96
192.0.2.2 → 192.0.2.1 WireGuard 170 Transport Data, receiver=0xC5B745FB, counter=8, datalen=96
transport data: frame 170 bytes, receiver index 0x8c36f234, counter 8 (the inner ping is encrypted)
A capture shows only the outer IP and UDP headers, a message type, a receiver index (a random session identifier) and a counter, which protects against replays. The inner ping is unreadable. The 96 bytes of data are the 84-byte ping packet padded to a multiple of 16, and a 16-byte authentication tag follows. Article 82 covers WireGuard's handshake and how it compares with IPsec.
What tunnels cost: overhead and MTU
Every tunnel's headers take space from the underlay's MTU. The lab measured the largest packet that crossed each tunnel with DF set:
tunnel interface MTU largest IPv4 packet that got through overhead
IP-in-IP 1480 1480 20B
GRE 1476 1476 24B
GRE with a key 1472 1472 28B
GRE carrying Ethernet (gretap) 1462 1462 38B
VXLAN 1450 1450 50B
WireGuard 1420 1420 80B

Linux sized each tunnel interface from its overhead: 20 bytes for IP-in-IP, 24 for GRE (28 with a key), 38 for gretap (GRE plus a 14-byte inner Ethernet header), and 50 for VXLAN. WireGuard is the exception: it adds 60 bytes over IPv4 but 80 over IPv6, and Linux's default MTU of 1420 assumes the worse case so the same configuration works on both.
Getting the tunnel MTU wrong is one of the most common causes of mysterious network problems. If a tunnel interface claims a larger MTU than really fits, large packets are either fragmented after encapsulation, which costs performance, or dropped. When the ICMP errors that should report this are filtered, the result is a black hole: pings and small requests work, but large downloads, TLS handshakes with big certificates or SSH sessions with long output hang (article 47). The usual fixes are a correct tunnel MTU, TCP MSS clamping on the tunnel's routers (lowering the maximum segment size in connection-opening SYN packets, article 19), or a larger MTU on the underlay (data centers often run 9000-byte jumbo frames so that 1500-byte overlay packets fit).
Tunnels for IPv6 transition
Several tunnels were designed to carry IPv6 across IPv4 networks. 6in4 (manually configured, protocol 41) is still used by tunnel brokers. 6to4 (RFC 3056) derived a site's IPv6 prefix from its IPv4 address and relied on public relays. Because the relays were unreliable, it was deprecated in 2015 (RFC 7526). Teredo (RFC 4380) tunneled IPv6 in UDP to get through NAT (network address translation, article 35), and Windows has shipped with it turned off since Windows 10 version 1803. Article 38 covers these and the current transition mechanisms.
Unidirectional links
Some links carry data in only one direction, such as a satellite downlink to a receive-only dish. Routing protocols and ARP assume that if A hears B, then B hears A, so such links break them. RFC 3077 defines a link-layer tunneling mechanism: the receivers send their return traffic through a tunnel over another path (a terrestrial link) to the feed, and a protocol called DTCP (Dynamic Tunnel Configuration Protocol) announces where those tunnels end. To the protocols above, the link then looks bidirectional. Such links are rare today, but the idea, a separate return path hidden below IP, shows up in broadcast and some satellite systems.
Attacks on the link layer
Because the link layer is the basis of everything above it, attacks on it are powerful, though they need local access: the attacker must be on the same LAN, Wi-Fi network or tunnel.
Sniffing
A network card normally passes up only frames addressed to it, its multicast groups and broadcasts. In promiscuous mode (which tcpdump turns on), it passes up everything it sees. On a shared medium, such as old Ethernet hubs or an open Wi-Fi network, that's all traffic. On a switched network, an attacker normally sees only flooded frames, unless they make the switch flood everything.
MAC table flooding
A switch's filtering database is finite (article 17). An attacker who sends frames from thousands of fake source addresses fills it. When the table is full, the switch can't learn real stations, so it floods their traffic to every port, including the attacker's. The lab limited a Linux bridge to 1000 learned entries (fdb_max_learned, added in Linux 6.7), and an attacker port sent 3000 frames from random addresses:
attacker m sent 3000 frames, each from a different random MAC address
fdb_n_learned 1000 fdb_max_learned 1000
1000 learned addresses on port p3
The table filled up entirely with the attacker's fake addresses. Then h1 pinged h2. Because the bridge had never been able to learn either of them, it flooded every frame, and the attacker captured the whole conversation. Each captured line starts with source MAC > destination MAC: none of these frames was addressed to the attacker, yet it received every request and reply:
3 packets transmitted, 3 received, 0% packet loss, time 608ms
the attacker's capture:
02:00:00:00:00:01 > 02:00:00:00:00:02, ethertype IPv4 (0x0800), length 98: 192.0.2.1 > 192.0.2.2: ICMP echo request, id 74, seq 1, length 64
02:00:00:00:00:02 > 02:00:00:00:00:01, ethertype IPv4 (0x0800), length 98: 192.0.2.2 > 192.0.2.1: ICMP echo reply, id 74, seq 1, length 64
02:00:00:00:00:01 > 02:00:00:00:00:02, ethertype IPv4 (0x0800), length 98: 192.0.2.1 > 192.0.2.2: ICMP echo request, id 74, seq 2, length 64
02:00:00:00:00:02 > 02:00:00:00:00:01, ethertype IPv4 (0x0800), length 98: 192.0.2.2 > 192.0.2.1: ICMP echo reply, id 74, seq 2, length 64
02:00:00:00:00:01 > 02:00:00:00:00:02, ethertype IPv4 (0x0800), length 98: 192.0.2.1 > 192.0.2.2: ICMP echo request, id 74, seq 3, length 64
02:00:00:00:00:02 > 02:00:00:00:00:01, ethertype IPv4 (0x0800), length 98: 192.0.2.2 > 192.0.2.1: ICMP echo reply, id 74, seq 3, length 64
Without a limit, a Linux bridge keeps learning until memory runs out, which is a denial-of-service risk of its own. Hardware switches defend against flooding with port security, limiting the number of MAC addresses each port may learn and shutting down a port that exceeds it, and with 802.1X so that only authenticated devices get onto a port (article 81).
Spanning tree and other control protocol attacks
A device that sends BPDUs (bridge protocol data units, the spanning tree protocol's control messages) with priority 0 can become the root bridge (article 17), so traffic flows through it or the tree keeps recomputing. BPDU guard and root guard on edge ports prevent this. Similar attacks target VLAN negotiation (an attacker port that negotiates a trunk, or double-tagged frames that hop VLANs, article 15) and LACP (the link aggregation control protocol, also article 15). The general defense is to disable negotiation protocols on ports that face users.
ARP attacks
ARP has no authentication at all, so anyone on a LAN can claim any IP address and redirect traffic. Article 22 shows this in detail, with its defenses.
Wireless attacks
On Wi-Fi, anyone within range can capture frames, and directional antennas extend that range a long way. "War driving", scanning neighborhoods for open or weakly protected networks, made this famous. WEP was broken within a couple of years, and WPA2 with a weak password can be cracked offline from one captured handshake, which is why WPA3 matters (article 18). Evil twin access points copy a network's name to lure clients, and forged deauthentication frames (until protected management frames became mandatory) kicked clients off so they would reconnect to the attacker. Open networks with captive portals (the login page at a café or hotel) authorize clients by MAC address after login, so an attacker can copy a logged-in client's address and use its access.
Attacks on PPP and tunnels
PAP sends passwords in clear text, and even CHAP exchanges can be attacked offline (article 19). Unencrypted tunnels such as GRE, IP-in-IP and VXLAN can be read on the path, and an attacker who can spoof the outer source address can inject packets that the far end unwraps and forwards into a private network. Filter tunnel protocols at network borders, accept them only from known endpoints, and use an encrypted tunnel such as WireGuard or IPsec across untrusted networks.
Common questions
Why can't I see traffic between two programs on my own machine in Wireshark?
It goes over the loopback interface, not your network card, even when you use the machine's own LAN address. Capture on lo (Linux), lo0 (macOS) or the "Adapter for loopback traffic capture" (Windows with Npcap).
Is 127.0.0.1 the same as localhost?
localhost is a name that normally resolves to 127.0.0.1 and ::1. Programs that try IPv6 first will use ::1, so a server listening only on 127.0.0.1 may refuse a connection to localhost that a client makes over IPv6.
What MTU should I set on a VPN interface?
The underlay MTU minus the tunnel's overhead, for the worst case of your underlay. For WireGuard, 1420 is a safe default on a 1500-byte network. Over PPPoE (1492), use 1412 or lower, and over mobile networks lower still. If unsure, measure with DF-set pings as in the lab.
Why does my VPN work for browsing some sites but hang on others?
That's the classic symptom of an MTU black hole. Small packets fit, but full-size ones are dropped somewhere, and the ICMP error that should tell your computer is filtered. Lower the tunnel MTU or enable MSS clamping.
Is VXLAN a VPN?
No. VXLAN separates networks logically but doesn't encrypt or authenticate anything. It's meant for networks under one operator's control. To cross the Internet, run it inside an encrypted tunnel or use a VPN protocol instead.
Can a switch be made immune to MAC flooding?
It can be made resistant: limit MAC addresses per port (port security), authenticate devices with 802.1X, and monitor for ports that learn many addresses. Separate VLANs also contain the damage, since flooding stays within one VLAN.
Summary
- Loopback (
lo) returns packets to the host itself. IPv4 reserves127.0.0.0/8, IPv6 only::1. Traffic to the host's own addresses also uses loopback and never reaches the wire. - The MTU is the largest IP packet a link carries: 1500 for Ethernet, 1492 for PPPoE, about 9000 for jumbo frames. The path MTU is the smallest along a path. With DF set, a router drops too-large packets and reports the MTU in an ICMP error, and the sender caches it.
- Tunnels wrap packets in new outer headers: IP-in-IP (protocol 4), GRE (protocol 47, with optional key and sequence number, and Ethernet over GRE as gretap), VXLAN (Ethernet in UDP 4789 with a 24-bit VNI), Geneve, L2TP, and WireGuard (encrypted, over UDP).
- Each tunnel's overhead reduces the MTU: 20 bytes for IP-in-IP, 24 for GRE, 38 for gretap, 50 for VXLAN, 60 or 80 for WireGuard. Wrong tunnel MTUs cause fragmentation or black holes.
- 6to4 and Teredo are retired IPv6 transition tunnels. RFC 3077 makes unidirectional links usable by tunneling the return path.
- Link-layer attacks need local access but are powerful: sniffing in promiscuous mode, MAC table flooding (which the lab showed turning a switch into a hub), STP and VLAN negotiation attacks, ARP spoofing, Wi-Fi attacks and injection into unencrypted tunnels. Port security, 802.1X, BPDU guard, WPA3 and encrypted tunnels are the main defenses.
Practice questions
1. Your host's address is 192.0.2.10. You run curl http://192.0.2.10/ on the same host while capturing on eth0. What do you see, and why?
Answer
Nothing from this connection. The kernel recognizes 192.0.2.10 as one of its own addresses (a local route) and delivers the packets over the loopback interface. Capture on lo to see them.
2. A router receives a 1500-byte IPv4 packet with DF set, and the next link's MTU is 1280. What does it do, and what does the sender do next?
Answer
It drops the packet and returns an ICMP destination unreachable, "fragmentation needed and DF set", message containing the next-hop MTU of 1280. The sender caches a path MTU of 1280 for that destination and sends smaller packets, for TCP by reducing the segment size.
3. A VXLAN tunnel runs over an underlay with an MTU of 1500. What is the largest inner IP packet that fits without fragmentation, and what underlay MTU would let 1500-byte inner packets through?
Answer
1500 − 50 = 1450 bytes (20 outer IPv4 + 8 UDP + 8 VXLAN + 14 inner Ethernet). To carry 1500-byte inner packets, the underlay needs an MTU of at least 1550, which is why VXLAN fabrics often use jumbo frames.
4. Why does the GRE header have a protocol type field, and what value means "an Ethernet frame follows"?
Answer
Because GRE is generic: the protocol type tells the receiver what kind of packet is inside, using EtherType values (for example 0x0800 IPv4, 0x86DD IPv6). 0x6558 (transparent Ethernet bridging) means the payload is a whole Ethernet frame, as in Linux's gretap.
5. An attacker on a switch port starts sending frames from tens of thousands of random source MAC addresses. Explain what happens to traffic between two other hosts, and name two defenses.
Answer
The switch's MAC table fills with fake entries. The legitimate hosts' entries age out or can't be learned, so the switch floods their unicast traffic to all ports in the VLAN, and the attacker receives a copy. Defenses: port security limiting addresses per port, 802.1X authentication on access ports, and VLAN separation to contain flooding.
6. WireGuard adds 60 bytes over IPv4. Why does Linux default the WireGuard interface MTU to 1420 rather than 1440?
Answer
Over IPv6, the outer header is 40 bytes instead of 20, so the overhead is 80 bytes. One configuration may be used over either IPv4 or IPv6 (and an endpoint can change), so 1500 − 80 = 1420 is safe in both cases.
Previous: PPP and PPPoE: Point-to-Point Links and Broadband Sessions
Next: ARP: How IPv4 Finds the MAC Address, the ARP Cache and the Frame Format

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.