Skip to content

Instantly share code, notes, and snippets.

@spiceywasabi
Last active October 22, 2021 16:53
Show Gist options
  • Save spiceywasabi/fc74a69505be7c40acd90d9ae7bbe134 to your computer and use it in GitHub Desktop.
Save spiceywasabi/fc74a69505be7c40acd90d9ae7bbe134 to your computer and use it in GitHub Desktop.

Competition VPN Network Instructions

As part of CPTC this year competitors must connect via a Wireguard VPN. While Wireguard is easy to use, this instruction guide is meant to provide a way to provide step by step instructions.

Installing Wireguard

Wireguard comes with official installers for the majority of platforms including Windows, macOS, and most Linux distributions. Please refer to this document for the installer for your appropriate system https://www.wireguard.com/install/. Plenty of guides are available for installing Wireguard, refer to these if you have issues

Getting your Wireguard Profile

Each team will be provided a set of Wireguard profiles available from the Competitors Portal.

  • Do not attempt to put multiple blocks into a single configuration file, that will not work properly.
  • Make sure each competitor has exactly one configuration as all competitors need a unique Address line in the configuration.

[WG-CONFIG]

#1 - WireGuard configurations should be saved as plain text #2 - This Address is the "Client VPN IP" ensure no two competitors have the same IP address or configuration file. This is often a manual step on Linux #3 - If you run into issues, change is to 0.0.0.0/0, otherwise the 10.0.254.0/24 is the Jump Box (client) range for you to connect to. These are NOT systems in scope, instead use these to access the competition environment.

Connecting

Below are the instructions to connect to the VPN on your respective platform

Windows

  1. Ensure the Wireguard Client is installed on the system in question
  2. Use a text editor such as VSCode or Notepad++ to save the configuration file. Do not use notepad or Wordpad as they can corrupt the line endings and make the file unusable for Wireguard. [CONFIG-WINDOWS-IMPORT-01]
  3. Open the Wireguard client and open the Import Wireguard Config [CONFIG-WINDOWS-IMPORT-02]
  4. Import the configuration and ensure the configuration matches the file
  5. Click "Activate"
  6. Open Command Prompt or your favorite terminal and ping a host in the environment [CONFIG-WINDOWS-IMPORT-03]

macOS

  1. Ensure the Wireguard Client is installed on the system in question, alternatively you can use Homebrew to install the wg client, however that is not covered here. It is recommended you use the graphical client.
  2. Use a text editor such as VSCode, BBEdit, vim, etc. Any text editor can be used, just ensure the file is saved in a place you can access (macOS Security Restrictions can prevent access to certain directories, generally your home folder is a safe location) [CONFIG-MAC-IMPORT-01]
  3. Open the Wireguard client and open the Import Wireguard Config [CONFIG-MAC-IMPORT-02]
  4. Import the configuration and ensure the configuration matches the file
  5. Click "Activate", please note you may be required to approve network monitoring and access before this will work. [CONFIG-MAC-IMPORT-03]
  6. Open another Terminal and attempt to ping a client in the environment [CONFIG-MAC-IMPORT-04]

Linux

Many Linux distributions are now providing helper scripts or service file to enable Wireguard in an easier manner. However these vary by distribution, please refer to your distributions documentation if you wish to use these. The guidance before is agnostic and can be used on any (modern) Linux system.

  1. Ensure the Wireguard Client is installed on the system in question. It is also recommended you have tmux or screen to launch the Wireguard session.
  2. Use a text editor such as vim or nano write the configuration file.
  3. Remove the Address line from the configuration file and save. Note the IP Address so you can add it to your interface. [CONFIG-LINUX-IMPORT-02]
  4. Open the Wireguard client and open the Import Wireguard Config
  5. Ensure IPv4 Forwarding is Enabled in your sysctl.conf

sysctl net.ipv4.ip_forward=1

  1. Create the Wireguard Interface and add the IP Address you saved from the configuration earlier.

ip link add dev wg0 type wireguard ip addr add 10.255.255.1/32 dev wg0

  1. Load the configuration into Wireguard

wg setconf wg0 cptc-wg.conf

  1. Bring up the interface and add finally add a route to the routing table

ip link set wg0 up ip route add 10.0.254.0/24 dev wg0

  1. Attempt to ping a system on the VPN [CONFIG-LINUX-IMPORT-03]

All commands combined:

