<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>VPN | A DevOps Blog</title><link>https://blog.bsdserver.nl/tag/vpn/</link><description>Hands-on DevOps and homelab content: Kubernetes clusters, self-hosted services, CI/CD pipelines and infrastructure as code, by Patrick de Ruiter of We Build Your Cloud.</description><language>en</language><image><url>https://blog.bsdserver.nl/images/app-icon.svg</url><title>A DevOps Blog</title><link>https://blog.bsdserver.nl/</link></image><lastBuildDate>Fri, 20 Nov 2026 09:00:00 +0100</lastBuildDate><atom:link href="https://blog.bsdserver.nl/tag/vpn/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title>OpenBSD VPN Road Warrior Setup with IKEv2</title><link>https://blog.bsdserver.nl/openbsd-vpn-road-warrior-setup-with-ikev2/</link><guid isPermaLink="false">693b521479eb54000160a4bb</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Thu, 11 Dec 2025 23:21:56 +0000</pubDate><description>Introduction OpenBSD is known for its security and clean design, making it an ideal choice for a VPN server.</description><category>OpenBSD</category><category>VPN</category><category>Security</category><category>Networking</category><media:content url="https://blog.bsdserver.nl/content/images/2026/01/openbsd-road-warior-vpn.png" medium="image"/><content:encoded><![CDATA[<p>Laptops and phones on the road need a secure way back into your network, or a trusted exit to the internet from hotel and café Wi-Fi. OpenBSD is known for its security and clean design, making it an ideal choice for that VPN server.</p>
<p>This guide sets up a road warrior (mobile client) VPN on OpenBSD with iked, the native IKEv2 daemon. The steps were verified on OpenBSD 7.9. Clients authenticate the server by certificate and themselves with a username and password.</p>
<h2 id="why-iked">Why iked? <a class="anchor" data-pagefind-ignore href="#why-iked" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>In base</strong> - iked, PF and LibreSSL ship with OpenBSD. Nothing to install.</li>
<li><strong>IKEv2</strong> - The protocol most desktop and mobile operating systems support natively, so clients often need no extra app.</li>
<li><strong>Small configuration</strong> - One policy in <code>/etc/iked.conf</code> covers all road warriors.</li>
</ul>
<h3 id="when-to-use-it">When to use it <a class="anchor" data-pagefind-ignore href="#when-to-use-it" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Use it</strong> for a handful to a few dozen mobile users who need access to your network or a trusted exit to the internet.</li>
<li><strong>Skip it</strong> for site-to-site links between fixed networks (a different iked policy) or when you need per-user certificates and central user management; this setup keeps users in a config file.</li>
</ul>
<h2 id="how-it-works">How It Works <a class="anchor" data-pagefind-ignore href="#how-it-works" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Component</th>
					<th>Runs on</th>
					<th>Job</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>iked</td>
					<td>VPN server</td>
					<td>Negotiates IKEv2, authenticates clients (EAP-MSCHAPv2), hands out addresses and DNS.</td>
			</tr>
			<tr>
					<td>Certificates (CA + server)</td>
					<td>VPN server, CA cert also on clients</td>
					<td>Prove to clients that they talk to the real server.</td>
			</tr>
			<tr>
					<td>PF</td>
					<td>VPN server</td>
					<td>Lets IKE and ESP in, passes tunnel traffic on <code>enc0</code>, NATs clients to the internet.</td>
			</tr>
			<tr>
					<td>IKEv2 client</td>
					<td>Laptop or phone</td>
					<td>Connects, checks the server certificate, logs in with username and password.</td>
			</tr>
	</tbody>
