All Projects → apognu → wgctl

apognu / wgctl

Licence: MIT license
Utility to configure and manage your WireGuard tunnels

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to wgctl

wireguard config maker
Simple Java program to create wireguard client config files
Stars: ✭ 51 (-13.56%)
Mutual labels:  vpn, wireguard
split-vpn
A split tunnel VPN script for Unifi OS routers (UDM, UXG, UDR) with policy based routing.
Stars: ✭ 589 (+898.31%)
Mutual labels:  vpn, wireguard
Subspace
A simple WireGuard VPN server GUI
Stars: ✭ 2,109 (+3474.58%)
Mutual labels:  vpn, wireguard
wgrest
WireGuard REST API
Stars: ✭ 92 (+55.93%)
Mutual labels:  vpn, wireguard
Wireguard-DNScrypt-VPN-Server
Fast setup wireguard server script, with dnscrypt and adblocking, maleware blocking, more blocking if you need. Use case eg. always on vpn and adblocking on ios or android, and be more secured in unknown networks.
Stars: ✭ 48 (-18.64%)
Mutual labels:  vpn, wireguard
Mullvadvpn App
The Mullvad VPN client app for desktop and mobile
Stars: ✭ 1,953 (+3210.17%)
Mutual labels:  vpn, wireguard
wireguard-tools
Wireguard helper scripts
Stars: ✭ 147 (+149.15%)
Mutual labels:  vpn, wireguard
Algo
Set up a personal VPN in the cloud
Stars: ✭ 24,275 (+41044.07%)
Mutual labels:  vpn, wireguard
PromGuard
Prometheus scraping over WireGuard: Example Terraform/Ansible for fully authenticated/encrypted stat scraping
Stars: ✭ 24 (-59.32%)
Mutual labels:  vpn, wireguard
wg-portal
WireGuard Configuration Portal with LDAP connection
Stars: ✭ 476 (+706.78%)
Mutual labels:  vpn, wireguard
Softethervpn
Cross-platform multi-protocol VPN software. Pull requests are welcome. The stable version is available at https://github.com/SoftEtherVPN/SoftEtherVPN_Stable.
Stars: ✭ 8,531 (+14359.32%)
Mutual labels:  vpn, wireguard
desktop-app-ui
Official IVPN Desktop app (legacy version)
Stars: ✭ 23 (-61.02%)
Mutual labels:  vpn, wireguard
W3 Goto World
🍅 Git/AWS/Google 镜像 ,SS/SSR/VMESS节点,WireGuard,IPFS, DeepWeb,Capitalism 、行业研究报告的知识储备库
Stars: ✭ 7,886 (+13266.1%)
Mutual labels:  vpn, wireguard
Wireguard Install
WireGuard VPN installer for Linux servers
Stars: ✭ 2,575 (+4264.41%)
Mutual labels:  vpn, wireguard
Streisand
Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.
Stars: ✭ 22,605 (+38213.56%)
Mutual labels:  vpn, wireguard
wireguard-kmod
WireGuard for UDM series routers
Stars: ✭ 328 (+455.93%)
Mutual labels:  vpn, wireguard
Freepac
科学上网/翻墙梯子/自由上网/SS/SSR/V2Ray/Brook 搭建教程 免费机场、VPN工具
Stars: ✭ 4,515 (+7552.54%)
Mutual labels:  vpn, wireguard
Tailscale
The easiest, most secure way to use WireGuard and 2FA.
Stars: ✭ 6,157 (+10335.59%)
Mutual labels:  vpn, wireguard
WGDashboard
Simplest dashboard for WireGuard VPN written in Python w/ Flask
Stars: ✭ 772 (+1208.47%)
Mutual labels:  vpn, wireguard
wireguard exporter
Command wireguard_exporter implements a Prometheus exporter for WireGuard devices. MIT Licensed.
Stars: ✭ 94 (+59.32%)
Mutual labels:  vpn, wireguard

wgctl - WireGuard control utility

CI Status Coverage Status

This is a personal project to allow WireGuard to be configured through the use of YAML files. It uses Netlink (through wgctrl) under the hood for all interaction with the system.

