Privacy Tools Guide

Optimize VPN speed by reducing MTU from the standard 1500 bytes to 1400-1450 bytes to account for WireGuard’s 60-byte or OpenVPN’s 50-70 byte overhead; test your optimal value using ping with the don’t-fragment flag to discover path MTU, then subtract 28 bytes for IP/ICMP headers to find your ideal setting. Incorrect MTU causes packet fragmentation that forces CPU-intensive reassembly on both endpoints and triggers PMTUD black holes; start at 1400 and incrementally increase until ping fails, then configure that value on your VPN interface to eliminate retransmissions and improve throughput by 10-30%.

Understanding MTU and VPN Overhead

The standard Ethernet MTU is 1500 bytes. When you establish a VPN tunnel, additional headers encapsulate your traffic. WireGuard adds 60 bytes overhead, OpenVPN adds approximately 50-70 bytes depending on configuration, and IPsec can add 50-80 bytes. If your MTU remains at 1500 while the tunnel overhead consumes header space, packets exceed the physical link limit and fragment into smaller units.

Fragmentation introduces CPU overhead on both endpoints and increases latency through additional processing. In worst-case scenarios, fragmented packets trigger PMTUD (Path MTU Discovery) black holes where ICMP messages get blocked, causing connections to stall indefinitely.

Diagnosing MTU Problems

The first step is identifying whether MTU contributes to your performance issues. Use the ping test with the “don’t fragment” flag to discover the path MTU:

# Test path MTU to your VPN server
ping -M do -s 1472 10.0.0.1  # Start with 1472 (1500 - 28 ICMP header)

Replace 10.0.0.1 with your VPN server IP. If packets succeed, try increasing the size gradually. When ping fails, you’ve exceeded the path MTU. The highest successful value plus 28 (IP and ICMP headers) gives you the optimal MTU.

A more approach uses tracepath or mtu-path discovery:

tracepath -n vpn.example.com

Look for the “pmtu” values along the path. Some network segments might have lower MTU limits than others, particularly if you’re traversing tunnel networks or satellite links.

Finding Your Optimal MTU Value

The theoretical optimum accounts for all encapsulation layers. For a typical WireGuard VPN:

However, this calculation assumes no additional network segments with reduced MTU. The empirical approach yields more reliable results.

Create a simple bash script to automate MTU testing:

#!/bin/bash
HOST="$1"
START=1400
END=1500

for ((mtu=START; mtu<=END; mtu+=10)); do
    if ping -M do -s $((mtu-28)) -c 3 "$HOST" >/dev/null 2>&1; then
        echo "Success at MTU $mtu"
    else
        echo "Failed at MTU $mtu"
    fi
done

Run this script targeting your VPN server:

./mtu-test.sh vpn.example.com

The output reveals the highest MTU that works without fragmentation. Subtract a safety margin of 20-40 bytes to account for network path variations.

Configuring MTU in Common VPN Solutions

WireGuard

WireGuard exposes the MTU parameter in the interface configuration. Edit your WireGuard configuration file (typically /etc/wireguard/wg0.conf):

[Interface]
Address = 10.0.0.2/24
PrivateKey = <your-private-key>
MTU = 1420
ListenPort = 51820

[Peer]
PublicKey = <server-public-key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Calculate the MTU by taking your discovered path MTU and subtracting the WireGuard overhead (60 bytes). If your path MTU tests at 1480, set WireGuard MTU to 1420.

OpenVPN

OpenVPN requires the tun-mtu directive in your client or server configuration:

# Add to both client and server config
tun-mtu 1400
tun-mtu-extra 32
mssfix 1400

The mssfix directive adjusts the TCP Maximum Segment Size, preventing fragmentation at the application layer. Adjust these values based on your path MTU testing results.

IPsec (StrongSwan)

For IPsec tunnels using StrongSwan, configure MTU in /etc/ipsec.conf:

# In the conn section
leftmtu=1400
rightmtu=1400

You may also need to adjust interface settings system-wide:

# Check current interface MTU
ip link show

# Temporarily adjust MTU
ip link set dev eth0 mtu 1400

Make permanent changes in your network configuration files (e.g., /etc/network/interfaces on Debian/Ubuntu or /etc/sysconfig/network-scripts/ on RHEL).

Automating MTU Discovery at Connection Time

Static MTU configuration works when your VPN route remains consistent. For dynamic scenarios where your VPN connects through varying network paths, implement automatic MTU detection.

Create a connection script that runs MTU tests before establishing the VPN:

#!/bin/bash
# auto-mtu.sh - Run before VPN connection

VPN_SERVER="$1"
OPTIMAL_MTU=1400  # Start with conservative default

# Discover path MTU
for size in 1472 1450 1400 1350 1300; do
    if ping -M do -s $size -c 2 -W 2 "$VPN_SERVER" >/dev/null 2>&1; then
        OPTIMAL_MTU=$((size + 28 - 60))  # Account for WireGuard overhead
        break
    fi
done

echo "Using MTU: $OPTIMAL_MTU"
# Apply MTU to WireGuard interface before connecting
wg set wg0 mtu $OPTIMAL_MTU 2>/dev/null || true

Run this script before your VPN connection command. Integrate it with systemd service templates for automated execution on connection.

Performance Verification

After configuring MTU, verify improvements using throughput testing:

# Install iperf3 if needed
brew install iperf3  # macOS
sudo apt install iperf3  # Linux

# Run server on VPN endpoint
iperf3 -s

# Run client through VPN
iperf3 -c 10.0.0.1 -P 4 -t 30

Compare throughput before and after MTU changes. Proper MTU configuration typically yields 5-15% throughput improvement and reduces latency variance. Use mtr or traceroute to verify fragmentation has stopped:

mtr -c 100 --no-dns vpn.example.com

Look for the “Loss%” column showing zero packet loss after optimization.

Troubleshooting Black Hole Connections

Some networks block ICMP messages required for PMTUD, causing connections to hang when packets exceed the path MTU. The mssfix directive in OpenVPN or setting a conservative MTU (like 1280) provides a workaround, though at the cost of some throughput.

For SSH connections over problematic paths, add this to your SSH config:

Host vpn.example.com
    MTU 1280

Built by theluckystrike — More at zovo.one