Creating an Internal Connection between DNS, WireGuard, and Traefik using Docker

Abstract: Resolve internal Docker container hostnames for WireGuard clients via Traefik and CoreDNS without leaking queries to public DNS.

Created: 2026-09-21 by

Creating an internal connection between DNS, WireGuard, and Traefik in Docker requires configuring a shared network for service discovery while routing external traffic through the encrypted WireGuard tunnel. By integrating CoreDNS or Pi-hole with Traefik’s dynamic configuration, you ensure that internal hostnames resolve correctly to container IPs within the secure overlay network.

Network Architecture Overview

The core challenge in this setup is ensuring that services inside the WireGuard network can resolve each other’s hostnames without leaking requests to public DNS servers. To achieve this, we must define a specific Docker network that acts as the bridge between the WireGuard interface and the application containers managed by Traefik. This architecture relies on three distinct layers: the physical or virtual network interface provided by WireGuard, the Docker internal network for service communication, and the Traefik reverse proxy layer for routing and TLS termination.

It is crucial to understand that WireGuard operates at Layer 3 (network layer), while Docker networks operate at Layer 2/3 depending on the driver. By attaching the WireGuard container to a custom bridge network, we allow it to act as a gateway or a peer within that subnet. Other containers, such as those running databases or web applications, attach to the same network. Traefik, acting as the edge router, listens on ports exposed to the WireGuard interface, allowing clients connected via the VPN to access services using internal domain names.

Configuring the WireGuard Container

The first step is to deploy the WireGuard container with the correct permissions and network settings. The container must have NET_ADMIN capabilities to manage the network interfaces. We will use the wireguard/wireguard image or a similar lightweight alternative. The configuration involves generating keys and defining the peer connections. In your docker-compose.yml, ensure the WireGuard service is attached to a custom network, for example, named secure-net.

version: '3.8'
services:
  wireguard:
    image: linuxserver/wireguard
    container_name: wireguard
    cap_add:
      - NET_ADMIN
      - SYS_MODULE
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
      - SERVERURL=vpn.yourdomain.com
      - SERVERPORT=51820
      - PEERS=2
      - PEERDNS=auto
      - INTERNAL_SUBNET=10.133.133.0
    volumes:
      - ./config:/config
    ports:
      - 51820:51820/udp
    networks:
      - secure-net
    restart: unless-stopped

networks:
  secure-net:
    driver: bridge

Note the PEERDNS=auto setting. This instructs the client to use the DNS server specified within the WireGuard configuration. However, for our internal Docker integration, we need to override this behavior so that queries for internal domains go to our local DNS resolver rather than Google or Cloudflare public DNS. This is where the next component comes into play.

Integrating Internal DNS Resolution

To handle internal name resolution, we deploy a lightweight DNS server like CoreDNS or dnsmasq within the same secure-net network. This DNS server will be responsible for resolving hostnames of other containers in the Docker environment. For instance, if you have a Nextcloud container named nextcloud, the DNS server must return its IP address when queried for nextcloud.secure-net or simply nextcloud depending on your search domain configuration.

You can configure CoreDNS to forward non-internal queries to upstream DNS providers while handling internal zones locally. Alternatively, you can use Docker’s built-in DNS resolver if all services are on the same network, but this often fails when cross-network communication is required or when strict isolation is needed. A dedicated DNS container offers more control over caching and forwarding rules.

Ensure that the WireGuard configuration points to this DNS container’s IP address. In the WireGuard server config file (/config/wg0.conf), set the DNS directive to the IP address of your DNS container within the secure-net network. This ensures that any device connecting to your VPN uses your internal DNS for lookups, preventing DNS leaks and enabling seamless access to internal services.

Configuring Traefik for Internal Access

Traefik serves as the entry point for all HTTP and HTTPS traffic coming from the WireGuard network. It needs to be aware of the services running behind it and route requests based on hostname. Configure Traefik to listen on the WireGuard interface. In your Traefik static configuration, specify the provider as Docker and enable the watch flag to detect new containers automatically.

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"
    exposedByDefault: false
    network: secure-net

By specifying the network parameter, Traefik only discovers containers attached to secure-net. This prevents accidental exposure of internal services to other networks. Each target container must have labels indicating how Traefik should route traffic. For example:

labels:
  - "traefik.http.routers.myapp.rule=Host(`myapp.local`)"
  - "traefik.http.services.myapp.loadbalancer.server.port=8080"

When a user connects via WireGuard and requests myapp.local, their DNS query resolves to the Traefik container’s IP. Traefik then routes the request to the appropriate backend service. This setup creates a fully functional internal ecosystem where security, routing, and resolution are tightly integrated.

Verifying Connectivity and Troubleshooting

After deploying all components, verify the connectivity by pinging the DNS server from a WireGuard client. Check the logs of the WireGuard container to ensure peers are connecting successfully. If DNS resolution fails, inspect the DNS container’s logs for errors and ensure that the WireGuard configuration’s DNS field matches the correct IP address. Additionally, check Traefik’s dashboard to confirm that routers and services are active and receiving traffic.

If you encounter issues with packet loss or latency, consider adjusting the MTU settings in both the WireGuard configuration and the Docker network. WireGuard typically requires an MTU of 1420 or lower to accommodate overhead. You can set this in the WireGuard config using MTU=1420. Furthermore, ensure that firewall rules on the host machine allow UDP traffic on port 51820 and TCP/UDP traffic for the services exposed by Traefik.

This architecture provides a robust foundation for private cloud services. It leverages Docker’s networking capabilities for service discovery, WireGuard for secure transport, and Traefik for flexible routing. By carefully aligning these components, you create a secure, self-hosted environment that behaves like a professional enterprise network.

Frequently Asked Questions

Can I use Traefik with multiple Docker networks?

Yes, Traefik can monitor multiple networks by listing them in the provider configuration. However, you must ensure that the routing rules do not conflict and that each network has distinct subnets to avoid IP collisions. This allows you to segment different types of services, such as separating development environments from production.

How do I prevent DNS leaks when using WireGuard?

To prevent DNS leaks, always configure the PEERDNS setting in your WireGuard client to point to your internal DNS resolver. Additionally, use a kill switch on your client device to block all internet traffic if the WireGuard tunnel drops, ensuring no unencrypted DNS queries escape the secure tunnel.

What happens if the DNS container goes down?

If the internal DNS container fails, clients connected via WireGuard will lose the ability to resolve internal hostnames. They may fall back to public DNS if configured to do so, which could expose traffic. It is recommended to run redundant DNS instances or use Docker’s built-in DNS as a fallback mechanism for critical services.

Is it possible to expose internal services to the public internet securely?

While this setup focuses on internal access, you can extend it by configuring Traefik to also listen on public interfaces with proper authentication and rate limiting. However, exposing internal services directly increases risk. A better approach is to use a separate public-facing Traefik instance that proxies requests through the internal network, maintaining strict separation of concerns.

How do I update certificates for Traefik in this setup?

Traefik supports automatic certificate management via Let's Encrypt. Configure the ACME resolver in your Traefik dynamic configuration to store certificates in a volume. When the DNS container is used for validation, ensure it supports the necessary DNS challenge records. This automates SSL/TLS renewal for all internal and external domains managed by Traefik.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More