<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DevMemo – vpn</title><link>https://devmemo.gitlab.io/tags/vpn/</link><description>Recent content in vpn on DevMemo</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sun, 02 Jul 2023 04:57:29 -0700</lastBuildDate><atom:link href="https://devmemo.gitlab.io/tags/vpn/index.xml" rel="self" type="application/rss+xml"/><item><title>Blog: Set Up VPN Server And VPN Router</title><link>https://devmemo.gitlab.io/blog/set_up_vpn_server_and_vpn_router/</link><pubDate>Sun, 02 Jul 2023 04:57:29 -0700</pubDate><guid>https://devmemo.gitlab.io/blog/set_up_vpn_server_and_vpn_router/</guid><description>
&lt;h2 id="set-up-vpn-server">Set Up VPN Server&lt;/h2>
&lt;p>Deploy an ubuntu 22.04 server on your target network. Run the following commands to install vpn server on it.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>wget https://raw.githubusercontent.com/Angristan/openvpn-install/master/openvpn-install.sh -O ubuntu-22.04-lts-vpn-server.sh
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>chmod -v +x ubuntu-22.04-lts-vpn-server.sh
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo ./ubuntu-22.04-lts-vpn-server.sh
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Once it is done, an ovpn file will be generated, for example,&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-text" data-lang="text">&lt;span style="display:flex;">&lt;span>The configuration file has been written to /home/ubuntu/linux.ovpn.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="set-up-vpn-router">Set Up VPN Router&lt;/h2>
&lt;h3 id="step-1-install-an-physical-ubuntu-server">Step 1: Install An Physical Ubuntu Server&lt;/h3>
&lt;p>Install ubuntu on a device which has:&lt;/p>
&lt;ul>
&lt;li>A physical ethernet port connected to your home router. This port will be used to exchange data from and to the Internet.&lt;/li>
&lt;li>A wifi adapter. This port will be used as a hotspot for your devices to connect. Any device connected to this hotspot will be able use send traffic through the vpn server.&lt;/li>
&lt;/ul>
&lt;p>This ubuntu server will be used as your VPN router.&lt;/p>
&lt;h3 id="step-2-set-up-dns">Step 2: Set Up DNS&lt;/h3>
&lt;p>Run the following command to set up your DNS on your VPN router.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>echo &lt;span style="color:#e6db74">&amp;#34;[Resolve]
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">DNS=8.8.8.8 8.8.4.4
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">&amp;#34;&lt;/span> | sudo tee /etc/systemd/resolved.conf.d/99-dns.conf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Restart your VPN router,&lt;/p>
&lt;h3 id="step-3-create-a-wifi-hotspot">Step 3: Create A Wifi Hotspot&lt;/h3>
&lt;p>Run the following command to create a wifi hotspot.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo nmcli d wifi hotspot ifname &lt;span style="color:#f92672">{&lt;/span>interface-name&lt;span style="color:#f92672">}&lt;/span> ssid &lt;span style="color:#f92672">{&lt;/span>wifi-ssid&lt;span style="color:#f92672">}&lt;/span> password &lt;span style="color:#f92672">{&lt;/span>wifi-passwd&lt;span style="color:#f92672">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-4-connect-to-your-vpn-server-from-your-vpn-router">Step 4: Connect To Your VPN Server From Your VPN Router&lt;/h3>
&lt;p>Copy the opvn config file from your VPN server to your VPN router, and run the following command.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo openvpn --config &lt;span style="color:#f92672">{&lt;/span>ovpn-config-file&lt;span style="color:#f92672">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="step-5-enable-nat-on-ubuntu-server">Step 5: Enable NAT On Ubuntu Server&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>iptables -t nat -A POSTROUTING -j MASQUERADE
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This config will go away if you reboot your linux server. To make it persistent, do the following&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo apt update -y &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> sudo apt install iptables-persistent
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now your VPN router is ready to use.&lt;/p></description></item></channel></rss>