A small program designed to run within the wg-easy container to automatically detect the correct network interface based on a configured IP prefix (TARGET_IP_PREFIX). This eliminates the need for manual configuration of the WG_DEVICE environment variable in wg-easy.
The wg-easy container requires the WG_DEVICE environment variable to be set to the correct network interface for routing WireGuard traffic. Manually identifying and configuring this interface can be cumbersome and prone to errors, especially in dynamic environments.
wg-iptables-manager automatically identifies the appropriate network interface by scanning interfaces and matching them against the IP prefix specified by the TARGET_IP_PREFIX environment variable. This allows wg-easy to function correctly without the user needing to manually determine and set WG_DEVICE.
- Automatic detection of the network interface based on
TARGET_IP_PREFIX. - Simplifies deployment of
wg-easyby removing the need for manualWG_DEVICEconfiguration. - Designed to run seamlessly within the
wg-easyDocker container environment.
- Docker (specifically for running the
wg-easycontainer). - The
wg-easyDocker image.
-
Build or obtain the
wg-iptables-managerexecutable. -
Mount the
wg-iptables-managerexecutable into yourwg-easycontainer. -
Set the
TARGET_IP_PREFIXenvironment variable for thewg-easycontainer to the desired IP prefix (e.g.,192.168.1.0/24). -
Utilize the
WG_POST_UPandWG_POST_DOWNenvironment variables provided bywg-easyto executewg-iptables-managerfor managing iptables rules.For more details on
WG_POST_UPandWG_POST_DOWN, refer to the wg-easy README.Example (using
docker-compose.yml):version: '3.8' services: wg-easy: image: ghcr.io/wg-easy/wg-easy container_name: wg-easy environment: - WG_HOST=YOUR_SERVER_IP_OR_HOSTNAME - PASSWORD_HASH=YOUR_ADMIN_PASSWORD_HASH # See wg-easy README for how to generate this - TARGET_IP_PREFIX=192.168.1. # Replace with your target IP prefix - WG_POST_UP=/path/to/wg-iptables-manager up - WG_POST_DOWN=/path/to/wg-iptables-manager down volumes: - .:/etc/wireguard:rw # Mount the wg-iptables-manager executable here ports: - 51820:51820/udp - 51821:51821/tcp # Admin UI cap_add: - NET_ADMIN - SYS_MODULE sysctls: net.ipv4.ip_forward: 1 net.ipv4.conf.all.src_valid_mark: 1
In this example:
- We mount the
wg-iptables-managerexecutable into the container. WG_POST_UPis set to runwg-iptables-manager upwhen the WireGuard interface comes up.WG_POST_DOWNis set to runwg-iptables-manager downwhen the WireGuard interface goes down.
Make sure to replace
YOUR_SERVER_IP_OR_HOSTNAME,YOUR_ADMIN_PASSWORD_HASH, and192.168.1.0/24with your actual values. Adjust the volume mount (.:/etc/wireguard:rw) based on where yourwg-iptables-managerexecutable is located on your host machine and where you want to mount it in the container. - We mount the
The primary configuration is done via the TARGET_IP_PREFIX environment variable.
| Env | Description |
|---|---|
TARGET_IP_PREFIX |
The IP prefix used to identify the correct network interface (e.g., 192.168.1.). |
Contributions are welcome! Please see the issue tracker for ways to contribute or open a pull request.
This project is dual-licensed under the Apache License, Version 2.0 and the MIT License. See the LICENSE-APACHE-2.0 and LICENSE-MIT files for details.