This episode builds VPNs and tunneling on Alpine: WireGuard with the native kernel module, OpenVPN, IPsec with strongSwan, plus SSH tunneling and a Tailscale-style WireGuard mesh. You'll also get to know netns for network isolation.

Alpine is a favorite distro for routers and gateways, and episode 18 leverages that position to build private connections between networks. You'll build WireGuard running in the kernel, configure OpenVPN and IPsec with strongSwan, and use SSH tunneling and a Tailscale-style mesh.
This material complements the nftables firewall from episode 10: VPNs and firewalls work together. Encrypted traffic comes in through the ports the firewall opens, then gets routed to the internal network.
WireGuard runs as a kernel module and provides a virtual interface:
apk add wireguard-tools
modprobe wireguard
lsmod | grep wireguardGenerate a key pair:
wg genkey | tee privatekey | wg pubkey > publickey
chmod 600 privatekeySet up the WireGuard interface on the server:
ip link add dev wg0 type wireguard
wg set wg0 listen-port 51820 \
private-key /root/privatekey \
peer <PUBLIC_KEY_CLIENT> \
allowed-ips 10.10.0.2/32
ip addr add 10.10.0.1/24 dev wg0
ip link set wg0 upwg set wg0 listen-port 51820 configures the WireGuard port and peers. For persistence, write the configuration in /etc/wireguard/wg0.conf and use wg-quick:
vi /etc/wireguard/wg0.conf
wg-quick up wg0
rc-service wg-quick startOpen the port in the nft firewall:
nft add rule inet filter input udp dport 51820 acceptOpenVPN is a mature TLS-based VPN:
apk add openvpn
rc-service openvpn start
rc-update add openvpn defaultThe basic server configuration lives in /etc/openvpn/server.conf:
port 1194
proto udp
dev tun
server 10.8.0.0 255.255.255.0
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key
auth SHA256Run the server with the configuration file:
openvpn --config /etc/openvpn/server.conf --daemonFor production, prepare the CA and certificates with easy-rsa, available in the repositories.
strongSwan implements the IPsec/IKEv2 protocol:
apk add strongswan
rc-service ipsec start
rc-update add ipsec default
ipsec versionThe connection configuration lives in /etc/ipsec.conf:
conn server
left=%defaultroute
leftcert=serverCert.pem
right=%any
rightauth=eap-mschapv2
auto=addLoad and establish the connection:
ipsec reload
ipsec statusall | head -20ipsec statusall shows the status of all active IPsec SAs.
SSH tunneling provides a secure connection without VPN infrastructure:
ssh -L 5432:localhost:5432 arman@db.internal
ssh -N -D 1080 arman@gateway.internalssh -L 5432:localhost:5432 forwards a local port to a remote database through SSH.
For a simple mesh between machines, Tailscale provides an automatic WireGuard mesh:
apk add tailscale
rc-service tailscaled start
tailscale up
tailscale statustailscale up connects the machine to your account's mesh network, and tailscale status shows the connected peers.
Network namespaces isolate the network stack between processes:
ip netns add test
ip netns exec test ip addr show
ip netns del testip netns exec test ip addr show runs a command inside an isolated namespace — the basic concept containers use.
Tip
For simple, fast site-to-site connections, WireGuard is almost always the best choice: it runs in the kernel, has a short configuration, and low overhead. OpenVPN and IPsec excel at enterprise needs with certificate integration.
Episode 18 built VPNs and tunneling on Alpine: native WireGuard with the kernel module, TLS-based OpenVPN, IPsec with strongSwan, SSH tunneling, a Tailscale-style WireGuard mesh, and an introduction to netns.
Key takeaways:
In the next episode, episode 19, we'll cover performance and resource optimization — leveraging the small footprint of musl and BusyBox, kernel tuning with sysctl, memory management, and monitoring with top, htop, free, and df.