0:00–0:10
Recap
0:10–1:50
Lab 5D
1:50–2:00
Wrap
0:00 – 0:10Recap · 10 min
- Quick check: all three files in place on S1?
ls /etc/ipsec.d/cacerts/ /etc/ipsec.d/private/ /etc/ipsec.d/certs/. Should show caCert.pem, s1Key.pem, s1Cert.pem respectively. Anyone missing files — resolve now before the migration.
- Ask: "What three config changes must we make to switch from PSK to cert auth?" — (1) ipsec.secrets: change from PSK to RSA key reference. (2) ipsec.conf: change authby, add leftcert, leftid, rightid. (3) Add keyexchange=ikev2. That's it — the tunnel comes up automatically.
0:10 – 1:50Lab 5D · 100 min
Lab 5D — Part 1: Migrate IPSec to cert auth. Part 2: Build WireGuard tunnel. Part 3: Compare.
Part 1 — Migrate to certificate authentication (45 min)
- On S1, edit
/etc/ipsec.secrets. Remove or comment out the PSK line. Add the RSA private key reference:
: RSA s1Key.pem
The colon at the start means "this server's identity." The filename is relative to /etc/ipsec.d/private/.
- On S3, do the same:
: RSA s3Key.pem
- On S1, edit
/etc/ipsec.conf. Update the connection block:
conn S1_to_S3
keyexchange=ikev2
type=tunnel
authby=pubkey (was: authby=secret)
leftcert=s1Cert.pem
leftid="C=CA, O=YourName, CN=s1.yourname.net"
rightid="C=CA, O=YourName, CN=s3.yourname.net"
left=[S1-External-IP]
leftsubnet=192.168.50.0/24
right=[S3-External-IP]
rightsubnet=192.168.51.0/24
ike=aes256-sha2_256-modp1024!
esp=aes256-sha2_256!
keyingtries=0
ikelifetime=1h
lifetime=8h
dpddelay=30
dpdtimeout=120
dpdaction=restart
auto=start
The leftid and rightid must match exactly the DN embedded in each certificate — check with ipsec pki --print.
- On S3, write the mirror configuration with leftcert=s3Cert.pem and the DNs swapped appropriately.
- Restart ipsec on both:
sudo ipsec restart. Wait 30 seconds. Check status:
sudo ipsec status
A successful cert-based SA shows the certificate DN in the output rather than the PSK identifier. Verify S2 can still ping S3's LAN IP.
- If the tunnel doesn't come up, check syslog:
sudo grep charon /var/log/syslog | tail -30
Common cert errors: "no trusted CA found" (caCert.pem not in cacerts/), "no matching peer config found" (DN mismatch between leftid/rightid and actual cert DN).
Part 2 — Build a WireGuard tunnel (45 min)
- Install WireGuard on S1 and S3:
sudo apt install wireguard
WireGuard is built into the Linux kernel since 5.6. The package installs the userspace tools (wg, wg-quick) and the kernel module.
- Generate key pairs on S1:
wg genkey | sudo tee /etc/wireguard/s1_private.key | wg pubkey | sudo tee /etc/wireguard/s1_public.key
This generates a private key, saves it, then derives the public key from it. Both are in base64 format.
sudo chmod 600 /etc/wireguard/s1_private.key
Display the public key: sudo cat /etc/wireguard/s1_public.key — copy this, you'll need it on S3.
- Generate key pairs on S3:
Same commands, saving to s3_private.key and s3_public.key.
Display S3's public key — copy it, you'll need it on S1.
- Create the WireGuard config on S1:
sudo nano /etc/wireguard/wg0.conf
[Interface]
Address = 10.0.0.1/24
PrivateKey = [S1's private key contents]
ListenPort = 51820
[Peer]
PublicKey = [S3's public key]
AllowedIPs = 10.0.0.2/32, 192.168.51.0/24
Endpoint = [S3-External-IP]:51820
Explanation: WireGuard gives each tunnel interface a new virtual IP (10.0.0.x). AllowedIPs acts as both an access control list and a routing table — traffic for 10.0.0.2 and 192.168.51.0/24 goes through the tunnel.
- Create the WireGuard config on S3:
[Interface]
Address = 10.0.0.2/24
PrivateKey = [S3's private key contents]
ListenPort = 51820
[Peer]
PublicKey = [S1's public key]
AllowedIPs = 10.0.0.1/32, 192.168.50.0/24
Endpoint = [S1-External-IP]:51820
- Bring up the WireGuard interface:
sudo wg-quick up wg0 on both S1 and S3.
Check the interface: sudo wg show — shows peers, latest handshake, bytes transferred, allowed IPs.
Test: ping from S1 to S3's WireGuard IP: ping 10.0.0.2. Should succeed.
Test: ping from S1 to S3's internal LAN IP through the WireGuard tunnel.
- Make WireGuard persistent:
sudo systemctl enable wg-quick@wg0
This enables the WireGuard interface to start automatically on boot.
Part 3 — Compare IPSec and WireGuard (10 min)
- Complete the comparison table in the lab sheet. Both tunnels are running simultaneously — the IPSec cert tunnel and the WireGuard tunnel coexist on the same machines. This demonstrates they are independent technologies.
- Key differences to highlight:
Codebase: IPSec (StrongSwan charon daemon) ~400,000 lines. WireGuard kernel module ~4,000 lines. Smaller code = smaller attack surface.
Cryptography: IPSec is configurable (and therefore misconfigurable). WireGuard uses fixed modern algorithms (ChaCha20-Poly1305, Curve25519, BLAKE2s) — no cipher negotiation possible, which is a feature not a limitation.
Configuration: IPSec requires ipsec.secrets + ipsec.conf on both sides + NAT changes. WireGuard requires one config file per side.
State: IPSec maintains complex SA state, IKE negotiation, DPD. WireGuard is stateless — a peer is "up" if it's sending packets, "down" if it's not. No keepalives required.
Use cases: IPSec is the standard for enterprise-grade site-to-site VPNs and mobile client VPNs (IKEv2). WireGuard is increasingly popular for modern deployments, particularly for remote access VPNs where simplicity matters.
Lab 5D complete when: ipsec status shows cert-based SA (DN visible in output). S2 can ping S3's LAN through IPSec tunnel. WireGuard wg show shows latest handshake. ping 10.0.0.2 from S1 succeeds. Comparison table completed with thoughtful answers.
1:50 – 2:00Wrap · 10 min
- Preview Friday's practical: students receive a WireGuard spec — two new IP addresses, pre-generated peer keys, AllowedIPs. They must configure both endpoints and demonstrate connectivity. The format is identical to what they did today, just with different values. Students who understand the [Interface]/[Peer] structure will find it fast.
- Preview Week 6: Docker containers. "The Nginx server you built in Week 4 served a static HTML page. Next week we put an application in a Docker container and put Nginx in front of it as a reverse proxy. Everything you've built so far becomes part of the infrastructure this application runs on."
Learning outcomes — by end of Day 4, students can…
Migrate IPSec from PSK to certificate authUpdate ipsec.secrets to RSA, add leftcert/leftid/rightid to ipsec.conf, and verify the SA re-establishes
Configure a WireGuard tunnelGenerate key pairs, write [Interface] and [Peer] config sections, bring up with wg-quick, verify with wg show
Explain WireGuard AllowedIPsDescribe how AllowedIPs serves as both a routing table and a packet filter in WireGuard
Compare IPSec and WireGuardArticulate the key differences in complexity, cryptographic flexibility, state management, and use cases
Common issues and fixes
| Issue | Likely cause | Fix |
| IPSec cert tunnel: "no trusted CA found" in syslog | caCert.pem not in /etc/ipsec.d/cacerts/ on one side | Check: ls /etc/ipsec.d/cacerts/ on both S1 and S3. Both must have caCert.pem. Copy it if missing |
| IPSec cert tunnel: "no matching peer config" | leftid or rightid in ipsec.conf doesn't exactly match the DN in the certificate | Run: ipsec pki --print --in /etc/ipsec.d/certs/s1Cert.pem and compare the subject DN to leftid in ipsec.conf. They must match character for character including spaces and capitalisation |
| WireGuard wg show shows no peers or no handshake | Public key mismatch, wrong endpoint IP, or UDP 51820 blocked by firewall | Verify public keys are exactly correct (copy-paste error is common). Check UFW: sudo ufw allow 51820/udp. Ping the endpoint IP first to confirm connectivity |
| wg-quick up fails: "Cannot find device wg0" | WireGuard kernel module not loaded | Load manually: sudo modprobe wireguard. Then retry wg-quick up wg0 |