Configuring OpenIKED

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

This configuration is for a road warrior setup, where a user wants to connect his device to a network (rather than connecting two networks).

Configure iked.conf

Add this to /etc/iked.conf (replace USERNAME_HERE and PASSWORD_HERE with the username and password you will use to connect, and replace with your server's public IP address and with vpn.your.domain, i.e.:

remote_gw = ""
vpn_id = ""
client_pool = ""
client_dns = ""

ikev2 'user_vpn' passive esp \
    from any to dynamic \
    local $remote_gw peer any \
    srcid $vpn_id \
    eap "mschap-v2" \
    config address $client_pool \
    config name-server $client_dns \
    tag "ROADW"

The value for the vpn_id macro parameter MUST be different from your IRCnow hostname. For example, if your IRCNow hostname is "", you should pick something like "". Whatever you pick should be a valid hostname that resolves to an IP address. The 'from' rule allows any user to connect. The name-server provides the name-server that vpn clients will use. So in this example, you must have a valid caching name server running on IP Note that these packets will get tagged as ROADW.

iked depends upon packet filter being enabled. First, you must make sure to enable packet filter if it is off:

$ doas pfctl -e

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.

To find your external interface, type:

$ ifconfig

The external interface is the one with the public IP address. If OpenBSD is run on a virtual machine, 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:

# 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 the hostname you picked for the value of vpn_id in iked.conf.

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

We will use unbound as the caching DNS resolver. Our servers have static IP addresses so we do not use DHCP (if DHCP is used, you must ignore the provided name servers):


lookup file bind


lookup file bind


access-control: allow

local-zone: "" static




The local-zone lines are only needed if you want to filter/censor domains. You can obtain a list of domains to block using StevenBlack's hosts files. I used the unified hosts + porn + gambling filter to block unwanted content.

$ ftp

We need to reformat this hosts file:

$ awk '!/^ *#/ && NF' hosts > newhosts # taken from stevenblack's list
$ sed 's/0\.0\.0\.0 \([^#]*\).*$/local-zone: "\1" static/' newhosts > newhosts2
$ sed 's/  "/"/' newhosts2 > newhosts3

Manually check for malformed entries, then put this into /var/unbound/etc/unbound.conf.

Add this to /etc/sysctl.conf:


Run this once:

$ doas sysctl net.inet.ip.forwarding=1
$ doas sysctl net.inet6.ip6.forwarding=1
$ doas sysctl net.inet.ipcomp.enable=1
$ doas sysctl net.inet.esp.enable=1
$ doas 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

Note: You may consider using blacklists from here:

Banned networks:


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.