Connecting a Local Network VPN on Windows and RPI (WireGuard, Nginx)
In this article, we will discuss the process of setting up a Virtual Private Network (VPN) on a local network consisting of a Windows machine and a Raspberry Pi (RPI), using WireGuard and Nginx. This setup will allow you to securely connect to your local network from an outside network, enabling you to SSH into your local machines without any issues.
Prerequisites
- A local network with a Windows machine and a Raspberry Pi
- WireGuard installed on both the Windows machine and the Raspberry Pi
- Nginx installed on the Raspberry Pi
Setting up WireGuard on Windows
To set up WireGuard on your Windows machine, follow these steps:
- Download and install the latest version of WireGuard for Windows from the official website.
- Create a new WireGuard interface by clicking on the "+" button in the WireGuard window.
- Enter a name for the interface and click "Generate" to create a new private key.
- Add the IP address and endpoint for the Raspberry Pi's WireGuard interface.
- Add the private key for the Raspberry Pi's WireGuard interface.
- Save the changes and start the WireGuard interface.
Setting up WireGuard on Raspberry Pi
To set up WireGuard on your Raspberry Pi, follow these steps:
- Install WireGuard on your Raspberry Pi by running the following command:
sudo apt-get install wireguard- Create a new WireGuard interface by running the following command:
sudo nano /etc/wireguard/wg0.conf- Enter the following configuration for the interface:
[Interface]
PrivateKey = [Raspberry Pi's Private Key]
Address = [Raspberry Pi's IP Address]
[Peer]
PublicKey = [Windows Machine's Public Key]
Endpoint = [Windows Machine's IP Address]:[WireGuard Port]
AllowedIPs = 0.0.0.0/0- Save and close the file.
- Start the WireGuard interface by running the following command:
sudo wg-quick up wg0Setting up Nginx on Raspberry Pi
To set up Nginx on your Raspberry Pi, follow these steps:
- Install Nginx on your Raspberry Pi by running the following command:
sudo apt-get install nginx- Create a new Nginx configuration file by running the following command:
sudo nano /etc/nginx/sites-available/vpn- Enter the following configuration for the Nginx server:
server {
listen 443 ssl;
server\_name [Raspberry Pi's IP Address];
ssl\_certificate /etc/nginx/ssl/cert.pem;
ssl\_certificate\_key /etc/nginx/ssl/key.pem;
location / {
proxy\_pass http://[Raspberry Pi's IP Address]:[WireGuard Port];
proxy\_set\_header Host $host;
proxy\_set\_header X-Real-IP $remote\_addr;
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;
proxy\_set\_header X-Forwarded-Proto $scheme;
}
}- Save and close the file.
- Create a symbolic link to the Nginx configuration file by running the following command:
sudo ln -s /etc/nginx/sites-available/vpn /etc/nginx/sites-enabled/- Restart the Nginx service by running the following command:
sudo systemctl restart nginxConnecting to the VPN
To connect to the VPN from an outside network, follow these steps:
- Connect to the VPN by running the following command on your Windows machine:
wg-quick up wg0- Connect to the Nginx server by opening a web browser and navigating to https://[Raspberry Pi's IP Address].
- SSH into your local machines using the IP addresses assigned to them on the local network.
In this article, we have discussed the process of setting up a VPN on a local network consisting of a Windows machine and a Raspberry Pi, using WireGuard and Nginx. This setup allows you to securely connect to your local network from an outside network, enabling you to SSH into your local machines without any issues. We have covered the prerequisites, the steps to set up WireGuard on both the Windows machine and the Raspberry Pi, the steps to set up Nginx on the Raspberry Pi, and the steps to connect to the VPN from an outside network.
References
- WireGuard: https://www.wireguard.com/
- Nginx: https://nginx.org/