This tool is very opinionated and designed for my own use (working on that), it might not be what you're looking for.

The configuration file should look like this (if you are using <= 1.0.0, please see this README):

description: Personal VPN server #1
private_key: /etc/wireguard/vpn1.key
peers:
  - description: Local laptop
    address: 192.168.0.1/32
    listen_port: 42000
    public_key: BooRta+d0t/2djkdZ3xfe/5xndKvPtfqH3pdZcdZ2TY=
    preshared_key: e16f1596201850fd4a63680b27f603cb64e67176159be3d8ed78a4403fdb1700
    fwmark: 1024
    routes: false
    post_up:
      - [ '/usr/bin/notify-send', 'WireGuard tunnel went up', 'A WireGuard tunnel was just brought up. Congrats.' ]
    pre_down:
      - [ '/usr/bin/notify-send', 'WireGuard tunnel went down', 'A WireGuard tunnel was just torn down. Congrats.' ]
  - description: VPN gateway at provider X
    address: 192.168.0.2/32
    listen_port: 42000
    public_key: cyfBMbaJ6kgnDYjio6xqWikvTz2HvpmvSQocRmF/ZD4=
    preshared_key: e16f1596201850fd4a63680b27f603cb64e67176159be3d8ed78a4403fdb1700
    endpoint: 1.2.3.4:42000
    keepalive_interval: 10s
    allowed_ips:
      - 192.168.0.0/30
      - 0.0.0.0/0

By default, wgctl will look for its configuration files under /etc/wireguard (as /etc/wireguard/<id>.yml). This can be overriden by giving it a filesystem path instead of an identifier. You can alsow set the directory where wgctl looks for its configuration by settings the environment variable WGCTL_CONFIG_PATH.

The post_up and pre_down directives take an array of arrays of commands to execute during the tunnel lifecycle events. You must use an absolute path to target the command you want to invoke.

Keep in mind that in order to put IPv6 addresses in the configuration, you'll need to coerce the value to a string with quotes :

peers:
  - endpoint: '[cafe:1:2:3::1]:10000'

The configuration is built so as to be able to be copied on all peers identically, the current node is detected when a peer public key matches the private key at the root of the file.

Build

$ go get -u github.com/apognu/wgctl

or

$ git clone https://github.com/apognu/wgctl.git && cd wgctl
$ dep ensure
$ go build .

You can, of course, get a prebuilt binary from the Releases section.

Testing

You can run the tests for this project, as root (since we are testing netlink communication and device creation). Keep in mind that this will modify properties on your live system (devices, routes, /proc settings, etc.), so use with caution.

$ sudo -E go test ./... 

Usage

$ wgctl help
usage: wgctl [<flags>] <command> [<args> ...]

WireGuard control plane helper

Flags:
  -h, --help  Show context-sensitive help (also try --help-long and --help-man).

Commands:
  help [<command>...]
  start [<flags>] <instance>
  stop <instance>
  restart [<flags>] <instance>
  status [<flags>] [<instance>]
  info <instance>
  set <instance> [<settings>...]
  peer
    set <instance> <peer>...
    replace <instance> <peer>...
  key
    private
    public
    psk
  version

Control the state of tunnels

$ wgctl start -f vpn
$ wgctl start vpn
$ wgctl stop vpn
$ wgctl restart vpn

Obtain the state of all configured or active tunnels

The -s option only displays the name of active tunnels, for ease of use in scripts.

$ wgctl status
[↓] tunnel 'vpn1' is down
[↑] tunnel 'vpn2' is up and running
[↓] tunnel 'corporate' is down
[↓] tunnel 'personal' is up and running

$ wgctl status -s
vpn2
personal

$ wgctl status vpn1
[↓] tunnel 'vpn1' is down

Get configuration and runtime details for an active tunnel

$ wgctl info vpn2
tunnel: 
  interface: Personal VPN tunnel #2
  public key: SqtWXnIGoHWibfqZwAe6iFc560wWuV6zUL+4CqzDxlQ=
  port: 51822
  fwmark: 12548
  peer: VPN gateway
    public key: /7vJFkiTPPTznPvey4Z4+xn+HRGlT/X3hv1o4+kS7FQ=
    endpoint: 4.3.2.1:10000
    allowed ips: 192.168.0.1/30, 0.0.0.0/0
    transfer: ↓ 0 ↑ 0