</table>
<p>The flow: client connects on UDP 500/4500 → verifies the server certificate against the CA → logs in with EAP → gets an address from <code>10.10.10.0/24</code> → its traffic goes through the tunnel → PF NATs it out of the server.</p>
<h2 id="prerequisites">Prerequisites <a class="anchor" data-pagefind-ignore href="#prerequisites" aria-label="Link to this section">#</a></h2>
<ul>
<li>A VPS or dedicated server running a supported OpenBSD release (the steps were verified on 7.9)</li>
<li>A domain name or static public IP address for the VPN server</li>
<li>Root access to your server</li>
</ul>
<h2 id="step-1-generate-certificates-and-keys">Step 1: Generate Certificates and Keys <a class="anchor" data-pagefind-ignore href="#step-1-generate-certificates-and-keys" aria-label="Link to this section">#</a></h2>
<p>Clients must be sure they talk to your server before they send a password. You build a small CA with OpenSSL (LibreSSL) and use it to sign the server certificate.</p>
<h3 id="create-the-directory-for-private-keys">Create the Directory for Private Keys <a class="anchor" data-pagefind-ignore href="#create-the-directory-for-private-keys" aria-label="Link to this section">#</a></h3>
<p>On OpenBSD <code>/etc/ssl/private</code> already exists, so <code>-p</code> keeps <code>mkdir</code> from failing; <code>chmod 700</code> keeps it root-only:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="nb">cd</span> /etc/ssl
</span></span><span class="line"><span class="cl">mkdir -p private
</span></span><span class="line"><span class="cl">chmod <span class="m">700</span> private
</span></span></code></pre></div><h3 id="generate-the-ca-private-key">Generate the CA Private Key <a class="anchor" data-pagefind-ignore href="#generate-the-ca-private-key" aria-label="Link to this section">#</a></h3>
<p>This key signs the server&rsquo;s certificate. Anyone who has it can create certificates your clients trust, so keep it protected:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">openssl genrsa -out private/cakey.pem <span class="m">4096</span>
</span></span></code></pre></div><h3 id="create-the-ca-certificate">Create the CA Certificate <a class="anchor" data-pagefind-ignore href="#create-the-ca-certificate" aria-label="Link to this section">#</a></h3>
<p>This self-signed certificate is what clients trust. OpenBSD&rsquo;s LibreSSL <code>openssl.cnf</code> adds no extensions by default, so without the <code>-addext</code> lines you get an X.509 v1 certificate without the CA flag, which clients such as strongSwan reject (&ldquo;ca certificate lacks CA basic constraint&rdquo;):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">openssl req -x509 -new -nodes <span class="se">\
</span></span></span><span class="line"><span class="cl">            -key private/cakey.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">            -sha256 -days <span class="m">3650</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">            -out cacert.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">            -subj <span class="s2">&#34;/C=NL/O=VPN/CN=VPN CA&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">            -addext <span class="s2">&#34;basicConstraints=critical,CA:TRUE&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">            -addext <span class="s2">&#34;keyUsage=critical,keyCertSign,cRLSign&#34;</span>
</span></span></code></pre></div><h3 id="generate-the-vpn-server-key">Generate the VPN Server Key <a class="anchor" data-pagefind-ignore href="#generate-the-vpn-server-key" aria-label="Link to this section">#</a></h3>
<p>The server&rsquo;s own private key:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">openssl genrsa -out private/vpn-server-key.pem <span class="m">4096</span>
</span></span></code></pre></div><h3 id="create-the-vpn-server-certificate-signing-request-csr">Create the VPN Server Certificate Signing Request (CSR) <a class="anchor" data-pagefind-ignore href="#create-the-vpn-server-certificate-signing-request-csr" aria-label="Link to this section">#</a></h3>
<p>The CSR carries the server&rsquo;s name and public key to the CA for signing:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">openssl req -new -key private/vpn-server-key.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">            -out vpn-server-csr.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">            -subj <span class="s2">&#34;/C=NL/O=VPN/CN=vpn.example.com&#34;</span>
</span></span></code></pre></div><h3 id="sign-the-vpn-server-certificate">Sign the VPN Server Certificate <a class="anchor" data-pagefind-ignore href="#sign-the-vpn-server-certificate" aria-label="Link to this section">#</a></h3>
<p>The CA signs the CSR. Two extensions matter:</p>
<ul>
<li><code>subjectAltName=DNS:vpn.example.com</code>: the name clients connect to. It must match.</li>
<li><code>extendedKeyUsage=serverAuth</code>: expected by Windows and Apple clients.</li>
</ul>
<p>OpenBSD&rsquo;s default shell (ksh) does not support <code>&lt;(...)</code> process substitution, so write the extensions to a file first:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="nb">printf</span> <span class="s2">&#34;subjectAltName=DNS:vpn.example.com\nextendedKeyUsage=serverAuth\n&#34;</span> &gt; vpn-server-ext.cnf
</span></span><span class="line"><span class="cl">openssl x509 -req -in vpn-server-csr.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">             -CA cacert.pem -CAkey private/cakey.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">             -CAcreateserial -out vpn-server-cert.pem <span class="se">\
</span></span></span><span class="line"><span class="cl">             -days <span class="m">1825</span> -sha256 <span class="se">\
</span></span></span><span class="line"><span class="cl">             -extfile vpn-server-ext.cnf
</span></span></code></pre></div><h3 id="install-the-certificates-for-iked">Install the Certificates for iked <a class="anchor" data-pagefind-ignore href="#install-the-certificates-for-iked" aria-label="Link to this section">#</a></h3>
<p>iked does not look in <code>/etc/ssl</code>. It loads its files from its own directories:</p>
<table>
	<thead>
			<tr>
					<th>File</th>
					<th>Location</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>CA certificates</td>
					<td><code>/etc/iked/ca/</code></td>
			</tr>
			<tr>
					<td>Its own certificate</td>
					<td><code>/etc/iked/certs/</code></td>
			</tr>
			<tr>
					<td>Its private key</td>
					<td><code>/etc/iked/private/local.key</code></td>
			</tr>
	</tbody>
