Alpine Linux set up WireGuard VPN server

Alpine Linux set up WireGuard VPN server

To set up a WireGuard VPN server on Alpine Linux, follow these steps:

  1. Install WireGuard on your Alpine Linux system:

WireGuard can be installed on Alpine Linux using the package manager. Run the following command to install WireGuard:

apk add wireguard-tools
Source‮:‬www.lautturi.com
  1. Create a WireGuard configuration file:

The WireGuard configuration file defines the VPN tunnel and specifies the firewall rules for the VPN connection. You can create a configuration file using the wg command-line tool.

To create a configuration file, run the following command:

wg genkey | tee /etc/wireguard/privatekey | wg pubkey | tee /etc/wireguard/publickey

This will generate a private and a public key and store them in the /etc/wireguard directory.

  1. Edit the configuration file:

Next, you need to edit the WireGuard configuration file and specify the firewall rules for the VPN connection. The configuration file is typically stored in the /etc/wireguard directory and is named wg0.conf.

Open the configuration file in a text editor and add the following lines:

[Interface]
Address = 192.168.1.1/24
PrivateKey = <private key>
ListenPort = 51820

[Peer]
PublicKey = <public key>
AllowedIPs = 192.168.1.2/32

Replace the <private key> and <public key> placeholders with the private and public keys that you generated in step 2.

The Address parameter specifies the IP address of the VPN server, and the ListenPort parameter specifies the port number on which the VPN server will listen for incoming connections.

The [Peer] section defines the firewall rules for the VPN client. The PublicKey parameter specifies the public key of the VPN client, and the AllowedIPs parameter specifies the IP address range that the VPN client is allowed to access.

  1. Enable and start the WireGuard service:

To enable and start the WireGuard service, use the following commands:

rc-update add wireguard
/etc/init.d/wireguard start

This will start the WireGuard service and establish the VPN connection.

  1. Test the VPN connection:

To test the VPN connection, you can try pinging the VPN client from the VPN server or vice versa. For example, if the VPN client has the IP address 192.168.1.2, you can use the following command to ping it from the VPN server:

ping 192.168.1.2

If the VPN connection is working properly, you should see the ping reply from the VPN client.

WireGuard service on Linux

To enable and start the WireGuard service on a Linux system, you can use the following commands:

Enable the WireGuard service:
systemctl enable wg-quick@wg0

This will enable the WireGuard service to start automatically when the system boots. Replace wg0 with the name of your WireGuard interface.

Start the WireGuard service:
systemctl start wg-quick@wg0

This will start the WireGuard service. Replace wg0 with the name of your WireGuard interface.

You can also use the following command to check the status of the WireGuard service:

systemctl status wg-quick@wg0

This will display the status of the WireGuard service, including whether it is running or not.

Created Time:2017-10-27 14:56:33  Author:lautturi