Roadwarrior IPsec

(redirected from Iked.Configure)

OpenIKED is OpenBSD's native VPN solution. It is included with the base system, so no installation will be necessary. It allows us to use IPSec to provide users with a VPN for security, privacy, and freedom of information.


  • Clean
  • Secure
  • Interoperable
  • Simple to Configure

In this guide, we configure a server to provide ipsec for devices in a road warrior setup: an end-user wants to relay all his traffic from a single device through the VPS to the Internet. The server acts as an IPsec gateway, and only the server needs a public IP address.; the end-user can be behind a NAT.

Note: If you are trying to connect two networks together, consult the site-to-site ipsec guide.

Before You Begin

Make sure to read the FAQ's VPN guide and the manual pages for iked and iked.conf.

Configure iked.conf

Add this to /etc/iked.conf (replace username and password with your actual username and password; replace with your server's public IP address; and replace with your actual hostname):

gateway = ""
hostname = ""
pool = ""
dns = ""

user 'username' 'password'
ikev2 $hostname passive esp \
    from any to dynamic \
    local $gateway peer any \
    srcid $hostname \
    eap "mschap-v2" \
    config address $pool \
    config name-server $dns \
    tag "ROADW"

You must replace with be a valid hostname that resolves to an IP address. Leave pool as

from any to dynamic allows any user to connect. $dns must provide the IP address for the name server that vpn clients will use. This example assumes you have a valid caching name server configured and listening on IP

These packets will get tagged as ROADW.

iked depends upon packet filter being enabled. First, enable packet filter if it is turned off:

$ doas pfctl -e

Next, add this to /etc/pf.conf:

pass in inet proto udp to port {isakmp, ipsec-nat-t} tag IKED
pass in inet proto esp tag IKED
pass on enc0 inet tagged ROADW
match out on $ext_if inet tagged ROADW nat-to $ext_if
match in quick on enc0 inet proto { tcp, udp } to port 53 rdr-to port 53

where $ext_if is your external interface.

NOTICE: You must make sure that your firewall whitelists VPN traffic. You might consider adding this macro:

VPN = ""

To find your external interface, type:

$ ifconfig

The external interface is the one with the public IP address. If OpenBSD is run inside vmm, the external interface is probably vio0.

To reload the new pf ruleset:

$ doas pfctl -f /etc/pf.conf 

At this point, we need to create PKI and X.509 certificates that the vpn client can use to verify the server. From the command line, run this as root:

# ikectl ca vpn create
# ikectl ca vpn install
certificate for CA 'vpn' installed into /etc/iked/ca/ca.crt
CRL for CA 'vpn' installed to /etc/iked/crls/ca.crl
# ikectl ca vpn certificate create
# ikectl ca vpn certificate install
writing RSA key

Replace with your actual domain.

Users of the VPN will need to download /etc/iked/ca/ca.crt to their device. The easiest way is to use openhttpd and serve the file over the web.

# cp /etc/iked/ca/ca.crt /var/www/htdocs/
# chown www:daemon /var/www/htdocs/

If the web server is configured correctly, users can then download the file at

Configuring DNS

This example uses unbound as the caching DNS resolver. It assumes your server has its IP addresses statically assigned and is not using DHCP to locate its name servers.

Replace /etc/resolv.conf with the following:

lookup file bind

Edit the following values in /var/unbound/etc/unbound.conf:

access-control: allow

We recommend configuring domain blacklists for unbound to block unwanted traffic.

Edit /etc/sysctl.conf to include these directives:


Next, run these commands as root:

sysctl net.inet.ip.forwarding=1
sysctl net.inet6.ip6.forwarding=1
sysctl net.inet.ipcomp.enable=1
sysctl net.inet.esp.enable=1
sysctl net.inet.ah.enable=1

IP forwarding allows the server to forward the user's packets to their final destination.

Tighten file permissions, then start iked:

$ doas chmod 0600 /etc/iked.conf
$ doas rcctl enable iked
$ doas rcctl start iked


Running iked in debug mode can provide valuable info about errors in configuration.

First, turn off iked if it is running:

$ doas rcctl stop iked

Check to make sure no iked processes are running:

$ ps ax | grep iked

Then, run iked in debug mode:

$ doas iked -dv

-d will cause iked to not daemonize, and -v will report errors verbosely.