{"id":987,"date":"2022-07-23T07:59:50","date_gmt":"2022-07-23T14:59:50","guid":{"rendered":"https:\/\/jasonsblog.access.ly\/?p=987"},"modified":"2022-11-05T08:52:37","modified_gmt":"2022-11-05T15:52:37","slug":"install-wireguard-vpn-on-your-raspberry-pi-with-docker","status":"publish","type":"post","link":"https:\/\/jasonsblog.ddns.net\/index.php\/2022\/07\/23\/install-wireguard-vpn-on-your-raspberry-pi-with-docker\/","title":{"rendered":"Install Wireguard VPN on your Raspberry Pi with Docker"},"content":{"rendered":"\n<p>Instead of trusting a third party for your VPN service when on public or someone else&#8217;s wifi network, you can easily install your own VPN on a Raspberry Pi. And with Wireguard VPN you&#8217;ll have one of the most modern, efficient and low overhead VPNs that will allow you to use the Raspberry Pi for other services or projects. This will also give you access to your local network and services you&#8217;ve setup like Pi-Hole DNS server with Unbound, adding DNS privacy and ad filtering to your mobile phone even while away from home. <\/p>\n\n\n\n<p>There are two ways to install Wireguard, so if you want to install natively the easiest way is with <a aria-label=\"PiVPN (opens in a new tab)\" href=\"https:\/\/www.pivpn.io\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">PiVPN<\/a> which is an interactive script to help you <a aria-label=\"setup the VPN (opens in a new tab)\" href=\"https:\/\/pimylifeup.com\/raspberry-pi-wireguard\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">setup the VPN<\/a> which couldn&#8217;t be easier. But for this article we&#8217;ll install the Wireguard docker image which is even easier. To get started you&#8217;ll want to create the directory to hold your docker-compose.yml file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir wireguard\ncd wireguard<\/code><\/pre>\n\n\n\n<p>Then create the file docker-compose.yml with the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: \"2.1\"\nservices:\n  wireguard:\n    image: linuxserver\/wireguard\n    container_name: wireguard\n    cap_add:\n      - NET_ADMIN\n      - SYS_MODULE\n    environment:\n      - PUID=1001\n      - PGID=100\n      - TZ=America\/Denver\n      - SERVERURL=auto\n      - SERVERPORT=51820\n      - PEERS=1 #change to match how many devies you want to use Wireguard on\n      - PEERDNS=auto\n      - INTERNAL_SUBNET=10.13.13.0 #optional\n      - ALLOWEDIPS=0.0.0.0\/0 #optional\n    volumes:\n      - \/path\/to\/appdata\/config:\/config\n      - \/lib\/modules:\/lib\/modules #do not change\n    ports:\n      - 51820:51820\/udp\n    restart: unless-stopped\nnetworks:\n      default:\n        external:\n          name: wireguard<\/code><\/pre>\n\n\n\n<p>If you want more than one device to be able to use the VPN, set PEERS to a the number you&#8217;ll need. Now before we run the instance, we&#8217;ll need to create the Docker network.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network create wireguard<\/code><\/pre>\n\n\n\n<p>And then run your instance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker-compose up -d<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"345\" src=\"https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_2022-07-23_07-57-01-1.png\" alt=\"\" class=\"wp-image-1932\" srcset=\"https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_2022-07-23_07-57-01-1.png 934w, https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_2022-07-23_07-57-01-1-300x111.png 300w, https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_2022-07-23_07-57-01-1-768x284.png 768w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/figure>\n\n\n\n<p>You&#8217;ll need to open the port 51820 on your home router and point it to your Raspberry Pi for incoming connections.<\/p>\n\n\n\n<p>Now you&#8217;ll want to install the Wireguard app on your smartphone, and for this example we&#8217;ll use Android.<\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.wireguard.android&amp;hl=en_US&amp;gl=US\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">https:\/\/play.google.com\/store\/apps\/details?id=com.wireguard.android&amp;hl=en_US&amp;gl=U<\/a><\/p>\n\n\n\n<p>Now to add your Wireguard instance to your app you&#8217;ll need to scan the QR code, so to display the QR code in your terminal you can run the following command and give it your peer number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker exec -it wireguard \/app\/show-peer 1<\/code><\/pre>\n\n\n\n<p>You&#8217;ll hit the add (plus) sign in the bottom right of the phone app, and then select Scan From QR Code, which will open the camera for you to scan the QR code. Once added select the VPN in the list and click the pencil icon at top right to edit the entry and add your dynamic DNS entry. Then you just click the slider to connect to your Pi Wireguard VPN. If it&#8217;s working at the bottom you&#8217;ll see traffic coming down and going up. And now you&#8217;re on your local network at home and can access local machines, use your private DNS servers or access any other services you like without having to expose them to the internet.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_20220723-080939-1-481x1024.png\" alt=\"\" class=\"wp-image-1933\" width=\"290\" height=\"616\" srcset=\"https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_20220723-080939-1-481x1024.png 481w, https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_20220723-080939-1-141x300.png 141w, https:\/\/jasonsblog.ddns.net\/wp-content\/uploads\/2022\/11\/Screenshot_20220723-080939-1-962x2048.png 962w\" sizes=\"auto, (max-width: 290px) 100vw, 290px\" \/><\/figure>\n\n\n\n<p>Note, that this is my second Wireguard VPN on my network, so I used port 51821 witch routes to 51820 in my docker image. Redundancy is nice, so I also have a Wireguard install on another Pi using the default port 51820. And you can change these ports to whatever you would like, but do search for the port online and make sure you&#8217;re not using the default port for another service if you&#8217;re looking for a little security by obscurity. <\/p>\n\n\n\n<p>And just that easily you have your own VPN service to use when away from home. And using commercial VPN services is starting to get complicated as they&#8217;re being bought up by large corporations, with one particular one <a aria-label=\"having a connection to an intelligence agency (opens in a new tab)\" href=\"https:\/\/www.hackread.com\/private-internet-access-pia-vpn-sold-israel-privacy-concerns\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">having a connection to an intelligence agency<\/a>. So if you do use a commercial VPN service make sure you research them and see that they have undergone a full audit to their claims of keeping no logs and honoring their service commitments. But at least you can trust your very own VPN service you control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Instead of trusting a third party for your VPN service when on public or someone else&#8217;s wifi network, you can easily install your own VPN on a Raspberry Pi. And with Wireguard VPN you&#8217;ll have one of the most modern, efficient and low overhead VPNs that will allow you to use the Raspberry Pi for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-987","post","type-post","status-publish","format-standard","hentry","category-tech"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"featured_image_src":null,"author_info":{"display_name":"Jason","author_link":"https:\/\/jasonsblog.ddns.net\/index.php\/author\/jturning\/"},"_links":{"self":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts\/987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/comments?post=987"}],"version-history":[{"count":9,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"predecessor-version":[{"id":1943,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/posts\/987\/revisions\/1943"}],"wp:attachment":[{"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jasonsblog.ddns.net\/index.php\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}