VXLAN or WireGuard?

Connecting two servers does not automatically require extending Ethernet. For secure IP access, WireGuard authenticates peers and protects transport; for a VM migration requiring a shared segment, VXLAN carries Ethernet over a routed network. This guide tests each separately and then together. Combining them is justified only when the Layer 2 need remains after considering broadcasts, loops, latency and failure scope.

VXLAN does not encrypt traffic by itself. It can run over WireGuard when both Ethernet connectivity and encryption are required. Here we configure each separately so the first setup stays easy to follow.

Layer, security and MTU are different decisions

Compare performance on the intended topology and workload
Property VXLAN WireGuard VXLAN over WireGuard
Payload Ethernet, including ARP/broadcasts; L2 overlay IPv4/IPv6 packets; routed L3 interface Ethernet inside an authenticated IP tunnel
Encapsulation UDP + 8-byte VXLAN header; outer IP routing Encrypted UDP; key-based peer selection VXLAN UDP packet becomes WireGuard inner IP
Encryption None; restrict VTEP reachability Authenticated encryption; private keys per peer WireGuard protects the complete VXLAN packet
MTU budget 50 bytes above untagged inner IP over IPv4; 70 over IPv6 At least 60/80 bytes for outer IPv4/IPv6, plus padding wg0 MTU 1420 minus IPv4 VXLAN 50 = inner IP 1370
Routes and NAT VTEPs need bidirectional IP reachability; UDP mapping must remain usable AllowedIPs and routes must agree; reachable endpoint/keepalive for NAT Route VTEP IPs over wg0; expose only WireGuard UDP on WAN
Operational cost MAC/FDB and broadcast/loop diagnostics Keys, routes, handshake and IP access policy Both operating models, smaller MTU and two failure layers
Separate labs: Ethernet over UDP versus encrypted IP over UDP
Separate labs: Ethernet over UDP versus encrypted IP over UDP — Open the diagram to zoom.

Before you start

Use two Ubuntu 24.04 servers, A and B, with sudo access. For the VXLAN lab, their existing private addresses are 192.168.10.11 and 192.168.10.12. They must already reach each other; check with ping before creating a tunnel.

BASH
sudo apt update
sudo apt install -y iproute2 iputils-ping wireguard
ip -br address
ip route

Run this on both servers. Find the interface used to reach the other host; the examples use ens18. Use unused tunnel subnets that do not overlap your existing networks.

The unencrypted VXLAN example belongs on a private lab network. On an existing UFW host, scope UDP 4789 to the peer source and destination. On A use the rule below; on B swap .11 and .12. Keep existing SSH permission and do not enable UFW without reviewing the whole policy.

BASH
sudo ufw allow in on ens18 from 192.168.10.12 to 192.168.10.11 port 4789 proto udp
sudo ufw status numbered

Set up VXLAN

On A, create VXLAN with VNI 100 and address 10.20.0.1. Linux supplies the tunnel support in the kernel and iproute2 supplies its configuration tools. If a firewall is active, allow UDP/4789 only between these two private IPs; public exposure is outside this lab design.

BASH
sudo ip link add vxlan100 type vxlan id 100 local 192.168.10.11 remote 192.168.10.12 dev ens18 dstport 4789
sudo ip link set dev vxlan100 mtu 1450
sudo ip address add 10.20.0.1/24 dev vxlan100
sudo ip link set dev vxlan100 up

On B, reverse the endpoint addresses and use 10.20.0.2 for the tunnel. Both sides must use VNI 100 and destination port 4789.

BASH
sudo ip link add vxlan100 type vxlan id 100 local 192.168.10.12 remote 192.168.10.11 dev ens18 dstport 4789
sudo ip link set dev vxlan100 mtu 1450
sudo ip address add 10.20.0.2/24 dev vxlan100
sudo ip link set dev vxlan100 up

From A, test the other tunnel address. MTU 1450 assumes an IPv4 underlay with MTU 1500; a smaller path needs a smaller tunnel MTU. This connects the two hosts without bridging their physical LANs.

BASH
ping -c 4 10.20.0.2
ip -d link show vxlan100

These ip commands are temporary and disappear after reboot. For this first lab, rerun them after reboot. For a permanent setup, recreate the same settings through your network manager. To remove this lab interface, use sudo ip link delete vxlan100.

Purpose: demonstrate one Ethernet overlay without touching the physical LAN bridge. Expected result: 10.20.0.1 and .2 exchange ARP/IP through VNI 100. Verification: ip -d link show vxlan100 and bridge fdb show dev vxlan100 after traffic. Failure analysis: check VNI/UDP port and peer route before the overlay address. Rollback: delete only vxlan100; the physical ens18 address and route remain in their existing manager.

Persist the private VXLAN lab with networkd