</table>
<p>Skip this step and iked silently authenticates with the raw public key it generated at install time; clients then fail with &ldquo;no trusted ECDSA public key found for &lsquo;vpn.example.com&rsquo;&rdquo;. The first command keeps a backup of that generated key:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">cp /etc/iked/private/local.key /etc/iked/private/local.key.orig
</span></span><span class="line"><span class="cl">cp /etc/ssl/cacert.pem /etc/iked/ca/ca.crt
</span></span><span class="line"><span class="cl">cp /etc/ssl/vpn-server-cert.pem /etc/iked/certs/vpn.example.com.crt
</span></span><span class="line"><span class="cl">install -m <span class="m">600</span> /etc/ssl/private/vpn-server-key.pem /etc/iked/private/local.key
</span></span></code></pre></div><p>Copy <code>cacert.pem</code> (never the key) to your clients so they can verify the server.</p>
<h2 id="step-2-edit-iked-configuration">Step 2: Edit iked Configuration <a class="anchor" data-pagefind-ignore href="#step-2-edit-iked-configuration" aria-label="Link to this section">#</a></h2>
<p><code>/etc/iked.conf</code> holds the users and one policy that accepts all road warrior clients. Open it with your preferred editor (vi is in base; vim is a package):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">vi /etc/iked.conf
</span></span></code></pre></div><p>And add the following configuration:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">user <span class="s2">&#34;username&#34;</span> <span class="s2">&#34;password&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">ikev2 <span class="s2">&#34;roadwarrior&#34;</span> passive esp <span class="se">\
</span></span></span><span class="line"><span class="cl">    from 0.0.0.0/0 to dynamic <span class="se">\
</span></span></span><span class="line"><span class="cl">    <span class="nb">local</span> 82.197.198.151 peer any <span class="se">\
</span></span></span><span class="line"><span class="cl">    srcid vpn.example.com <span class="se">\
</span></span></span><span class="line"><span class="cl">    eap <span class="s2">&#34;mschap-v2&#34;</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    config address 10.10.10.0/24 <span class="se">\
</span></span></span><span class="line"><span class="cl">    config name-server 192.168.2.166 <span class="se">\
</span></span></span><span class="line"><span class="cl">    tag <span class="s2">&#34;</span><span class="nv">$name</span><span class="s2">&#34;</span>
</span></span></code></pre></div><table>
	<thead>
			<tr>
					<th>Setting</th>
					<th>What it does</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>user &quot;username&quot; &quot;password&quot;</code></td>
					<td>A client login. Add one <code>user</code> line per client.</td>
			</tr>
			<tr>
					<td><code>passive</code></td>
					<td>The server waits for clients to connect; it never initiates.</td>
			</tr>
			<tr>
					<td><code>from 0.0.0.0/0 to dynamic</code></td>
					<td>Clients reach everything through the tunnel; <code>dynamic</code> narrows the flow to the address each client is assigned.</td>
			</tr>
			<tr>
					<td><code>local 82.197.198.151 peer any</code></td>
					<td>Replace with your VPN server&rsquo;s public IP. <code>peer any</code>: clients connect from any address.</td>
			</tr>
			<tr>
					<td><code>srcid vpn.example.com</code></td>
					<td>The server&rsquo;s identity. Must match the certificate name.</td>
			</tr>
			<tr>
					<td><code>eap &quot;mschap-v2&quot;</code></td>
					<td>Clients authenticate with a <code>user</code> name and password.</td>
			</tr>
			<tr>
					<td><code>config address 10.10.10.0/24</code></td>
					<td>The pool client addresses come from.</td>
			</tr>
			<tr>
					<td><code>config name-server 192.168.2.166</code></td>
					<td>The DNS server pushed to clients. Set your own.</td>
			</tr>
			<tr>
					<td><code>tag &quot;$name&quot;</code></td>
					<td>Tags the tunnel&rsquo;s traffic for PF. The rules below do not need it.</td>
			</tr>
	</tbody>
</table>
<p>Do not use <code>to 0.0.0.0/0</code> instead of <code>to dynamic</code>: that installs a 0.0.0.0/0 -&gt; 0.0.0.0/0 flow on the server and sends all of the server&rsquo;s own traffic (including your SSH session) into the first client&rsquo;s tunnel.</p>
<p>Make sure the file is only readable by root, or iked refuses to load it. <code>iked -n</code> checks the syntax without starting anything:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">chmod <span class="m">600</span> /etc/iked.conf
</span></span><span class="line"><span class="cl">iked -n
</span></span></code></pre></div><h2 id="step-3-configure-pf-firewall-rules">Step 3: Configure PF Firewall Rules <a class="anchor" data-pagefind-ignore href="#step-3-configure-pf-firewall-rules" aria-label="Link to this section">#</a></h2>
<p>PF must let the VPN protocols in and NAT the clients out. Open the PF configuration file:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">vi /etc/pf.conf
</span></span></code></pre></div><p>Add the following rules to permit IKE and ESP traffic and to NAT the VPN clients out of the server:</p>
<pre tabindex="0"><code>pass in quick on egress proto udp from any to any port { 500, 4500 }
pass out quick on egress proto udp from any to any port { 500, 4500 }
pass in quick on egress proto esp from any to any
pass out quick on egress proto esp from any to any
pass in quick on enc0 all
pass out quick on enc0 all
match out on egress from 10.10.10.0/24 to any nat-to (egress:0)
</code></pre><table>
	<thead>
			<tr>
					<th>Rule</th>
					<th>Why</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>UDP 500, 4500</td>
					<td>IKE, and NAT traversal for clients behind NAT (most of them).</td>
			</tr>
			<tr>
					<td><code>proto esp</code></td>
					<td>Encrypted traffic from clients that are not behind NAT.</td>
			</tr>
			<tr>
					<td><code>enc0</code></td>
					<td>The decrypted tunnel traffic appears on this interface.</td>
			</tr>
			<tr>
					<td><code>nat-to (egress:0)</code></td>
					<td>Client traffic leaves with the server&rsquo;s public address.</td>
			</tr>
	</tbody>
</table>
<p>The server must also forward packets between the tunnel and the internet. The first command enables it now, the second after a reboot:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">sysctl net.inet.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;net.inet.ip.forwarding=1&#39;</span> &gt;&gt; /etc/sysctl.conf
</span></span></code></pre></div><p>Reload the PF configuration:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">pfctl -f /etc/pf.conf
</span></span></code></pre></div><h2 id="step-4-enable-and-start-the-iked-service">Step 4: Enable and Start the iked Service <a class="anchor" data-pagefind-ignore href="#step-4-enable-and-start-the-iked-service" aria-label="Link to this section">#</a></h2>
<p>Enable the service so iked starts at boot. No flags are needed: iked no longer blocks the server&rsquo;s own IPv6 traffic, and on 7.9 the old <code>-6</code> flag only logs &ldquo;the -6 option is ignored and will be removed in the future&rdquo;:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">rcctl <span class="nb">enable</span> iked
</span></span></code></pre></div><p>Start the service:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">rcctl start iked
</span></span></code></pre></div><h2 id="troubleshooting">Troubleshooting <a class="anchor" data-pagefind-ignore href="#troubleshooting" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Symptom</th>
					<th>Cause / fix</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Client: &ldquo;no trusted ECDSA public key found for &lsquo;vpn.example.com&rsquo;&rdquo;</td>
					<td>iked uses its raw install-time key. Install the certificates in <code>/etc/iked/</code> (Step 1).</td>
			</tr>
			<tr>
					<td>strongSwan: &ldquo;ca certificate lacks CA basic constraint&rdquo;</td>
					<td>CA created without the <code>-addext</code> lines. Recreate it.</td>
			</tr>
			<tr>
					<td>iked refuses to load the config</td>
					<td><code>/etc/iked.conf</code> is not mode 600.</td>
			</tr>
			<tr>
					<td>SSH to the server drops when a client connects</td>
					<td>The policy uses <code>to 0.0.0.0/0</code>. Use <code>to dynamic</code>.</td>
			</tr>
			<tr>
					<td>Clients connect but cannot reach the internet</td>
					<td>IP forwarding off, or the <code>nat-to</code> rule missing.</td>
			</tr>
	</tbody>
</table>
<h2 id="security-considerations">Security Considerations <a class="anchor" data-pagefind-ignore href="#security-considerations" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>Passwords are in plain text</strong> in <code>/etc/iked.conf</code>. Keep it mode 600 and use a unique password per client.</li>
<li><strong>Protect the CA key.</strong> <code>/etc/ssl/private/cakey.pem</code> can sign certificates your clients trust. Consider moving it off the server once the certificate is signed.</li>
<li><strong>Clients must verify the server.</strong> Install <code>cacert.pem</code> on every client; EAP passwords are only safe when the server is authenticated first.</li>
</ul>
<h2 id="conclusion">Conclusion <a class="anchor" data-pagefind-ignore href="#conclusion" aria-label="Link to this section">#</a></h2>
<p>OpenBSD is now an IKEv2 VPN server with base tools only: iked for the tunnels, PF for filtering and NAT. Road warrior clients connect from anywhere with encrypted traffic, and adding a user is one line in <code>iked.conf</code>.</p>
]]></content:encoded></item></channel></rss>