DEV Community

Mateusz (6vz)
Mateusz (6vz)

Posted on • Edited on

4 2

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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay