Course contentsShow
← Linux
Lesson 1253 of 1,81910. Network Administration and Kernel StacksFree lesson

Advanced IPsec VPN Topologies

Create mesh-VPN networks using kernel-integrated IPsec.

In this lesson, you will learn how to transition from traditional hub-and-spoke VPNs to a full-mesh topology using Linux kernel-integrated IPsec.

Beyond the Hub-and-Spoke

In a standard hub-and-spoke topology, all traffic between branches must transit through a central gateway. This creates a bottleneck and adds unnecessary latency. A full-mesh topology allows each node in your network to establish direct, encrypted IPsec tunnels to every other node. By leveraging the Linux kernel’s XFRM (Transform) framework, we can build these direct paths without needing a central intermediary.

Implementing the Mesh with XFRM

The key to a mesh is managing Security Policy Databases (SPD) and Security Association Databases (SAD) across all nodes. Instead of routing traffic to a central hub, each node is configured with a set of policies that recognize the internal subnets of its peers.

When Node A needs to talk to Node B, the kernel checks the SPD. If the destination matches a peer's subnet, the kernel invokes the specific Security Association (SA) for that direct connection, encapsulating the traffic using ESP (Encapsulating Security Payload) and sending it directly over the physical network interface.

Here is how you define a direct policy between two nodes using ip xfrm:

# Define the policy to secure traffic between Node A and Node B
ip xfrm policy add src 10.0.1.0/24 dst 10.0.2.0/24 dir out tmpl src <NodeA_IP> dst <NodeB_IP> proto esp mode tunnel

Scaling Considerations

While full-mesh offers the lowest latency and highest redundancy, it grows quadratically; for nn nodes, you require n(n−1)/2n(n-1)/2 tunnels. As a network administrator, you must ensure your kernel’s security policies are correctly versioned across your infrastructure. If a new node joins the mesh, it must broadcast its identity and subnet routes so that every existing node can update its own SPD/SAD tables. When combined with the Network Namespace Persistence techniques we covered earlier, you can isolate these VPN tunnels into specific namespaces to ensure that your encrypted mesh remains logically separate from your primary management traffic.

Key Takeaway: Full-mesh IPsec replaces centralized bottlenecks with peer-to-peer tunnels managed directly by the kernel's XFRM framework, minimizing latency through direct site-to-site encryption.