WIUNIX ACADEMY
WireGuard hub and spoke with filtered BGP and FRRouting
Page 2 of 6. Review the earlier steps and prerequisites before continuing.
YOUR SYSTEM. YOUR STEPS.
Where are you working?
Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.
USE YOUR OWN VALUES
Configure this tutorial
Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.
Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.
Set values for my environment19 editable values
LET’S BUILD
Generate keys without printing private material
Create a new root on each gateway after verifying every ancestor is a real, root-owned directory without group/world write access. Generate private keys locally. Exchange only public keys over an authenticated channel; never copy a private key to another node, browser settings, chat or Git. The hub uses its own key on two interfaces; each spoke has its own identity. Retain the original package configuration, routes and full sysctl inventory privately before changing forwarding.
Dedicated fresh lab gateways; Bash
set -eu
sudo python3 - <<'PY'
import os,stat
from pathlib import Path
root=Path('/srv/academy-wgbgp')
for node in list(root.parents)[::-1]:
st=node.lstat()
if not stat.S_ISDIR(st.st_mode) or st.st_uid!=0 or st.st_mode & 0o022:
raise SystemExit('Lab ancestor must be a root-owned real directory without group/world write permission')
if root.exists() or root.is_symlink(): raise SystemExit('Fresh root required')
root.mkdir(mode=0o700)
PY
sudo sh -c 'umask 077; wg genkey > "/srv/academy-wgbgp/private.key"; wg pubkey < "/srv/academy-wgbgp/private.key" > "/srv/academy-wgbgp/public.key"'
sudo cat '/srv/academy-wgbgp/public.key'
sudo install -d -m 0700 /etc/wireguard
sudo cp -a /etc/frr '/srv/academy-wgbgp/frr-before'
sudo sh -c 'umask 077; ip route show table all > "/srv/academy-wgbgp/routes-before.txt"; sysctl -a 2>/dev/null > "/srv/academy-wgbgp/sysctl-before.txt"'
Only a public key appears on screen; private.key is0600 in the new0700 root and initial FRR/routes/sysctls are retained.
LET’S BUILD
Inspect the native service and security policy
The pinned upstream FRR and private libyang sources are installed under a root-owned prefix traversable by the service account. Archive SHA-256 checks detect changed downloads; they are not independent signatures or a security audit. Compile as your normal user and install outputs as root. System libyang and AUR recipes are not modified.
The generated upstream unit uses this build’s absolute paths and native config/run directories. Its runtime directory is recreated and assigned to frr at service start. Install the unit under the local vendor directory, leaving the existing administrative mask effective until configuration and firewall are ready. Record actual rolling packages and stop on a missing dependency or failed build. Manjaro branches advance separately; do not add Arch repositories or perform a partial upgrade.
All three dedicated gateways; Bash
set -eu
sudo modprobe wireguard
systemctl show frr.service -p LoadState -p UnitFileState
sed -n '1,160p' /usr/local/lib/systemd/system/frr.service
sudo ls -ld /etc/frr /etc/wireguard
sudo sed -n '1,160p' /etc/frr/daemons
The native unit and daemon options are reviewed, WireGuard loads and security managers remain active.
LET’S BUILD
Open both protected hub tunnel files
Hub only. Paste the following file contents into their named files. In the protected editor replace REPLACE_PRIVATE_KEY from this node’s private file and replace public-key placeholders from the authenticated peers. Do not run the template as shell. Close the editor before enabling anything. No endpoint is required on the hub: it learns authenticated spoke endpoints. Do not enable SaveConfig, which can overwrite reviewed files.
Dedicated fresh lab gateways; Bash
set -eu
test "$ROLE" = h
test ! -e '/etc/wireguard/wg-ac-a.conf'; test ! -L '/etc/wireguard/wg-ac-a.conf'
sudo install -m 0600 /dev/null '/etc/wireguard/wg-ac-a.conf'
test ! -e '/etc/wireguard/wg-ac-b.conf'; test ! -L '/etc/wireguard/wg-ac-b.conf'
sudo install -m 0600 /dev/null '/etc/wireguard/wg-ac-b.conf'
sudo nano '/etc/wireguard/wg-ac-a.conf' '/etc/wireguard/wg-ac-b.conf'
Both hub files are0600; public keys belong to A/B and the private key belongs only to this hub. No placeholders remain before activation.
LET’S BUILD
File: hub link to A
Only A’s inner address and source LAN are allowed on this peer.
Dedicated fresh lab gateways; Bash
[Interface]
Address = 10.254.1.1/30
ListenPort = 51871
PrivateKey = REPLACE_PRIVATE_KEY
Table = off
MTU = 1380
[Peer]
PublicKey = REPLACE_PEER_PUBLIC_KEY
AllowedIPs = 10.254.1.2/32, 10.71.10.0/24
The A-link file has hub 10.254.1.1/30, UDP51871, Table=off and only 10.254.1.2/32 plus 10.71.10.0/24 for its authenticated peer.
LET’S BUILD
File: hub link to B
This separate interface has its own connected /30 and UDP listener.
Dedicated fresh lab gateways; Bash
[Interface]
Address = 10.254.2.1/30
ListenPort = 51872
PrivateKey = REPLACE_PRIVATE_KEY
Table = off
MTU = 1380
[Peer]
PublicKey = REPLACE_PEER_PUBLIC_KEY
AllowedIPs = 10.254.2.2/32, 10.72.20.0/24
The B-link file has hub 10.254.2.1/30, UDP51872, Table=off and only 10.254.2.2/32 plus 10.72.20.0/24 for its authenticated peer.
LET’S BUILD
Open the appropriate protected spoke file
Run only the matching line on each spoke, then use its matching file below. Each file’s peer public key is the hub’s public key. Insert only the local private key using the protected editor. Keepalive25 is useful for NAT; remove it when no mapping needs preservation. The documentation endpoint is not an operational internet address: use the real reachable hub in settings.
Dedicated fresh lab gateways; Bash
set -eu
case "$ROLE" in
a) test ! -e '/etc/wireguard/wg-ac-a.conf'; test ! -L '/etc/wireguard/wg-ac-a.conf'
sudo install -m 0600 /dev/null '/etc/wireguard/wg-ac-a.conf'
sudo nano '/etc/wireguard/wg-ac-a.conf' ;;
b) test ! -e '/etc/wireguard/wg-ac-b.conf'; test ! -L '/etc/wireguard/wg-ac-b.conf'
sudo install -m 0600 /dev/null '/etc/wireguard/wg-ac-b.conf'
sudo nano '/etc/wireguard/wg-ac-b.conf' ;;
*) printf '%s
' 'Spokes only'; exit 1 ;;
esac
Only the matching spoke file is created, with mode0600, its local private key and the authenticated hub public key.
LET’S BUILD
File: A to hub
The hub peer carries B’s LAN, not an internet default.
Dedicated fresh lab gateways; Bash
[Interface]
Address = 10.254.1.2/30
ListenPort = 51871
PrivateKey = REPLACE_PRIVATE_KEY
Table = off
MTU = 1380
[Peer]
PublicKey = REPLACE_PEER_PUBLIC_KEY
AllowedIPs = 10.254.1.1/32, 10.72.20.0/24
Endpoint = 198.51.100.10:51871
PersistentKeepalive = 25
A uses 10.254.1.2/30 and sends only 10.254.1.1/32 and 10.72.20.0/24 to the hub endpoint 198.51.100.10:51871; no default AllowedIPs.
LET’S BUILD
File: B to hub
The hub peer carries A’s LAN. Never use identical competing AllowedIPs for two peers on one interface.
Dedicated fresh lab gateways; Bash
[Interface]
Address = 10.254.2.2/30
ListenPort = 51872
PrivateKey = REPLACE_PRIVATE_KEY
Table = off
MTU = 1380
[Peer]
PublicKey = REPLACE_PEER_PUBLIC_KEY
AllowedIPs = 10.254.2.1/32, 10.71.10.0/24
Endpoint = 198.51.100.10:51872
PersistentKeepalive = 25
B uses 10.254.2.2/30 and sends only 10.254.2.1/32 and 10.71.10.0/24 to the hub endpoint 198.51.100.10:51872; no default AllowedIPs.