sysctl net.ipv4.ip_forward=1
ip link add dev wg0 type wireguard
ip addr add 10.255.255.1/32 dev wg0
wg setconf wg0 cptc-wg.conf
ip link set wg0 up
ip route add 10.0.254.0/24 dev wg0
<h1 id="competition-vpn-network-instructions">Competition VPN Network Instructions</h1>
<p>As part of CPTC this year competitors must connect via a <a href="https://www.wireguard.com/">Wireguard</a> VPN. While Wireguard is easy to use, this instruction guide is meant to provide a way to provide step by step instructions.</p>
<h2 id="installing-wireguard">Installing Wireguard</h2>
<p>Wireguard comes with official installers for the majority of platforms including Windows, macOS, and most Linux distributions. Please refer to this document for the installer for your appropriate system <a href="https://www.wireguard.com/install/">https://www.wireguard.com/install/</a>. Plenty of guides are available for installing Wireguard, refer to these if you have issues</p>
<h2 id="getting-your-wireguard-profile">Getting your Wireguard Profile</h2>
<p>Each team will be provided a set of Wireguard profiles available from the Competitors Portal. </p>
<ul>
<li>Do not attempt to put multiple blocks into a single configuration file, that will not work properly. </li>
<li>Make sure each competitor has exactly one configuration as all competitors need a unique Address line in the configuration. </li>
</ul>
<p>[WG-CONFIG]</p>
<p><em>#1</em> - WireGuard configurations should be saved as plain text
<em>#2</em> - This Address is the &quot;Client VPN IP&quot; ensure no two competitors have the same IP address or configuration file. This is often a manual step on Linux
<em>#3</em> - If you run into issues, change is to 0.0.0.0/0, otherwise the 10.0.254.0/24 is the Jump Box (client) range for you to connect to. These are <strong>NOT</strong> systems in scope, instead use these to access the competition environment.</p>
<h2 id="connecting">Connecting</h2>
<p>Below are the instructions to connect to the VPN on your respective platform </p>
<h3 id="windows">Windows</h3>
<ol>
<li>Ensure the Wireguard Client is installed on the system in question</li>
<li>Use a text editor such as VSCode or Notepad++ to save the configuration file. <strong>Do not use notepad or Wordpad</strong> as they can corrupt the line endings and make the file unusable for Wireguard.
[CONFIG-WINDOWS-IMPORT-01]</li>
<li>Open the Wireguard client and open the Import Wireguard Config
[CONFIG-WINDOWS-IMPORT-02]<ol>
<li>Import the configuration and ensure the configuration matches the file</li>
<li>Click &quot;Activate&quot;</li>
<li>Open Command Prompt or your favorite terminal and ping a host in the environment
[CONFIG-WINDOWS-IMPORT-03]</li>
</ol>
</li>
</ol>
<h3 id="macos">macOS</h3>
<ol>
<li>Ensure the Wireguard Client is installed on the system in question, alternatively you can use <a href="https://mullvad.net/en/help/wireguard-mullvad-macos/">Homebrew</a> to install the <em>wg</em> client, however that is not covered here. <strong>It is recommended you use the graphical client.</strong> </li>
<li>Use a text editor such as VSCode, BBEdit, vim, etc. Any text editor can be used, just ensure the file is saved in a place you can access (macOS Security Restrictions can prevent access to certain directories, generally your home folder is a safe location)
[CONFIG-MAC-IMPORT-01]</li>
<li>Open the Wireguard client and open the Import Wireguard Config
[CONFIG-MAC-IMPORT-02]<ol>
<li>Import the configuration and ensure the configuration matches the file</li>
<li>Click &quot;Activate&quot;, please note you may be required to approve network monitoring and access before this will work.
[CONFIG-MAC-IMPORT-03]</li>
<li>Open another Terminal and attempt to ping a client in the environment
[CONFIG-MAC-IMPORT-04]</li>
</ol>
</li>
</ol>
<h3 id="linux">Linux</h3>
<p>Many Linux distributions are now providing helper scripts or service file to enable Wireguard in an easier manner. However these vary by distribution, please refer to your distributions documentation if you wish to use these. The guidance before is agnostic and can be used on any (modern) Linux system.</p>
<ol>
<li>Ensure the Wireguard Client is installed on the system in question. It is also recommended you have <em>tmux</em> or <em>screen</em> to launch the Wireguard session. </li>
<li>Use a text editor such as vim or nano write the configuration file.</li>
<li>Remove the Address line from the configuration file and save. Note the IP Address so you can add it to your interface.
[CONFIG-LINUX-IMPORT-02]</li>
<li>Open the Wireguard client and open the Import Wireguard Config</li>
<li>Ensure IPv4 Forwarding is Enabled in your sysctl.conf<blockquote>
<p>sysctl net.ipv4.ip_forward=1</p>
</blockquote>
</li>
<li>Create the Wireguard Interface and add the IP Address you saved from the configuration earlier. <blockquote>
<p>ip link add dev wg0 type wireguard
ip addr add 10.255.255.1/32 dev wg0</p>
</blockquote>
</li>
<li>Load the configuration into Wireguard <blockquote>
<p>wg setconf wg0 cptc-wg.conf</p>
</blockquote>
</li>
<li>Bring up the interface and add finally add a route to the routing table<blockquote>
<p>ip link set wg0 up
ip route add 10.0.254.0/24 dev wg0</p>
<ol>
<li>Attempt to ping a system on the VPN
[CONFIG-LINUX-IMPORT-03]</li>
</ol>
</blockquote>
</li>
</ol>
<p>All commands combined:</p>
<pre><code>sysctl net.ipv4.ip_forward=<span class="hljs-number">1</span>
<span class="hljs-built_in">ip</span> link <span class="hljs-keyword">add</span> dev wg0 type wireguard
<span class="hljs-built_in">ip</span> addr <span class="hljs-keyword">add</span> <span class="hljs-number">10.255</span><span class="hljs-meta">.255</span><span class="hljs-meta">.1</span>/<span class="hljs-number">32</span> dev wg0
wg setconf wg0 cptc-wg.conf
<span class="hljs-built_in">ip</span> link set wg0 <span class="hljs-meta">up</span>
<span class="hljs-built_in">ip</span> route <span class="hljs-keyword">add</span> <span class="hljs-number">10.0</span><span class="hljs-meta">.254</span><span class="hljs-meta">.0</span>/<span class="hljs-number">24</span> dev wg0
</code></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment