0:00–0:30
Lecture
0:30–1:50
Lab 5A
1:50–2:00
Debrief
0:00 – 0:30Lecture · 30 min
Why VPNs exist, IPSec protocol suite, IKE negotiation, and the StrongSwan mental model
Part 1 — The VPN problem (5 min)
- Draw the scenario: two isolated private networks (S1's LAN1 at 192.168.50.0/24, S3's LAN at 192.168.51.0/24) connected to the same public network (classroom at 172.17.x.x). S2 cannot reach S3's internal hosts. Traffic between S1 and S3 traverses the classroom network in plaintext. A VPN solves both problems: it routes S2→S3's LAN traffic through a tunnel, and it encrypts everything that traverses the public network.
- Tunnel mode (what we use): the entire original IP packet is encrypted and encapsulated inside a new IP packet. The outer IP header carries the VPN endpoint IPs (S1 and S3's external IPs). An observer on the classroom network sees only encrypted ESP packets between S1 and S3 — they cannot see the inner packet headers or payload.
- Transport mode (not used here): only the payload is encrypted; the IP header is left in plaintext. Used for host-to-host encryption, not site-to-site tunnels.
Part 2 — IPSec protocol suite (10 min)
- IKE (Internet Key Exchange): The control plane — negotiates the encryption parameters and exchanges keys. Uses UDP port 500 (or 4500 for NAT traversal). IKE operates in two phases:
Phase 1: Establishes a secure, authenticated channel (the ISAKMP SA) between the two peers. This is how they verify each other's identity (via PSK or certificate) and agree on encryption for Phase 2 negotiation.
Phase 2: Within the Phase 1 channel, negotiates the actual IPSec SA — the encryption algorithm (ESP cipher suite) and keys for data traffic. The result is two unidirectional SAs (one for each direction).
- ESP (Encapsulating Security Payload): The data plane — encrypts and authenticates the actual IP packets. Protocol number 50. This is what carries the user data through the tunnel. Most VPN configurations use ESP only.
AH (Authentication Header): Provides integrity and authentication only — no encryption. Protocol number 51. Rarely used alone; ESP with authentication provides a strict superset of AH's capabilities. AH is incompatible with NAT (it authenticates the IP header, which NAT modifies).
- The IKE cipher suite we configure:
ike=aes256-sha2_256-modp1024! — AES-256 encryption, SHA-256 integrity, Diffie-Hellman group 2 (1024-bit MODP). The ! means "exact match only — don't negotiate alternatives." The ESP suite: esp=aes256-sha2_256! — AES-256 and SHA-256 for the data channel.
Part 3 — StrongSwan mental model (8 min)
- StrongSwan uses a "lefty local, righty remotey" convention throughout its configuration. On any given server, left = this server's side, right = the remote peer. This means the ipsec.conf on S1 and the ipsec.conf on S3 are mirrors of each other — left and right are swapped.
- Key ipsec.conf directives:
left= / right= — the external (tunnel endpoint) IPs
leftsubnet= / rightsubnet= — the internal subnets that traffic for, are routed through the tunnel
authby=secret — PSK authentication (changed to pubkey for cert auth)
auto=start — bring the tunnel up automatically on ipsec restart
keyingtries=0 — retry negotiation indefinitely (0 = unlimited)
dpddelay=30 / dpdtimeout=120 / dpdaction=restart — Dead Peer Detection: check peer every 30s, restart tunnel if no response after 120s
- NAT exclusion — why it's critical: Without it, packets from S2 (192.168.50.2) destined for S3's LAN hit S1's iptables POSTROUTING chain before the VPN policy is applied. They get masqueraded — the source IP becomes S1's external IP. The encrypted tunnel receives packets with source IP 172.17.x.x instead of 192.168.50.2. S3's routing can't return them correctly. The fix: exclude tunnel-bound traffic from MASQUERADE using a
! -d [remote-subnet] condition in the rule.
Part 4 — WireGuard preview (7 min)
- Briefly introduce WireGuard as a contrast to IPSec. WireGuard is a modern VPN protocol built into the Linux kernel since 5.6. Its design goals: simplicity (the entire codebase is ~4000 lines vs IPSec's ~400,000), performance, and modern cryptography (ChaCha20, Poly1305, Curve25519 — not negotiable, not configurable). The entire WireGuard configuration is a handful of lines. Students will build it on Thursday after experiencing IPSec's complexity first — the contrast is educational.
0:30 – 1:50Lab 5A · 80 min
Lab 5A — Verify and extend the network topology for S1↔S3 VPN
Part 1 — Verify existing topology (20 min)
- S3 should already have two NICs from the original setup: one on the External vSwitch and one on LAN2. Verify on S3:
ip addr show — confirm two interfaces, both with IPs. The External NIC should have a 172.17.x.x address from DHCP. The LAN2 NIC should have a static 192.168.51.2/24 address.
- From S1, ping S3's external IP:
ping 172.17.[S3-IP]. This must work before Tuesday's lab. If it fails — debug the External vSwitch connectivity on S3 first.
- From S2, attempt to ping S3's LAN IP (192.168.51.2 or S3's LAN address): this should fail. Record the result — this is the connectivity gap the VPN will bridge.
Part 2 — Configure S3 as a NAT gateway (30 min)
- S3 may not yet be configured as a full NAT gateway for its LAN2 subnet. Configure identically to how S1 was configured in Week 1:
Enable IP forwarding: sudo sysctl -w net.ipv4.ip_forward=1 (and persist in /etc/sysctl.conf)
Add MASQUERADE rule: sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Persist with iptables-persistent.
- Verify: from a device on S3's LAN subnet (or S3 itself), ping 8.8.8.8. Internet access through S3 should work.
Part 3 — Network topology documentation (30 min)
- Complete the topology table in the lab sheet — record all IPs for all interfaces on all servers. This reference is essential for the VPN config files:
S1: External IP (172.17.x.x), LAN1 IP (192.168.50.1), LAN1 subnet (192.168.50.0/24)
S3: External IP (172.17.x.x), LAN2 IP (192.168.51.x), LAN2 subnet (192.168.51.0/24)
- Answer the pre-lab questions in the lab sheet. These verify conceptual understanding before the configuration work begins on Tuesday.
Lab 5A complete when: S1 can ping S3's External IP. S3 can ping S1's External IP. S2 cannot ping S3's LAN IP (expected — this is what the VPN will fix). All topology IPs documented in the lab sheet. S3 has internet access through its NAT gateway config.
1:50 – 2:00Debrief · 10 min
- Ask: "When the VPN is running, and S2 sends a packet to 192.168.51.2, what happens to that packet at S1?" — S1 sees the destination is in the rightsubnet defined in ipsec.conf, wraps the packet in ESP encryption with a new outer IP header (S1→S3 external IPs), and sends it to S3. S3 decrypts the outer ESP packet, recovers the original inner packet destined for 192.168.51.2, and delivers it.
- Preview Tuesday: now that the topology is verified, we install StrongSwan and configure the PSK tunnel. The key file is short — about 10 lines in ipsec.conf and one line in ipsec.secrets. If S1↔S3 ping works, the config just needs to be correct and the tunnel comes up.
Learning outcomes — by end of Day 1, students can…
Explain IPSec IKE phasesDescribe what is negotiated in Phase 1 vs Phase 2 and why two phases are needed
Distinguish ESP and AHExplain what each provides and why ESP is used in tunnel mode VPNs while AH is incompatible with NAT
Verify the VPN topology prerequisitesConfirm S1↔S3 external IP connectivity and document all interface IPs for use in ipsec.conf
Explain the NAT exclusion requirementDescribe why the MASQUERADE rule must be modified before VPN traffic can flow correctly
Common issues and fixes
| Issue | Likely cause | Fix |
| S1 cannot ping S3's external IP | S3 not connected to External vSwitch, or External NIC not configured | In Hyper-V: verify S3 has a NIC connected to the External vSwitch. On S3: check ip addr show — External NIC should have a 172.17.x.x DHCP address |
| S3 cannot reach internet after enabling NAT | IP forwarding not enabled, or MASQUERADE rule on wrong interface | Check: cat /proc/sys/net/ipv4/ip_forward (must be 1). Check: sudo iptables -t nat -L POSTROUTING — MASQUERADE rule must reference S3's External interface name |