<?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/">
  <channel>
    <title>WireGuard on n3s0 || notes</title>
    <link>https://notes.n3s0.tech/tags/wireguard/</link>
    <description>Recent content in WireGuard on n3s0 || notes</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sat, 03 Dec 2022 17:01:37 -0600</lastBuildDate><atom:link href="https://notes.n3s0.tech/tags/wireguard/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Setup For My Personal VPN Using Wireguard, OpenBSD, and Vultr VPS</title>
      <link>https://notes.n3s0.tech/posts/20221203170137/</link>
      <pubDate>Sat, 03 Dec 2022 17:01:37 -0600</pubDate>
      
      <guid>https://notes.n3s0.tech/posts/20221203170137/</guid>
      <description>Notes for building my personal WireGuard VPN on OpenBSD hosted on a Vultr VPS.</description>
      <content:encoded><![CDATA[<h2 id="summary">Summary</h2>
<p>It&rsquo;s been a minute since I&rsquo;ve posted. But, here you go. New post with
some personal infrastructure. In the future I&rsquo;ll lay out some of the
personal infrastructure I have and use.</p>
<p>There are plenty of options on the Internet for VPN providers. Many good
ones in fact. But, I would rather have control of things like that. I&rsquo;ve
been kicking around the idea of having my own Private Cloud for years.
But, never put real thought into it. Finally after noodled through
options for this I think I have what I need, set it up, and I use this
from day to day. On my cell phone and my personal laptop.</p>
<p>One thing to note. The configuration that looks like
$WIREGUARD_PUBLIC_KEY or the like is intended to represent what it says
it is. If someone were to stumble across this in the future; judging
it isn&rsquo;t outdated by then, they&rsquo;d know what to replace the value with.</p>
<h2 id="cloud-hosting">Cloud Hosting</h2>
<p>Vultr VPS is an awesome cloud hosting provider with multiple options
available. Go ahead and check out some of their options. You can build
your own cloud server with OS options anywhere from Microsoft Windows
Server, OpenBSD, Alpine, Ubuntu, etc. They have awesome pricing for
their VMs and for this personal project they were a great fit.</p>
<ul>
<li><a href="https://www.vultr.com/pricing/">Vultr Pricing</a></li>
</ul>
<p>I chose the High Performance Intel server with the following configuration.
Which was a steal as far as monthly pricing is concerned. It may even
be able to host other services that I&rsquo;ll talk about in the future. It
has everything I need for this project.</p>
<ul>
<li>vCPU (Intel Xeon CPU): 1</li>
<li>Memory: 1 GB</li>
<li>Bandwidth: 2.00 TB</li>
<li>Storage (NVMe SSD): 25 GB</li>
<li>Pricing:
<ul>
<li>Monthly: $6.00/mo</li>
<li>Hourly: $0.009/hr</li>
</ul>
</li>
</ul>
<p>The operating system I chose for this installation was OpenBSD 7.2
release. This machine is directly accessible on the Internet. So I chose
to go with an operating system that takes the development and security
of the OS seriously.</p>
<p>Vultr provides an option where you can install a custom ISO. For added
security I&rsquo;ll rebuild this with some disk encryption so any data at
rest has some added protections from a nosey Vultr employee.</p>
<p>Post for some of the prerequisites I have before I start installing or
configuring any service on OpenBSD that&rsquo;s accessible from the Internet.
It will provide a semi-well rounded baseline for the OS. I&rsquo;ll be adding
more as I improve on this.</p>
<ul>
<li><a href="/posts/20221203224604/">OpenBSD: Initial Virtual Private Server Baseline</a></li>
</ul>
<p>Post for deploying OpenBSD with full disk encryption will be provided
below.</p>
<ul>
<li><a href="#">OpenBSD: Full Disk Encryption on Vultr Instance</a></li>
</ul>
<h2 id="initial-server-setup">Initial Server Setup</h2>
<p>First step is to install the necessary packages to perform the setup.
The libqrencode(1) package is installed so I can configure WireGuard
peers on my cell phone.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">pkg_add wireguard-tools vim libqrencode
</span></span></code></pre></div><p>The following command will enable IPv4 forwarding on the server. This is
configured so I can reach the Internet from the client VPN. NAT is used
to forward traffic back out the public facing network interface.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">sysctl net.inet.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span></code></pre></div><p>This section below is optional. It&rsquo;s needed to configure IPv6
forwarding. If IPv6 isn&rsquo;t needed or configured I generally don&rsquo;t
configure this. But, if I do in the future. I should be able to find it
in the future with this post.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">sysctl net.inet6.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span></code></pre></div><p>So these settings persist across reboots. The following line needs to be
added to the <code>/etc/sysctl.conf</code> file.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">net.inet.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span></code></pre></div><p>For the future if there is a need for both IPv4 and IPv6 forwarding in
the <code>/etc/sysctl.conf</code> file.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">net.inet.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span><span class="line"><span class="cl">net.inet6.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span></code></pre></div><h2 id="wireguard-server-setup">WireGuard Server Setup</h2>
<p>Creating the wirguard directory where the confiuration file will be
stored.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">mkdir -p /etc/wireguard
</span></span></code></pre></div><p>Creating the WireGuard configuration file for later.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">touch /etc/wireguard/wg0.conf
</span></span></code></pre></div><p>Making the configuration file for the tunnel interface less accessible
to anyone who could access the server.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">chmod <span class="m">0600</span> /etc/wireguard/*
</span></span></code></pre></div><p>Changing the user and group access of the wg0.conf file to root and
wheel.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">chown root:wheel /etc/wireguard/wg0.conf
</span></span></code></pre></div><h3 id="generate-server-keys">Generate Server Keys</h3>
<p>The <code>wg genkey</code> command below will generate the private key and
place the output in the private.key file. Located in the /etc/wireguard
directory.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg genkey &gt; private.key
</span></span></code></pre></div><p>Using the <code>wg pubkey</code> while directing the contents of
<code>private.key</code> into the command. This will generate the public key
and direct the output to the <code>public.key</code> file.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg pubkey &lt; private.key &gt; public.key
</span></span></code></pre></div><h3 id="server-configuration">Server Configuration</h3>
<p>In the <code>/etc/wireguard/wg0.conf</code> file, added the following. The
<code>wg0.conf</code> file will be utilized to apply the WireGuard
configuration on the interface when it initializes on boot. I&rsquo;ll be
talking about this in another section.</p>
<p>Below is some explaination of what it all means.</p>
<ul>
<li><code>[Interface]</code>: Indicates that the contents below are for the
interface.</li>
<li><code>PrivateKey</code>: Private key for the server.</li>
<li><code>ListenPort</code>: Port that WireGuard is listening on.</li>
<li><code>[Peer]</code>: Indicates that it&rsquo;s configuration for a peer. Each peer
will need to have this above them.</li>
<li><code>PublicKey</code>: Public key for the peer.</li>
<li><code>AllowedIPs</code>: The IP address of the peer that is allowed on the
WireGuard server.</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl"><span class="c1"># Server configuration</span>
</span></span><span class="line"><span class="cl"><span class="o">[</span>Interface<span class="o">]</span>
</span></span><span class="line"><span class="cl"><span class="nv">PrivateKey</span> <span class="o">=</span> <span class="nv">$WIREGUARD_SERVER_PRIVATE_KEY</span>
</span></span><span class="line"><span class="cl"><span class="nv">ListenPort</span> <span class="o">=</span> <span class="m">51820</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Client configuration</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Workstation</span>
</span></span><span class="line"><span class="cl"><span class="o">[</span>Peer<span class="o">]</span>
</span></span><span class="line"><span class="cl"><span class="nv">PublicKey</span> <span class="o">=</span> <span class="nv">$WORKSTATION_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl"><span class="nv">AllowedIPs</span> <span class="o">=</span> 10.19.19.10/32
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Phone</span>
</span></span><span class="line"><span class="cl"><span class="o">[</span>Peer<span class="o">]</span>
</span></span><span class="line"><span class="cl"><span class="nv">PublicKey</span> <span class="o">=</span> <span class="nv">$PHONE_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl"><span class="nv">AllowedIPs</span> <span class="o">=</span> 10.19.19.11/32
</span></span></code></pre></div><p>Configuration for the tunnel interface. Name of the interface is wg0.
This is located in the <code>/etc/hostname.wg0</code> path.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">touch /etc/hostname.wg0
</span></span></code></pre></div><p>Configuration for the interface can be found below. This does the
following things.</p>
<ul>
<li>Sets the IP address for the interface to 10.19.19.250/24.</li>
<li>Sets a description for the interface. So I know what it&rsquo;s for.</li>
<li>Enables or turns on the interface.</li>
<li>Sets the WireGuard configuration on wg0 with the configuration file
found in <code>/etc/wireguard/wg0.conf</code>.</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">inet 10.19.19.250 255.255.255.0 NONE description <span class="s2">&#34;Road Warrior Tunnel (wg0)&#34;</span>
</span></span><span class="line"><span class="cl">up
</span></span><span class="line"><span class="cl">!/usr/local/bin/wg setconf wg0 /etc/wireguard/wg0.conf
</span></span></code></pre></div><h3 id="pf-configuration">PF Configuration</h3>
<p>Firewall rules are needed so traffic passes accordingly. It does the
following.</p>
<ul>
<li>Passes in all traffic on the <code>wg0</code> interface and logs the
traffic.</li>
<li>Allows UDP traffic in from anywhere to anywhere on the WireGuard port.</li>
<li>Passes all traffic from the egress port from the WireGuard network to
anything. NATed on the vio0 interface.</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl"><span class="c1"># WireGuard tunnel rules (wg0)</span>
</span></span><span class="line"><span class="cl">pass in log on wg0
</span></span><span class="line"><span class="cl">pass in log inet proto udp from any to any port <span class="m">51820</span>
</span></span><span class="line"><span class="cl">pass out log on egress inet from <span class="o">(</span>wg0:network<span class="o">)</span> to any nat-to <span class="o">(</span>vio0<span class="o">)</span>
</span></span></code></pre></div><h2 id="phone-configuration">Phone Configuration</h2>
<p>Some recommendations for WireGuard apps can be seen in the following.</p>
<h3 id="key-generation">Key Generation</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg genkey &gt; phone-private.key
</span></span></code></pre></div><p>Generate the public key.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg pubkey &lt; phone-private.key &gt; phone-public.key
</span></span></code></pre></div><h3 id="phone-client-configuration">Phone Client Configuration</h3>
<p>Some explaination of the phone configuration is below.</p>
<ul>
<li><code>PrivateKey</code>: Private key created for the phone.</li>
<li><code>Address</code>: IP address of the phone on the tunnel.</li>
<li><code>DNS</code>: DNS server(s) for name resolution.</li>
<li><code>PublicKey</code>: Public wireguard key for the server.</li>
<li><code>AllowedIPs</code>: Allows all traffic too and from over the WireGuard
tunnel.</li>
<li><code>Endpoint</code>: IP address of the WireGuard server. Along with the
WireGuard port that&rsquo;s passing traffic.</li>
<li><code>PersistentKeepAlive</code>: Ammount of time in seconds that the
availability of tunnel connectivity is checked.</li>
</ul>
<p>The actual configuration output for the phone can be found below as
well.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="k">[Interface]</span>
</span></span><span class="line"><span class="cl"><span class="na">PrivateKey</span> <span class="o">=</span> <span class="s">$PHONE_PRIVATE_KEY</span>
</span></span><span class="line"><span class="cl"><span class="na">Address</span> <span class="o">=</span> <span class="s">10.19.19.11/24</span>
</span></span><span class="line"><span class="cl"><span class="na">DNS</span> <span class="o">=</span> <span class="s">1.1.1.1</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">[Peer]</span>
</span></span><span class="line"><span class="cl"><span class="na">PublicKey</span> <span class="o">=</span> <span class="s">$WIREGUARD_SERVER_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl"><span class="na">AllowedIPs</span> <span class="o">=</span> <span class="s">0.0.0.0/0</span>
</span></span><span class="line"><span class="cl"><span class="na">Endpoint</span> <span class="o">=</span> <span class="s">$WIREGUARD_SERVER_IP:51820</span>
</span></span><span class="line"><span class="cl"><span class="na">PersistentKeepAlive</span> <span class="o">=</span> <span class="s">25</span>
</span></span></code></pre></div><h3 id="configure-vpn-on-phone">Configure VPN On Phone</h3>
<p>Generate the QR code with the</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">cat /etc/wireguard/phone-client.conf <span class="p">|</span> qrencode -t ansiutf8
</span></span></code></pre></div><p>A QR code will show up on the screen after entering the command for the
configuration. Open up the WireGuard mobile app on your phone; after
installing it, and add a new VPN through the app using the QR code
option. Once it&rsquo;s added it should connect with no issue.</p>
<p>Once the tunnel is up. Internet connectivity can be tested using a web
browser. All traffic should be routed through the WireGuard server
hosted on the VPS now.</p>
<h2 id="workstation-configuration">Workstation Configuration</h2>
<p>Before setting up WireGuard on the workstation. Consideration needs to
be taken into which OS is being used. WireGuard is integrated in the
Linux Kernel. But, how it&rsquo;s setup will depend on the distro it&rsquo;s setup
on.</p>
<p>This will cover setting up WireGuard on Ubuntu because that&rsquo;s the OS I&rsquo;m
on at the time. But, I plan on exploring with other operating system in
the future.</p>
<h3 id="installing-packages">Installing Packages</h3>
<p>Need to install the necessary software for setting up the WireGuard VPN
client. Need to install resolvconf because it&rsquo;s required by the wg-quick
script.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">sudo apt install wireguard resolvconf -y
</span></span></code></pre></div><h3 id="key-generation-1">Key Generation</h3>
<p>Need to generate the private key first.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg genkey &gt; phone-private.key
</span></span></code></pre></div><p>Generate the public key.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg pubkey &lt; phone-private.key &gt; phone-public.key
</span></span></code></pre></div><h3 id="creating-the-configuration-file">Creating The Configuration File</h3>
<p>Created the configuration file using the following command.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">touch /etc/wireguard/wg0.conf
</span></span></code></pre></div><p>The contents of the configuration file can be found below. All of these
options are the same as the explaination provided in the phone
configuration. Just the workstation private key, and Address will be
catered to the workstations configuration.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="k">[Interface]</span>
</span></span><span class="line"><span class="cl"><span class="na">PrivateKey</span> <span class="o">=</span> <span class="s">$WORKSTATION_PRIVATE_KEY</span>
</span></span><span class="line"><span class="cl"><span class="na">Address</span> <span class="o">=</span> <span class="s">10.19.19.10/24</span>
</span></span><span class="line"><span class="cl"><span class="na">DNS</span> <span class="o">=</span> <span class="s">1.1.1.1</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">[Peer]</span>
</span></span><span class="line"><span class="cl"><span class="na">PublicKey</span> <span class="o">=</span> <span class="s">$WIREGUARD_SERVER_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl"><span class="na">AllowedIPs</span> <span class="o">=</span> <span class="s">0.0.0.0/0</span>
</span></span><span class="line"><span class="cl"><span class="na">Endpoint</span> <span class="o">=</span> <span class="s">$WIREGUARD_SERVER_IP:51820</span>
</span></span><span class="line"><span class="cl"><span class="na">PersistentKeepAlive</span> <span class="o">=</span> <span class="s">25</span>
</span></span></code></pre></div><h3 id="connecting-to-wireguard">Connecting To WireGuard</h3>
<p>The command below brings the tunnel up. Depending on how the config file
is setup. It will configure routing out through the wireguard tunnel and
to devices on it. In this particular setup. Devices on the tunnel can see
each other. But, that&rsquo;s not always bad. Just depends on the use case.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg-quick up wg0
</span></span></code></pre></div><p>Wanted to discuss the output of the command because it&rsquo;s important to
note. I will do that in due time.</p>
<p>Below is the output of the command.</p>
<pre tabindex="0"><code>[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.19.19.10/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] resolvconf -a tun.wg0 -m 0 -x
[#] wg set wg0 fwmark 51820
[#] ip -4 route add 0.0.0.0/0 dev wg0 table 51820
[#] ip -4 rule add not fwmark 51820 table 51820
[#] ip -4 rule add table main suppress_prefixlength 0
[#] sysctl -q net.ipv4.conf.all.src_valid_mark=1
[#] nft -f /dev/fd/63
</code></pre><h3 id="disconnecting-from-wireguard-tunnel">Disconnecting From WireGuard Tunnel</h3>
<p>The command below will bring the tunnel down and restore connectivity to
the local network.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg-quick down wg0
</span></span></code></pre></div><p>The output below shows that it&rsquo;s doing the following things. It&rsquo;s
cleaning up all of the work it&rsquo;s done from the previous <code>wg-quick down wg0</code> command.</p>
<pre tabindex="0"><code>[#] ip -4 rule delete table 51820
[#] ip -4 rule delete table main suppress_prefixlength 0
[#] ip link delete dev wg0
[#] resolvconf -d tun.wg0 -f
[#] nft -f /dev/fd/63
</code></pre><p>There is a section for testing the configuration. Go ahead and navigate
<a href="/posts/20221203170137/#troubleshooting--testing">here</a>.
It will provide some things that will allow for proper testing and some
troubleshooting tips for the VPN.</p>
<h2 id="troubleshooting--testing">Troubleshooting &amp; Testing</h2>
<p>This section covers some tips for troubleshooting. Throughout a
deployment issues come up. It happens. Something runs amok and there&rsquo;s a
need to fix this or that. But, It&rsquo;s not bad as long as you take the time
to troubleshoot. That is the purpose of this section. To assist with
troubleshooting on OpenBSD and test the WireGuard setup.</p>
<p>This command can be run on the server and the client/peer. It provides
the status of WireGuard connections, data that&rsquo;s been transferred,
latest handshake time, and a little more.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wg show
</span></span></code></pre></div><p>Below is the output of the command.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">Interface: wg0
</span></span><span class="line"><span class="cl">  public key: <span class="nv">$WIREGUARD_SERVER_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl">  private key: <span class="o">(</span>hidden<span class="o">)</span>
</span></span><span class="line"><span class="cl">  listening port: <span class="m">51820</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">peer: <span class="nv">$PEER_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl">  allowed ips: 10.19.19.10/32
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">peer: <span class="nv">$PEER_PUBLIC_KEY</span>
</span></span><span class="line"><span class="cl">  endpoint: <span class="nv">$PEER_IP</span>:57323
</span></span><span class="line"><span class="cl">  allowed ips: 10.19.19.11/32
</span></span><span class="line"><span class="cl">  latest handshake: <span class="m">45</span> seconds ago
</span></span><span class="line"><span class="cl">  transfer: 2.06 MiB received, 2.33 MiB sent
</span></span></code></pre></div><p>Pinging the tunnel gateway for the server is a good way to test that
there is some routing and connectivity working correctly. At least on
the inside of the tunnel.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">ping -c <span class="m">4</span> 10.19.19.250
</span></span></code></pre></div><p>Output can be seen below.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">PING 10.19.19.250 <span class="o">(</span>10.19.19.250<span class="o">)</span> 56<span class="o">(</span>84<span class="o">)</span> bytes of data.
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 10.19.19.250: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">1</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">255</span> <span class="nv">time</span><span class="o">=</span>34.0 ms
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 10.19.19.250: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">2</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">255</span> <span class="nv">time</span><span class="o">=</span>33.5 ms
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 10.19.19.250: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">3</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">255</span> <span class="nv">time</span><span class="o">=</span>35.4 ms
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 10.19.19.250: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">4</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">255</span> <span class="nv">time</span><span class="o">=</span>34.2 ms
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">--- 10.19.19.250 ping statistics ---
</span></span><span class="line"><span class="cl"><span class="m">4</span> packets transmitted, <span class="m">4</span> received, 0% packet loss, <span class="nb">time</span> 3004ms
</span></span><span class="line"><span class="cl">rtt min/avg/max/mdev <span class="o">=</span> 33.549/34.286/35.352/0.661 ms
</span></span></code></pre></div><p>Pinging an external IP address - like Cloudflare - is a good way to test
connectivity outside of the VPN. Afterall, that is one of points to this
client VPN. So, testing it&rsquo;s working is pretty important.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">ping -c <span class="m">4</span> 1.1.1.1
</span></span></code></pre></div><p>Belwo is the output from this command.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">PING 1.1.1.1 <span class="o">(</span>1.1.1.1<span class="o">)</span> 56<span class="o">(</span>84<span class="o">)</span> bytes of data.
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 1.1.1.1: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">1</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">57</span> <span class="nv">time</span><span class="o">=</span>35.7 ms
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 1.1.1.1: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">2</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">57</span> <span class="nv">time</span><span class="o">=</span>34.6 ms
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 1.1.1.1: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">3</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">57</span> <span class="nv">time</span><span class="o">=</span>42.8 ms
</span></span><span class="line"><span class="cl"><span class="m">64</span> bytes from 1.1.1.1: <span class="nv">icmp_seq</span><span class="o">=</span><span class="m">4</span> <span class="nv">ttl</span><span class="o">=</span><span class="m">57</span> <span class="nv">time</span><span class="o">=</span>34.7 ms
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">--- 1.1.1.1 ping statistics ---
</span></span><span class="line"><span class="cl"><span class="m">4</span> packets transmitted, <span class="m">4</span> received, 0% packet loss, <span class="nb">time</span> 3005ms
</span></span><span class="line"><span class="cl">rtt min/avg/max/mdev <span class="o">=</span> 34.559/36.949/42.822/3.418 ms
</span></span></code></pre></div><p>This command should provide the public address of the system issuing it.
It sends a GET request to <a href="https://ifconfig.io">ifconfig.io</a> and sends the
public IP back.</p>
<p>This can be checked before and after connecting to the VPN to determine
that it&rsquo;s working. If the IP changes to the WireGuard server. It works.</p>
<p>Note that this wont work as expected if the WireGuard server is just
some machine on your network. It will show the same public IP every
time.</p>
<p>It&rsquo;s also a good way to check that things are working on your phone. Use
the link provided and it should open in a browser.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">curl ifconfig.io
</span></span></code></pre></div><p>Helps check the route path using ICMP and not UDP. It can be done
without the <code>-I</code> flag to test UDP.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">traceroute -I ifconfig.io
</span></span></code></pre></div><h3 id="i-tip-my-hat-to-the-details">I Tip My Hat To The Details</h3>
<p>One thing to also consider during setup is typos in configuration files.
This occured when I started setting up the VPN on the server. When I
setup the IP forwarding so it could reach the Internet. I fat fingered
the IP forwarding in the <code>/etc/sysctl.conf</code> file.</p>
<p>This caused about a week of troubleshooting and pulling my hair out.
Part of thinking that everything was configured the way it should be.
When finally had enough. I got a second opinion from a friend of mine
and he asked to see the <code>sysctl.conf(5)</code> file. Which revealed that
the IPv4 configuration was the problem.</p>
<p>If someone else is setting this up. Just keep this in mind.</p>
<p>Command for checking all sysctl parameters and filtering the
<code>net.inet.ip.forwarding</code> value.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">sysctl -a <span class="p">|</span> grep inet.ip.forwarding
</span></span></code></pre></div><p>The output should look like this. If it&rsquo;s set to 0 and you swear that
it&rsquo;s configured properly in the configuration file. It probably isn&rsquo;t.
Check the configuration file to make sure.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">net.inet.ip.forwarding<span class="o">=</span><span class="m">1</span>
</span></span></code></pre></div><h2 id="reference">Reference</h2>
<p>Below are some references that can be found for when I was looking into
accomplishing this.</p>
<ul>
<li><a href="https://www.vultr.com/pricing/">Vultr Pricing</a></li>
<li><a href="https://www.wireguard.com/">WireGuard</a></li>
<li><a href="https://www.wireguard.com/papers/wireguard.pdf">WireGuard Whitepaper</a></li>
<li><a href="https://nox.im/posts/2021/0926/self-hosted-wireguard-vpn-on-openbsd/">Self Hosted WireGuard VPN on OpenBSD</a></li>
<li><a href="https://blog.jasper.la/wireguard-on-openbsd.html">Wireguard On OpenBSD</a></li>
<li><a href="https://flak.tedunangst.com/post/toying-with-wireguard-on-openbsd">toying with wireguard on openbsd</a></li>
<li><a href="https://x61.sh/log/2022/01/20220104T122904-wireguard.html">wireguard</a></li>
<li><a href="https://www.vultr.com/docs/install-wireguard-vpn-server-on-openbsd-7-0/">Install Wireguard VPN Server on OpenBSD 7.0</a></li>
<li><a href="https://ianix.com/wireguard/openbsd-howto.html">Howto: WireGuard on OpenBSD</a></li>
<li><a href="https://thomasward.com/openbsd-wireguard/">Securely tunnel smart phone traffic with WireGuard and OpenBSD</a></li>
</ul>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
