Setting up a WireGuard VPN Server with Docker
In this article, we will explain how to set up a WireGuard VPN server using a Docker container. This will allow you to securely connect to your home network from anywhere in the world. We will also cover how to manage clients and their access to the local network.
Prerequisites
Before we begin, you will need the following:
- A Linux-based operating system (e.g. Ubuntu)
- Docker installed
- A basic understanding of networking and the command line
Setting up the WireGuard VPN Server
The first step is to create a new Docker container for the WireGuard VPN server. We will use the linuxserver/wireguard image, which is based on Alpine Linux and includes the WireGuard package.
docker run -d --name wg-server -p 51820:51820/udp linuxserver/wireguard
This will start the container and expose port 51820 for WireGuard connections. You can check the status of the container with the following command:
docker ps
Generating WireGuard Keys
Next, we need to generate the keys for the WireGuard server and clients. We will use the official WireGuard quickstart guide to generate these keys.
# On the server
wg genkey | tee privatekey | wg pubkey > publickey
# On each client
wg genkey | tee privatekey | wg pubkey > publickey
Configuring the WireGuard Server
Now that we have the keys for the server and clients, we can configure the WireGuard server. We will use the following configuration file as an example:
[Interface]
Address = 10.0.0.1/24
PrivateKey =
ListenPort = 51820
[Peer]
PublicKey =
AllowedIPs = 10.0.0.2/32
In this configuration, the server has an IP address of 10.0.0.1/24 and the client has an IP address of 10.0.0.2/32. The server's private key is
To apply this configuration, we will use the following command:
docker exec -it wg-server wg-quick up wg0
Configuring WireGuard Clients
Now that the server is configured, we can configure the WireGuard clients. We will use the following configuration file as an example:
[Interface]
Address = 10.0.0.2/32
PrivateKey =
[Peer]
PublicKey =
Endpoint = :51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
In this configuration, the client has an IP address of 10.0.0.2/32 and the server has an IP address of
To apply this configuration, we will use the following command:
wg-quick up wg0
Managing WireGuard Clients
Once the clients are connected, you can manage their access to the local network using firewall rules. For example, you can allow the clients to access specific subnets or deny access to certain services.
In this article, we have explained how to set up a WireGuard VPN server using a Docker container and manage clients and their access to the local network. With this setup, you can securely connect to your home network from anywhere in the world.