[How-To] Stand Up WireGuard P2P between two sites
Overview of the Setup
-
JAX01 (Your Homelab):
- Network: Multiple VLANs.
- VPN VM: Will be connected to a dedicated VLAN for VPN traffic.
- Local Networks: Accessible alongside the VPN.
-
JAX02 (Friend’s Homelab):
- Network: Single non-VLAN network (
192.168.60.0/22
). - VPN VM: Connected to the main network.
- Local Networks: Accessible alongside the VPN.
- Network: Single non-VLAN network (
-
Objective:
- JAX01: Access both local VLANs and JAX02’s network without disrupting local internet traffic.
- JAX02: Access both local network and JAX01’s network without disrupting local internet traffic.
- Avoid DHCP Conflicts: Ensure that DHCP servers on both sides do not interfere with each other.
Prerequisites
-
Ubuntu 24.04 Server VMs:
JAX01SITE01 VM: Connected to adedicatedlocalVLAN for VPN traffic.network.JAX02SITE02 VM: Connected totheamain
local network.192.168.60.0/22
-
Static IP Addresses:
- Ensure both VPN VMs have static IPs within their respective networks to maintain consistent VPN connectivity.
-
Firewall Access:
- Ensure that UDP port
51820
(default WireGuard port) is open on both networks' firewalls to allow VPN traffic.
- Ensure that UDP port
-
Access to Network Equipment:
- Ability to create and manage
VLANsnetworksonatJAX01’sbothnetwork infrastructure.sites.
- Ability to create and manage
Step-by-Step Installation and Configuration
1. Install WireGuard on Both Servers
On Both JAX01SITE01 and JAX02SITE02 VPN VMs:
-
Update Package Lists:
-
Install WireGuard:
2. Generate WireGuard Keys
On Both Servers:
-
Generate Private and Public Keys:
- Files Created:
privatekey
: Keep this secure; never share.publickey
: Share this with your peer.
- Files Created:
-
Exchange Public Keys:
JAX01'SITE01's VPN VM Public Key: Send toJAX02’SITE02’s VPN VM.JAX02'SITE02's VPN VM Public Key: Send toJAX01’SITE01’s VPN VM.
3. Configure Network Interfaces
JAX01 (Your Homelab):
Create a Dedicated VLAN for VPN Traffic:Assumption:Your primary network interface iseth0.VLAN ID:Choose an unused VLAN ID, e.g.,10.
Configure the VLAN Interface:Edit the Netplan configuration:Add the VLAN configuration:Apply Netplan Configuration:Note:Ensure10.10.10.0/24is not overlapping with any existing networks.
JAX02 (Friend’s Homelab):
Ensure VPN VM is on the Main Network (192.168.60.0/22):Assign a static IP, e.g.,192.168.60.10.
4. Configure WireGuard on Both Servers
JAX01SITE01 VPN VM Configuration:
-
Create WireGuard Configuration File:
-
Add the Following Configuration:
[Interface] PrivateKey = <JAX01_PrivateKey> Address = 10.
10.10.1/6.0.5/24 ListenPort = 51820 SaveConfig = true [Peer] PublicKey = <JAX02_PublicKey> AllowedIPs = 192.168.168.60.0/22,0/22, 10.10.10.2/6.0.10/32 Endpoint = <JAX02_Public_IP>:51820 PersistentKeepalive = 25
- Replace:
<JAX01_PrivateKey>
: Content ofprivatekey
on JAX01.<JAX02_PublicKey>
: Public key from JAX02.<JAX02_Public_IP>
: Public IP or dynamic DNS of JAX02’s network.10.10.10.2
: IP assigned to JAX02’s VPN interface.
Enable IP Forwarding:
-
To make it persistent:
Add:
Set Up Firewall Rules (Using UFW as Example):
Start and Enable WireGuard:
JAX02 VPN VM Configuration:
-
Create WireGuard Configuration File:
-
Add the Following Configuration:
[Interface] PrivateKey = <JAX02_PrivateKey> Address = 10.
10.10.2/6.0.10/24 ListenPort = 51820 SaveConfig = true [Peer] PublicKey = <JAX01_PublicKey> AllowedIPs = 10.10.5.40.0/22, 10.0/24,6.0.5/32192.168.60.0/22