<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://dev1galaxy.org/extern.php?action=feed&amp;tid=5319&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / Wireguard VPN install]]></title>
		<link>http://dev1galaxy.org/viewtopic.php?id=5319</link>
		<description><![CDATA[The most recent posts in Wireguard VPN install.]]></description>
		<lastBuildDate>Tue, 01 Nov 2022 02:01:10 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Wireguard VPN install]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=38193#p38193</link>
			<description><![CDATA[<p>This post may look long, and it is.&#160; After installing, using, and fighting with an openvpn server for about 6 years, configuring and using a wireguard vpn server is much easier.&#160; A lot has been shared on the internet on installing and configuring wireguard.&#160; I don&#039;t think another one is needed, but I tried to put together a wireguard vpn and this is what I came up with on Devuan Chimaera.&#160; </p><p>The information below was mainly taken from these two tutorials:<br /><a href="https://linuxize.com/post/how-to-set-up-wireguard-vpn-on-debian-10/" rel="nofollow">https://linuxize.com/post/how-to-set-up … debian-10/</a></p><p>Dual stack ipv4 and ipv6:<br /><a href="https://stanislas.blog/2019/01/how-to-setup-vpn-server-wireguard-nat-ipv6/" rel="nofollow">https://stanislas.blog/2019/01/how-to-s … -nat-ipv6/</a></p><p>Also, I did run across and implement a couple of features that appear to work well with wireguard and devuan.&#160; These two items are 1- a sysvinit start/stop/status script, and 2- how to run multiple instances on the same vps, using different ports.&#160; You may not need to run wireguard on multiple ports but if you have a dedicated vps server, and one port is blocked by an internet service provider, having another port available might be of use.&#160; This &quot;should&quot; get a functional vpn tunnel operational, and then you can do more advanced things within the tunnel itself, if you wish.</p><p>Configuration steps:<br />- install wireguard<br />- Configure keys and wg0 file on both the server and peer (client)<br />- Create sysvinit startup script<br />- sysctl.conf edits to allow for routing on the server<br />- Add vpn profile to mobile device with a qr-code scan<br />- Import WireGuard profile using Network-Manager (nmcli)<br />- Create multiple instances of wireguard on different ports (same host/server) (optional)</p><p><strong>On Server</strong><br />Install:</p><div class="quotebox"><blockquote><div><p>apt install wireguard</p></div></blockquote></div><p>create keys:<br />&#160; &#160; </p><div class="codebox"><pre><code>wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey</code></pre></div><p>&#160; &#160; </p><div class="codebox"><pre><code>sudo nano /etc/wireguard/wg0.conf</code></pre></div><p>Add to wg0.conf file, you may choose your own ip address subnets, and you may select a different port number:&#160; &#160; </p><div class="quotebox"><blockquote><div><p>[Interface]<br />Address = 10.0.0.1/24,fd00::1/64<br />ListenPort = 51820<br />PrivateKey = SERVER_PRIVATE_KEY<br />PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<br />PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE</p><p>[Peer]<br />PublicKey = CLIENT_PUBLIC_KEY<br />AllowedIPs = 10.0.0.2,fd00::2&#160; &#160; <br />PersistentKeepalive = 24</p></div></blockquote></div><p>&#160; &#160; </p><div class="codebox"><pre><code>sudo chmod 600 /etc/wireguard/{privatekey,wg0.conf}</code></pre></div><p><a href="https://www.procustodibus.com/blog/2021/06/wireguard-sysv-init-script/" rel="nofollow">https://www.procustodibus.com/blog/2021 … it-script/</a><br />Sysvinit start/stop/status script:<br />&#160; &#160; </p><div class="codebox"><pre><code>nano /etc/init.d/wg0</code></pre></div><p>Add this to file:</p><div class="codebox"><pre class="vscroll"><code>#!/bin/sh -eu
# checkconfig: 2345 30 70
# description: set up a WireGuard interface simply
### BEGIN INIT INFO
# Provides: wg-quick
# Required-Start: $local-fs $network
# Required-Stop: $local-fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: set up a WireGuard interface simply
### END INIT INFO

command=/usr/bin/wg-quick
interface=wg0
description=&quot;wg-quick on $interface&quot;
logfile=/var/log/$interface

status() {
    /usr/bin/wg show $interface
}

start() {
    touch $logfile &amp;&amp; date &gt;&gt;$logfile
    echo &quot;starting $description ...&quot; | tee -a $logfile
    $command up $interface &gt;&gt;$logfile 2&gt;&amp;1
    echo &quot;... started $description&quot; | tee -a $logfile
}

stop() {
    touch $logfile &amp;&amp; date &gt;&gt;$logfile
    echo &quot;stopping $description ...&quot; | tee -a $logfile
    $command down $interface &gt;&gt;$logfile 2&gt;&amp;1
    echo &quot;... stopped $description&quot; | tee -a $logfile
}

case &quot;${1-}&quot; in
    status) status ;;
    start) start ;;
    restart) stop || true; start ;;
    stop) stop ;;
    *) echo &quot;usage: $0 {status|start|restart|stop}&quot; ;;
