---
title: 'Virtual Private Networking'
url: 'https://niklas-stephan.de/en/wiki/self-hosted/virtual-private-networking'
markdown: 'https://niklas-stephan.de/en/wiki/self-hosted/virtual-private-networking.md'
lang: en
date: '2026-03-14'
description: 'Virtual Private Networking The VPN is not to be confused with a DMZ: resources that we want to provide publicly on the internet belong in this DMZ, which is provided in combination of the Traefik reverse proxy and a further Docker network. Here we build the following: A Wireguard network for the e…'
---

#  Virtual Private Networking 

The VPN is not to be confused with a DMZ: resources that we want to provide publicly on the internet belong in this DMZ, which is provided in combination of the Traefik reverse proxy and a further Docker network.

Here we build the following:

- A Wireguard network for the encrypted communication of our own resources – VPS, home server, and further clients.
- A Wireguard network for the encrypted communication between our VPS and the internet.

Both networks run virtualized, independently, and separately from each other.

![](https://niklas-stephan.de/user/pages/wiki/02.self-hosted/virtual-private-networking/diagram.svg)

## Server setup

On our VPS we create an own internal VPN network with Wireguard, in which the VPS is treated as server and the home server as well as other devices as clients.

Additionally we build another VPN via a different way, in which it is about that the VPS optionally itself can build up an as anonymous as possible connection to further resources from the internet.

### Internal network

To provide a Wireguard VPN we use "[wg-easy](https://wg-easy.github.io/wg-easy/latest/)", a tool that, operated as a Docker container, delivers not only a Wireguard server as such, but also a web UI for it and simplifies the configuration.

The `compose.yml` for that can e.g. look like this:

```yaml
<span class="hljs-attr">services:</span>
    <span class="hljs-attr">wg-easy:</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">ghcr.io/wg-easy/wg-easy:15</span>
        <span class="hljs-attr">container_name:</span> <span class="hljs-string">wg-easy</span>
        <span class="hljs-attr">environment:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">WG_HOST=PUBLIC-IPv4-ADDRESS-OF-THE-SERVER</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">WG_PORT=51820</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">WG_DEFAULT_ADDRESS=10.8.0.x</span> <span class="hljs-comment"># or another address range</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">WG_DEFAULT_DNS=</span> <span class="hljs-comment"># yes, deliberately empty, so that the DNS config of the clients is not overwritten</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">WG_ALLOWED_IPS=10.42.42.0/24,fdcc:ad94:bacf:61a3::/64</span> <span class="hljs-comment"># additional security factor</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">INSECURE=false</span>
        <span class="hljs-attr">networks:</span>
            <span class="hljs-attr">wg:</span>
                <span class="hljs-attr">ipv4_address:</span> <span class="hljs-number">10.42</span><span class="hljs-number">.42</span><span class="hljs-number">.42</span>
                <span class="hljs-attr">ipv6_address:</span> <span class="hljs-string">fdcc:ad94:bacf:61a3::2a</span>
        <span class="hljs-attr">volumes:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">./config:/etc/wireguard</span> <span class="hljs-comment"># for the config</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">/lib/modules:/lib/modules:ro</span> <span class="hljs-comment"># for hardware-accelerated Wireguard encryption</span>
        <span class="hljs-attr">ports:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">"51820:51820/udp"</span>  <span class="hljs-comment"># Do not forget the release in the firewall!</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">"51821:51821/tcp"</span>  <span class="hljs-comment"># Do not forget the release in the firewall!</span>
        <span class="hljs-attr">restart:</span> <span class="hljs-string">unless-stopped</span>
        <span class="hljs-attr">cap_add:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">NET_ADMIN</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">SYS_MODULE</span>
        <span class="hljs-attr">sysctls:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">net.ipv4.ip_forward=1</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">net.ipv4.conf.all.src_valid_mark=1</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">net.ipv6.conf.all.disable_ipv6=0</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">net.ipv6.conf.all.forwarding=1</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">net.ipv6.conf.default.forwarding=1</span>
<span class="hljs-attr">networks:</span>
    <span class="hljs-attr">wg:</span>
        <span class="hljs-attr">driver:</span> <span class="hljs-string">bridge</span>
        <span class="hljs-attr">enable_ipv6:</span> <span class="hljs-literal">true</span>
        <span class="hljs-attr">ipam:</span>
            <span class="hljs-attr">driver:</span> <span class="hljs-string">default</span>
            <span class="hljs-attr">config:</span>
                <span class="hljs-bullet">-</span> <span class="hljs-attr">subnet:</span> <span class="hljs-number">10.42</span><span class="hljs-number">.42</span><span class="hljs-number">.0</span><span class="hljs-string">/24</span>
                <span class="hljs-bullet">-</span> <span class="hljs-attr">subnet:</span> <span class="hljs-string">fdcc:ad94:bacf:61a3::/64</span>
```

So that the clients can later connect too, we release the Wireguard port `51820` for UDP and the port `51821` for TCP in the firewall of our VPS.

## Home server setup

On the home server we set up the Wireguard client in the form of a Docker container.

`compose.yml`:

```yaml
<span class="hljs-attr">services:</span>
    <span class="hljs-attr">wireguard:</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">lscr.io/linuxserver/wireguard:latest</span>
        <span class="hljs-attr">container_name:</span> <span class="hljs-string">wireguard</span>
        <span class="hljs-attr">cap_add:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">NET_ADMIN</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">SYS_MODULE</span>
        <span class="hljs-attr">environment:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">PUID=1000</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">PGID=1000</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">TZ=Europe/Berlin</span>
        <span class="hljs-attr">volumes:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">./config:/config</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">/lib/modules:/lib/modules:ro</span>
        <span class="hljs-attr">network_mode:</span> <span class="hljs-string">host</span>
        <span class="hljs-attr">restart:</span> <span class="hljs-string">unless-stopped</span>
```

## Further clients

### Linux

For Debian-based distributions:

`client.conf`:

```ini
<span class="hljs-section">[Interface]</span>
<span class="hljs-attr">PrivateKey</span> = PRIVATE_KEY
<span class="hljs-attr">Address</span> = <span class="hljs-number">10.8</span>.<span class="hljs-number">0</span>.X/<span class="hljs-number">24</span>
<span class="hljs-attr">MTU</span> = <span class="hljs-number">1420</span>
<span class="hljs-attr">DNS</span> =

<span class="hljs-section">[Peer]</span>
<span class="hljs-attr">PublicKey</span> = PUBLIC_KEY
<span class="hljs-attr">PresharedKey</span> = PRESHARED_KEY
<span class="hljs-attr">AllowedIPs</span> = <span class="hljs-number">10.42</span>.<span class="hljs-number">42.0</span>/<span class="hljs-number">24</span>,<span class="hljs-number">10.8</span>.<span class="hljs-number">0.0</span>/<span class="hljs-number">24</span>,fdcc:ad94:bacf:<span class="hljs-number">61</span>a3::/<span class="hljs-number">64</span>
<span class="hljs-attr">PersistentKeepalive</span> = <span class="hljs-number">30</span>
<span class="hljs-attr">Endpoint</span> = VPS_PUBLIC_IPv4:<span class="hljs-number">51820</span>
```

## Sources and links

- Wireguard server "wg-easy"
- Wireguard Docker client from linuxserver.io

 self-hostedvpnprivacynetwork

---

## Navigation

- Parent: [Self-hosted](https://niklas-stephan.de/en/wiki/self-hosted.md)
- Previous: [Stalwart](https://niklas-stephan.de/en/wiki/self-hosted/stalwart.md)
- Next: [VS Code Server](https://niklas-stephan.de/en/wiki/self-hosted/vs-code-server.md)
