If you are not going to use a local VPN, you can skip this section.
We will configure the private traffic Docker stack; we will configure the firewall to allow the necessary port; and we will bring the stack up through Portainer. We will do Port Forwarding of port 51820 for WireGuard. Finally, we will configure the clients that are going to connect to it. This can be done in 2 ways: through a QR code or through a .conf
file. Once connected to this VPN, we will be able to access services that we did not expose publicly with our Reverse Proxy such as Portainer and Cockpit, which are too critical to expose to attacks on the public internet. The stack consists of the following container:
- WireGuard: VPN for the local network.
Note
WireGuard will be configured with split tunneling. If you want to redirect all client traffic, then you must change the ALLOWEDIPS
variable in the stack in Portainer to 0.0.0.0/0
.
- Run:
./scripts/create_wireguard_folder.sh
to generate the container directory on the SSD. - Run:
./scripts/iptable_setup.sh
. Adds a kernel module at system startup required for WireGuard. - Edit the stack file:
nano ./files/private-traffic-stack.yml
. - Replace
TZ=America/New_York
with your system time zone. You can use this list as a reference: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. - Replace the XXX with the
uid
andgid
of the usermediacenter
. You can useid mediacenter
to get theuid
andgid
. - Replace
myhome
with the subdomain you registered on DuckDNS.org and set theALLOWEDIPS
variable in case192.168 .1.0/24
is not the CIDR range of your local network. Do not remove10.13.13.0
as it is the internal WireGuard network and you will lose connectivity if you remove it. If you assigned a different IP to your DNS (for example if you used Technitium), update thePEERDNS
variable with the right IP. Do not remove10.13.13.1
as it is the internal WireGuard DNS and it won't work. The guide assumes 2 clients that will connect to the VPN with the IDs:phone
andlaptop
. If you require more or fewer clients, add or remove or rename the client IDs as you wish. - Copy all contents of the file to the clipboard. Save and exit with
Ctrl + X, Y, Enter
. - Run:
./scripts/wireguard_firewalld_services.sh
. Configure Firewalld for WireGuard. The script opens the ports for WireGuard. - Add stack in Portainer from the browser.
- Access Portainer through https://192.168.1.253:9443. If you get a security alert, you can accept the risk since Portainer uses a self-signed SSL certificate.
- Click "Get Started" and then select "local."
- Select "Stacks" and create a new stack.
- Name it "private-traffic" and paste the content of the private-traffic-stack.yml that you copied to the clipboard and create the stack. From now on, modifications to the stack must be made through Portainer and not in the file.
- Configure the router. Each router is different, so you will have to consult your manual to be able to do the following step.
- Forward port 51820 in UDP to the server.
- If you want to configure with a QR code, do the following:
- Access Portainer on your local network from a device that is not the client you are configuring.
- Navigate to
local
>Containers
. - In the
wireguard
container row press theexec console
button. - Press
Connect
. - Show the QR code for the client
phone
in the console with:/app/show-peer phone
. - From the device that will be the
phone
client (your cell phone for example), open the WireGuard application and selectAdd tunnel
. - Choose
Scan QR code
and scan the code that was displayed on the console. - If you want to test that it works correctly, disconnect your device from the local network (turn off Wi-Fi for example) and enable the VPN. Try to access an IP on your local network.
- If you want to configure with a configuration file, do the following (Note: the guide assumes a Linux device that already has the
wireguard-tools
package or equivalent installed. For other OS, please read the WireGuard documentation):- Connect to the server from the device that will be the client with SSH:
ssh [email protected]
. - We show the configuration for the
laptop
client:sudo cat /Apps/wireguard/peer_laptop/peer_laptop.conf
. - Copy the contents of the file to the clipboard.
- Return to the client device console with
exit
or open a new console. - We create the configuration file for a virtual network with the name
wg0
:sudo nano /etc/wireguard/wg0.conf
. - Paste the contents of the clipboard. Save and exit with
Ctrl + X, Y, Enter
. - If you want to test that it works correctly, disconnect your device from the local network (connect to your guest Wi-Fi network or from the public network of a cafe or use your cell phone as a modem) and enable the virtual network
wg0
with :wg-quick up wg0
. Try to access an IP on your local network.
- Connect to the server from the device that will be the client with SSH: