gw-scripts is a collection of bash scripts that help you manage WireGuard using Docker.
466
gw-scripts is a collection of bash scripts designed to help you manage and configure WireGuard servers and peers using Docker. WireGuard is a fast, modern, and secure VPN tunnel that runs on Linux, Windows, macOS, Android, iOS, and more. Docker is a platform that allows you to run applications in isolated containers.
This project builds upon linuxserver/docker-wireguard, which provides a Docker image for WireGuard.
You can find the Docker image here and the source code on GitHub.
The following will run gw-scripts pulling from the image on docker hub.
$ docker run -d \
--name gw-scripts \
--cap-add NET_ADMIN \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=America/Chicago \
-e SERVERURL=myserver.example.com \
-e SERVER_MODE=true \
-e LOG_CONFS=false \
--restart unless-stopped \
tigsus/gw-scripts:1.0.20210914
gw-scripts provides the following scripts to help you set up and manage your WireGuard servers and peers:
wg_down.sh: This script brings down the wg server (all device interfaces).wg_up.sh: This script brings up the wg server (all device interfaces).wg_reload.sh: This script performs a hot reload of a single device interface that won't disrupt active sessions.wg_server_create.sh: This script creates a new server device interface.
/config/server_DEVINT.config/wg_confs/DEVINT.conf.wg_server_destroy.sh: This script deletes all references to a server by its device interface.
/config/server_DEVINT.config/wg_confs/DEVINT.conf.wg_server_status.sh: This script shows a status listing of all peers for a single device interface and includes these outputs:
Address, Endpoint, Last-Handshake, TransferRx and TransferTxwg-json found in wireguard-tools contribswg_peer_new.sh: This script creates a new peer (aka client) by DEVINT using a PEERID and optional USERID.
/config/server_DEVINT/peer_PEERID.config/wg_confs/DEVINT.conf.wg_peer_disable.sh: This script disables a peer by DEVINT and PEERID.
config/wg_confs/DEVINT.conf.disabled.conf under the peer folder.wg_peer_enable.sh: This script enables a disabled peer by DEVINT and PEERID.
disabled.conf under its folder.disabled.conf to the end of config/wg_confs/DEVINT.conf.disabled.conf.wg_peer_remove.sh: This script removes a peer (aka client) by DEVINT and PEERID or USERID.
/config/server_DEVINT/peer_PEERID.config/wg_confs/DEVINT.conf.wg_convert_from_linuxserver.sh: This script converts a linuxserver /config directory to the gw-scripts format.
config/wg_confs/DEVINT.conf.wg_unit_tests.sh: Used to verify scripts.To roll-your-own gw-scripts, you need to have Docker and Docker Compose installed on your system.
git clone https://github.com/tigsus/gw-scripts.git
cd gw-scripts
Update the Dockerfile with the desired version of linuxserver/wireguard. For custom-builds, replace our repo information tigsus/gw-scripts with your own.
docker build --build-arg BUILD_DATE="$(date +%Y%m%d)" --build-arg VERSION="1.0.20210914" -t tigsus/gw-scripts:1.0.20210914 .
Build the Docker container, then run the sample docker compose file.
docker compose up -d
docker compose logs -f
To use gw-scripts, you need to access the gw-scripts container and run the scripts from there. You can do this by using the following command:
docker exec -it gw-scripts bash
This will open a bash shell inside the gw-scripts container. Next, enter the gw-scripts folder, as follows:
cd /gw-scripts
From there, you can run the scripts as you wish.
For example, to create a new server device interface named wg0, you can run:
./wg_server_create.sh -D wg0
To create a new peer for the wg0 server with the peer ID 1, you can run:
./wg_peer_new.sh -D wg0 -p PEER1
To disable the peer with the ID PEER1 for the wg0 server, you can run:
./wg_peer_disable.sh -D wg0 -p PEER1
To enable the disabled peer with the ID PEER1 for the wg0 server, you can run:
./wg_peer_enable.sh -D wg0 -p PEER1
To remove the peer with the ID PEER1 for the wg0 server, you can run:
./wg_peer_remove.sh -D wg0 -p PEER1
To bring up the wireguard server, you can run:
./wg_up.sh
To bring down the entire wireguard server, you can run:
./wg_down.sh
To perform a hot reload of the wg0 server, you can run:
./wg_reload.sh -D wg0
To view the status of the wg0 server, including Address, Endpoint, Last-Handshake, TransferRx and TransferTx, you can run:
./wg_server_status.sh -D wg0
To delete the wg0 server and all its references, you can run:
./wg_server_destroy.sh -D wg0
To convert from a linuxserver file structure, in Docker mount the directory to convert from (eg /from-configs).
See the comment in docker-compose.yml for a mount example. It is best to run on a clean installation.
Then run the convertor script:
./wg_convert_from_linuxserver.sh -D wg0 -F "/from-configs"
To verify scripts, run the included unit-tester. If it errors, the script exits immediately, allowing one to inspect the current state for debugging purposes.
./wg_unit_tests.sh -D wg0
The jump from an existing installation of linuxserver/docker-wireguard to using gw-scripts is not immediate. There are breaking changes. Here are some of them:
wg0) are identified as device interfaces (DEVINT).wg_server_create.sh./config/server_DEVINT.
/config.SERVER_MODE=true to avoid USECOREDNS logic.
Note: This could be added back but in a way that plays nice with gw-scripts.
iptable rules in /defaults/server.conf.gw-scripts is an open source project and we welcome contributions from anyone who is interested. If you want to contribute to gw-scripts, please follow these steps:
Please make sure to follow the code style and conventions of the project, and to test your changes before submitting a pull request. You can also check the issues page to see if there are any open tasks that you can help with.
gw-scripts is licensed under the GPL Version 3.
Content type
Image
Digest
sha256:aeaf48de3…
Size
32.9 MB
Last updated
over 1 year ago
docker pull tigsus/gw-scripts:1.0.20210914-12