Change tunnel configuration on the fly

Those changes are not persisted, if you want to export the current configuration of a tunnel, use export below. Please note that you can provide a subset of the options shown below.

# Change properties on the interface itself
$ wgctl set vpn1 privkey=/etc/wireguard/new.key port=43210 fwmark=1437

# Add a new peer or change the properties of the peer with the given public key
$ wgctl peer set vpn1 pubkey=sSg9kL+KsMBQpFPO+TXl7A4OKjLb0xWORx7eR3JDjXM= endpoint=192.168.255.254:10000 allowedips=2.2.2.2/24,3.3.3.3/30 keepalive=20 psk=636493c476092bf06806794d6c2d62c990c68a39b71b73019a328a4d646d9e42

# Replace the whole set of peers with the given one
$ wgctl peer replace vpn1 pubkey=sSg9kL+KsMBQpFPO+TXl7A4OKjLb0xWORx7eR3JDjXM= endpoint=192.168.255.254:10000 allowedips=2.2.2.2/24,3.3.3.3/30 keepalive=20 psk=636493c476092bf06806794d6c2d62c990c68a39b71b73019a328a4d646d9e42

Export the configuration of a tunnel

You can export the current configuration of an active tunnel by using the wgctl export command. If a wgctl configuration already exists, non-WireGuard properties (descriptions, hooks, etc.) will be merged with the running config. If not, the default values will be used.

Please note that if the tunnel was not created through wgctl, the private key path will be left blank.

$ wgctl export vpn1
interface:
  description: Personal VPN server #1
  address: 192.168.0.1/32
  listen_port: 42000
  private_key: /path/to/private.key
  routes: false
  post_up:
    - [ '/usr/bin/notify-send', 'WireGuard tunnel went up', 'A WireGuard tunnel was just brought up. Congrats.' ]
  pre_down:
    - [ '/usr/bin/notify-send', 'WireGuard tunnel went down', 'A WireGuard tunnel was just torn down. Congrats.' ]
peers:
  - description: VPN gateway at provider X
    public_key: cyfBMbaJ6kgnDYjio6xqWikvTz2HvpmvSQocRmF/ZD4=
    preshared_key: e16f1596201850fd4a63680b27f603cb64e67176159be3d8ed78a4403fdb1700
    endpoint: 1.2.3.4:42000
    keepalive_interval: 10s
    allowed_ips:
      - 192.168.0.0/30
      - 0.0.0.0/0

Generate keys to be used by WireGuard

$ wgctl key private
nAyxQotWfano6/cC9S6fjSRYe9oQ0/GQn2mK9/PXvyg=
$ wgctl key private | wgctl key public
OtvPEAa2d3PP0qAT9bm7zxdTLa6i6w2wNrCdziI76Hg=
$ wgctl key psk
d9c966f0cf2320d4e67d543e0a0cd3856fc0f065392799fff8e040bed51b3176

Routes and firewall

By default, wgctl will add routes matching your allowed IP addresses in order to traffic to be routed through your VPN. Similarly to wg-quick, il will set up any default routes to route all your traffic (with the fwmark technique).

If you want to manage the routing yourself, you can pass --no-routes to wgctl start and wgctl restart to prevent that behavior. You can also set the interface directive routes to false to disable this behavior permanently.

wgctl will not touch your firewall rules, if you need to open a port or add specific rules, you'll need to do it yourself manually, or use a post_up directive.

Use as a service

You can tell wgctl to stay in the foreground by starting your tunnel with the -f flag. This allows you to start up your tunnels as daemons with, for example, this systemd service unit:

$ cat /etc/systemd/system/[email protected]
[Unit]
Description=Wireguard tunnel

[Service]
Type=simple
Restart=always
WorkingDirectory=/etc/wireguard
ExecStart=/usr/local/bin/wgctl start -f %i
ExecStopPost=-/usr/local/bin/wgctl stop %i

[Install]
WantedBy=multi-user.target
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].