Use this method only on the two Ubuntu Server lab hosts where systemd-networkd is already active. These files match vxlan100 only and leave the physical interface configuration to its existing Netplan/network manager. If NetworkManager owns the overlay, use its equivalent profile instead; do not switch the host manager over SSH. Choose the A variable block on A and the B block on B, then run the shared block on both.

BASH
# Server A
LOCAL=192.168.10.11
REMOTE=192.168.10.12
OVERLAY=10.20.0.1/24
# Server B: use these values INSTEAD
# LOCAL=192.168.10.12
# REMOTE=192.168.10.11
# OVERLAY=10.20.0.2/24
BASH
systemctl is-active systemd-networkd
# Stop here unless the result is active, and confirm these files do not exist
sudo install -d -m 0755 /etc/systemd/network
sudo tee /etc/systemd/network/30-vxlan100.netdev > /dev/null <<EOF
[NetDev]
Name=vxlan100
Kind=vxlan
MTUBytes=1450
[VXLAN]
VNI=100
Local=$LOCAL
Remote=$REMOTE
DestinationPort=4789
Independent=yes
EOF
sudo tee /etc/systemd/network/30-vxlan100.network > /dev/null <<EOF
[Match]
Name=vxlan100
[Network]
Address=$OVERLAY
LinkLocalAddressing=no
EOF
# Remove the transient lab interface before networkd creates its replacement
sudo ip link delete vxlan100
sudo networkctl reload
networkctl status vxlan100
ip -d link show vxlan100

Expected result: networkd creates vxlan100 with MTU 1450 and the chosen overlay address. Verify with ping before and after a scheduled reboot; check journalctl -u systemd-networkd for unknown keys or conflicts. Rollback: remove these two new files, reload networkd and delete vxlan100. A reload does not remove every netdev whose file disappeared, so explicit interface deletion matters.

Create WireGuard keys

Before configuring WireGuard, give each server its own key pair. Use a new directory to avoid overwriting an existing installation's keys. Share public.key with the other endpoint and keep private.key on its own server; confusing the two roles prevents correct peer authentication.

BASH
mkdir -m 700 ~/wg-lab
cd ~/wg-lab
umask 077
wg genkey | tee private.key | wg pubkey > public.key
cat public.key
sudo install -d -m 700 /etc/wireguard

Purpose: generate distinct peer identities with restrictive permissions. Expected result: different public keys and private files readable only by their owner. Verification: ls -l ~/wg-lab and compare the exchanged public keys. Failure analysis: if the folder exists, inspect its keys instead of overwriting them. Rollback: retire unused keys only after removing their peer authorization; restore an existing configuration from its private backup.

Configure WireGuard

A is the reachable endpoint: it needs a public IP or port forwarding for UDP 51820. B may sit behind NAT. In this example we connect only their tunnel addresses, so no IP forwarding or internet NAT is needed.

On A, edit /etc/wireguard/wg0.conf with sudo nano. Replace A_PRIVATE_KEY with the contents of A private.key and B_PUBLIC_KEY with B public.key. Do not leave placeholders in the file.

INI
[Interface]
Address = 10.30.0.1/24
ListenPort = 51820
PrivateKey = A_PRIVATE_KEY

[Peer]
PublicKey = B_PUBLIC_KEY
AllowedIPs = 10.30.0.2/32

On B, create the same file with the following contents. Replace the keys, and change 203.0.113.10 to the real public address of A; that address is reserved for documentation.

INI
[Interface]
Address = 10.30.0.2/24
PrivateKey = B_PRIVATE_KEY

[Peer]
PublicKey = A_PUBLIC_KEY
Endpoint = 203.0.113.10:51820
AllowedIPs = 10.30.0.1/32
PersistentKeepalive = 25

AllowedIPs selects only the opposite tunnel IP in this example; Internet traffic keeps its existing route. PersistentKeepalive on B helps maintain its NAT mapping. If UFW is active on A, run sudo ufw allow 51820/udp and check the provider firewall too. Do not enable a new firewall remotely without preserving SSH access.

Purpose: Bind one private key and one remote public key to the tunnel IPs.

Expected result: Each peer allows the opposite /32 and B reaches A public UDP endpoint.

Verification: Start through wg-quick@wg0 and inspect wg show after generating traffic.

Failure analysis: Check peer key, endpoint DNS/IP, UDP policy and protected file permissions.

Rollback: Stop wg-quick@wg0 and restore any pre-existing private configuration.

Start and test WireGuard

On both servers, protect the configuration file and start the service. Do not run wg-quick up separately after starting it through systemd.

BASH
sudo chmod 600 /etc/wireguard/wg0.conf
sudo systemctl enable --now wg-quick@wg0
sudo wg show

Send traffic from B to 10.30.0.1 and inspect wg show again. A fresh latest handshake together with increasing transfer establishes encrypted exchange between the endpoints. The configured service starts after reboot too, but retest the path so service startup is not mistaken for working connectivity.