esac</code></pre></div><p>Make executable with<br />&#160; &#160; </p><div class="codebox"><pre><code>chmod +x /etc/init.d/wg0</code></pre></div><p>Update default rc links:<br />&#160; &#160; </p><div class="codebox"><pre><code>update-rc.d wg0 defaults</code></pre></div><p>Enable IPv4 and IPv6 routing on the server<br />In /etc/sysctl.conf, add or uncomment these, and save file</p><div class="codebox"><pre><code>net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding = 1</code></pre></div><p>Save the file and apply the change:<br />&#160; &#160; </p><div class="codebox"><pre><code>sudo sysctl -p</code></pre></div><p>Open up your firewall to allow for incoming udp connections to the port number you specified, if it is different from port 51820.&#160; </p><p><strong>On Client</strong><br />Install:</p><div class="quotebox"><blockquote><div><p>apt install wireguard</p></div></blockquote></div><p>create keys:<br />&#160; &#160; </p><div class="codebox"><pre><code>wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey</code></pre></div><p>Create the file wg0.conf and add the following contents:<br />&#160; &#160; </p><div class="codebox"><pre><code>sudo nano /etc/wireguard/wg0.conf</code></pre></div><p>Add this to the wg0.conf file on the client machine</p><div class="quotebox"><blockquote><div><p>[Interface]<br />PrivateKey = CLIENT_PRIVATE_KEY<br />Address = 10.0.0.2/24<br />DNS = 8.8.8.8,2620:0:ccc::1</p><p>[Peer]<br />PublicKey = SERVER_PUBLIC_KEY<br />Endpoint = SERVER_IP_ADDRESS:51820<br />AllowedIPs = 0.0.0.0/0</p></div></blockquote></div><p>The client keys needed for a mobile device can be created on any computer, and does not need to be created on the mobile device itself.&#160; I just created a different folder and populated it with the keys so that the other keys were not overwritten.</p><p>At this point, you should have a fully functional wireguard vpn server.&#160; But you will need to start the wg0 service first.<br />&#160; &#160; </p><div class="codebox"><pre><code>service wg0 start</code></pre></div><p>Useful commands to see wg0 on server, or use &quot;service wg0 {start,stop,status}&quot;<br />To start vpn tunneling:<br />&#160; &#160; </p><div class="codebox"><pre><code>sudo wg-quick up wg0</code></pre></div><p>To stop the tunneling, bring down the wg0 interface:<br />&#160; &#160; </p><div class="codebox"><pre><code>sudo wg-quick down wg0</code></pre></div><p>To check the interface state and configuration, run:<br />&#160; &#160; </p><div class="codebox"><pre><code>sudo wg show wg0</code></pre></div><p>You can also verify the interface state with ip a show wg0:<br />&#160; &#160; </p><div class="codebox"><pre><code>ip a show wg0</code></pre></div><p><a href="https://www.hardill.me.uk/wordpress/2021/04/20/setting-up-wireguard-ipv6/" rel="nofollow">https://www.hardill.me.uk/wordpress/202 … uard-ipv6/</a></p><p>Add vpn profile to mobile device with qr-code scan.&#160; To generate qr code for android import:&#160; <br />&#160; &#160; </p><div class="quotebox"><blockquote><div><p>apt install qrencode</p></div></blockquote></div><p>From the computer where the client keys and client wg0.conf file are located, as root<br />&#160; &#160; </p><div class="codebox"><pre><code>qrencode -t png -o wg0.png &lt; wg0.conf</code></pre></div><p>&#160; &#160; </p><div class="codebox"><pre><code>qrencode -t ansiutf8 &lt; wg0.conf</code></pre></div><p>The qr-code will display in the terminal, and from the wireguard mobile app<br />&#160; &#160; Add &gt; Scan from QR Code<br />Once the profile is imported, minor changes can be made to the profile itself as editing is allowed.</p><p><a href="https://www.cyberciti.biz/faq/how-to-import-wireguard-profile-using-nmcli-on-linux/" rel="nofollow">https://www.cyberciti.biz/faq/how-to-im … -on-linux/</a></p><p>How to import WireGuard profile using nmcli (Network-Manager) on Linux.&#160; We can import /etc/wireguard/wg0.conf by typing the following command(s):</p><p>Set up shell environment variable: <br />&#160; &#160; </p><div class="codebox"><pre><code>file=&#039;/etc/wireguard/wg0.conf&#039;</code></pre></div><p>&#160; &#160;<br />Now import it using the nmcli command: <br />&#160; &#160; </p><div class="codebox"><pre><code>sudo nmcli connection import type wireguard file &quot;$file&quot;</code></pre></div><p>&#160; <br />Rename profile wg0 as hostname-wg0, or whatever you want it to be: <br />&#160; &#160; </p><div class="codebox"><pre><code>nmcli connection modify wg0 connection.id &quot;hostname-wg0&quot;</code></pre></div><p>You may repeat this procedure for all WireGuard profiles on Linux when using NetworkManager CLI interface called nmcli.</p><p><strong>Multiple instances</strong> on same host with different ports, minimal changes are needed to a newly created wg1 interface file.&#160; The file can be given any name.<br />wg1 sounds good for this example.</p><p>Make duplicate of wg0.conf file<br />&#160; &#160; </p><div class="codebox"><pre><code>cd /etc/wireguard</code></pre></div><p>&#160; &#160; </p><div class="codebox"><pre><code>cp wg0.conf wg1.conf</code></pre></div><p>Edits to wg1.conf file, change the listening port</p><div class="codebox"><pre><code>ListenPort = ??</code></pre></div><p>&#160; &#160; (whatever port you choose)</p><p>Also, <em>the noted [Peer] subnet must be different from wg0!</em><br />Change this from what is noted in the wg0.conf file:<br />&#160; &#160; </p><div class="codebox"><pre><code>AllowedIPs = 10.0.0.3,fd00::3</code></pre></div><p>&#160; &#160; -to-<br />&#160; &#160; </p><div class="codebox"><pre><code>AllowedIPs = 10.0.1.3,fd01::3</code></pre></div><p>The rest of the file can stay the same, including the keys.<br />&#160; &#160; </p><div class="codebox"><pre><code>sudo chmod 600 /etc/wireguard/wg1.conf</code></pre></div><p>The best port to use for a vpn is open for discussion.&#160; Which port is least likely to be blocked by internet carriers?<br />Wireguard only uses udp, not tcp.&#160; Ports 443 and 53 are most often mentioned as least likely to be blocked.</p><p>Add / edit the /etc/init.d/wg1 script<br />Make copy of /etc/init.d/wg0 script<br />&#160; &#160; </p><div class="codebox"><pre><code>cd /etc/init.d</code></pre></div><p>&#160; &#160; </p><div class="codebox"><pre><code>cp wg0 wg1</code></pre></div><p>Open file /etc/init.d/wg1<br />&#160; &#160; </p><div class="codebox"><pre><code>nano wg1</code></pre></div><p>&#160; &#160; <br />and change the following line:<br />&#160; &#160; </p><div class="quotebox"><blockquote><div><p>interface=wg0</p></div></blockquote></div><p>&#160; &#160;<br />change to:<br />&#160; &#160; </p><div class="codebox"><pre><code>interface=wg1</code></pre></div><p>Save the file.</p><p>The first time above we ran <br />&#160; &#160; update-rc.d wg0 defaults<br />to update the script links into the /etc/rc.d folders.&#160; However, when it is run again with <br />&#160; &#160; update-rc.d wg1 defaults<br />It does not build any links in any rc0, rc1, rc2... folders, and this response is noted in the terminal,</p><div class="quotebox"><blockquote><div><p>insserv: script wg1: service wg-quick already provided!</p></div></blockquote></div><p>But the wg1 service still works, it just does not start at boot.&#160; This can be corrected by adding <br />&#160; &#160; </p><div class="codebox"><pre><code>service wg1 start</code></pre></div><p>to /etc/rc.local file so it will start at boot.&#160; You might want the rc.local file to look like this:</p><div class="quotebox"><blockquote><div><p>service wg1 start<br />sleep 1<br />exit 0</p></div></blockquote></div><p>The&#160; service {wg0,wg1} start/stop/status&#160; commands will work. </p><p>The additional memory usage for the extra interface is minimal on a 512mb vultr vps server.&#160; CPU and memory use is quite light with wireguard in general.</p><p>Additional and helpful info on wireguard:<br /><a href="https://www.reddit.com/r/WireGuard/comments/qlqtbe/wireguard_how_to_have_multiple_clients_on_the/" rel="nofollow">https://www.reddit.com/r/WireGuard/comm … ts_on_the/</a></p><p>I hope I did not overlook anything.</p><p>I get a little paranoid using public wifi hotspots.&#160; I am glad my vpn is operational again and I don&#039;t want to pay for a vpn if I can host my own.</p>]]></description>
			<author><![CDATA[dummy@example.com (nixer)]]></author>
			<pubDate>Tue, 01 Nov 2022 02:01:10 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=38193#p38193</guid>
		</item>
	</channel>
</rss>
