Installing PiVPN on Alpine Linux Latest

PiVPN is a tool used to create a Private Virtual Network (VPN) on a Raspberry Pi, which allows you to access your network remotely or secure your internet traffic.

In this tutorial, you will learn how to install PiVPN on Alpine Linux Latest.

Prerequisites

Before you begin, ensure that you have the following:

Step 1: Install PiVPN

To install PiVPN, run the commands below in the terminal or shell:

curl -L https://install.pivpn.io | bash

During the installation process, you will be prompted to configure the PiVPN settings such as the client settings, OpenVPN ports, and other settings as required.

Follow the prompts to complete the installation process.

Step 2: Enable IP forwarding

IP forwarding must be enabled on your Raspberry Pi to route traffic from your VPN clients. To enable IP forwarding, follow the steps below:

  1. Navigate to the /etc/sysctl.d/ directory by running the command.
cd /etc/sysctl.d/
  1. Create a new file named 99-sysctl.conf and insert the following line.
sudo nano 99-sysctl.conf
net.ipv4.ip_forward=1

Save the file and exit.

  1. Apply the new settings by running the command below.
sudo sysctl -p /etc/sysctl.d/99-sysctl.conf

Step 3: Configure the Firewall

To allow traffic from VPN clients to pass through the firewall, you need to modify the rules to allow OpenVPN traffic.

  1. Open the ufw configuration file.
sudo nano /etc/ufw/before.rules
  1. Insert the following lines to allow traffic to the OpenVPN port on your Raspberry Pi.
# Allow traffic from OpenVPN clients
-A ufw-before-input -p udp -m udp --dport 1194 -j ACCEPT
-A ufw-before-input -p tcp -m tcp --dport 1194 -j ACCEPT
  1. Close and save the file.

  2. Reload the firewall.

sudo ufw reload

Step 4: Generate a client configuration file

Next, you need to generate a client configuration file for the OpenVPN client to establish a connection to the PiVPN server.

  1. Run the command below to generate a client configuration file.
sudo pivpn add
  1. Follow the prompts to create a new client and configure its settings.

  2. Save and exit when done.

The configuration file for the newly created client will be stored in the /home/pi/ovpns/ directory.

Step 5: Connect to the VPN

To connect to the VPN, follow the steps below:

  1. Install the OpenVPN client on your local computer.

  2. Copy the client configuration file (*.ovpn) to your local computer.

  3. Open the OpenVPN client application and choose Import Profile.

  4. Select the client configuration file (*.ovpn) and click Open.

  5. Enter your login credentials in the fields provided and click Connect.

You will be connected to the VPN and can access your local network or browse the internet securely.

Congratulations! You have successfully installed PiVPN on Alpine Linux Latest and created a VPN server on your Raspberry Pi.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!