BASH
ping -c 4 10.30.0.1
sudo wg show

Carry VXLAN over the working WireGuard link

Complete the WireGuard test first. Keep its VTEP addresses 10.30.0.1 and 10.30.0.2 in AllowedIPs. Use a new VNI 200 and overlay subnet 10.40.0.0/24; this example does not bridge a real LAN. Explicitly set wg0 MTU 1420 in both wg0.conf Interface sections and restart the service during a maintenance window before adding this optional layer.

VNI 200 uses WireGuard tunnel addresses as VTEPs; WAN carries only encrypted UDP
VNI 200 uses WireGuard tunnel addresses as VTEPs; WAN carries only encrypted UDP — Open the diagram to zoom.
BASH
# Server A
sudo ip link add vxwg type vxlan id 200 local 10.30.0.1 remote 10.30.0.2 dev wg0 dstport 4789
sudo ip link set vxwg mtu 1370
sudo ip address add 10.40.0.1/24 dev vxwg
sudo ip link set vxwg up
sudo ufw allow in on wg0 from 10.30.0.2 to 10.30.0.1 port 4789 proto udp
# Server B
sudo ip link add vxwg type vxlan id 200 local 10.30.0.2 remote 10.30.0.1 dev wg0 dstport 4789
sudo ip link set vxwg mtu 1370
sudo ip address add 10.40.0.2/24 dev vxwg
sudo ip link set vxwg up
sudo ufw allow in on wg0 from 10.30.0.1 to 10.30.0.2 port 4789 proto udp
BASH
# Server A: allow ICMP on vxwg in your active host firewall
ping -M do -s 1342 -c 4 10.40.0.2
bridge fdb show dev vxwg
sudo wg show

Expected result: the 1370-byte IPv4 probe crosses the overlay and WireGuard counters increase. Failure analysis: test 10.30.0.2 before 10.40.0.2 to separate encryption/routing from VXLAN. Keep UDP 4789 closed on the WAN. To persist this optional variant, use the same networkd files with Name=vxwg, VNI=200, MTUBytes=1370, Local/Remote=10.30.0.x and Address=10.40.0.x/24; independent netdev creation avoids taking ownership of wg0 from wg-quick. Verify after reboot that WireGuard is ready before testing VXLAN traffic.

If a guest or namespace later joins a bridge, move its overlay IP from the VXLAN port to that bridge, give the guest MTU 1370 and add only dedicated virtual ports. This host-only experiment needs no IP forwarding; routing other LANs is a separate change. Check for alternate egress paths as well, because traffic leaving outside the tunnel is outside WireGuard’s protection.

When the connection fails

For VXLAN, start with underlay IPs, interface, VNI and UDP/4789 permission. For WireGuard without a handshake, check A's public IP, UDP/51820 and both public keys. If a handshake works but ping fails, inspect AllowedIPs, tunnel addresses and ICMP permission. This order separates encryption-path failures from inner-route failures.

BASH
sudo systemctl status wg-quick@wg0 --no-pager
sudo journalctl -u wg-quick@wg0 -n 30 --no-pager

Once this works, extend it only for a concrete need: remote LAN access needs routing, while Ethernet extension needs a bridge design. Avoid adding either before you have tested the basic connection.

Remove the experiment in dependency order

BASH
# Remove only files created for this experiment, after inspecting them
sudo rm -- /etc/systemd/network/30-vxlan100.netdev /etc/systemd/network/30-vxlan100.network
sudo networkctl reload
# Run only for an interface that exists and belongs to this lab
sudo ip link delete vxwg
sudo ip link delete vxlan100
sudo systemctl disable --now wg-quick@wg0

Remove the exact scoped UFW rules using ufw status numbered; indices change after each deletion. Preserve a private copy of wg0.conf and restore any pre-existing file instead of deleting it. The disabled service must no longer bring up wg0 on reboot. For networkd vxwg persistence also remove its two new files before deleting vxwg. Do not flush all routes, firewall rules or network-manager state.

Questions from deployment reviews

Can WireGuard replace VXLAN?

It can replace an L2 extension only when the application works across routed subnets. It does not transport Ethernet ARP or broadcasts by itself.

Why is the combined inner MTU 1370?

The configured WireGuard interface offers 1420 bytes for its inner IP packet. IPv4 VXLAN consumes 50 above the innermost IP packet, leaving 1370 before any additional tag.

References

Linux kernel VXLAN documentation

ip-link command reference

WireGuard installation

WireGuard quick start and keys

wg-quick configuration reference

Ubuntu 24.04 networkd VXLAN properties

RouterOS bridge/VLAN mapping counterpart

Share

Meet AJInfrastructure & DevOps
Loading…