DEV Community

Mateusz (6vz)
Mateusz (6vz)

Posted on • Updated on

How to set up Wireguard on VPS (using Docker)

Introduction

You can very easily set up a Wireguard server, using docker (for docker-compose accuracy) on your Linux server. This option may also work on Windows, however I am not testing it

Requirements

  1. Linux Server (with root access)
  2. Ability to open ports
  3. docker & docker-compose installed

Before you start...

Please open ports 51820 (UDP), otherwise it won't work

Installation process

  • Enter these two commands, they will create required directories
mkdir -p ~/wireguard/
mkdir -p ~/wireguard/config/
Enter fullscreen mode Exit fullscreen mode
  • Run nano ~/wireguard/docker-compose.yml and paste below-mentioned content into the docker-compose.yml file
version: '3.8'
services:
  wireguard:
    container_name: wireguard
    image: linuxserver/wireguard
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Warsaw
      - SERVERURL=00.00.00.00
      - SERVERPORT=51820
      - PEERS=10
      - PEERDNS=auto
      - INTERNAL_SUBNET=10.0.0.0
    ports:
      - 51820:51820/udp
    volumes:
      - type: bind
        source: ./config/
        target: /config/
      - type: bind
        source: /lib/modules
        target: /lib/modules
    restart: always
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    sysctls:
      - net.ipv4.conf.all.src_valid_mark=1
Enter fullscreen mode Exit fullscreen mode

Fill this config:

  • TZ is a Timezone - Get yours from TZ Database in Wikipedia
  • SERVERURL is your server IP
  • PEERS are basically configs, if you want 10 configs, just type 10, and peers will generate automaticly

Hit CTRL + X and then Y then ENTER to save the file

To run Wireguard enter these two commands:
cd ~/wireguard/
docker-compose up -d

  • Enter docker-compose logs -f wireguard - There should be QR codes, with connection profiles
  • Or go to ~/wireguard/config/ to see .conf files for every peer.

Enjoy your fresh & private VPN

Top comments (0)