-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced new config format where the local node is listed as a norm…
…al peer to allow for copying the same file to different machines.
- Loading branch information
Showing
11 changed files
with
186 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,20 +9,24 @@ This tool is very opinionated and designed for my own use (working on that), it | |
|
||
The configuration file (which is subject to breaking changes until 1.0) should look like this: | ||
|
||
``` | ||
interface: | ||
description: Personal VPN server #1 | ||
address: 192.168.0.1/32 | ||
listen_port: 42000 | ||
private_key: /etc/wireguard/vpn1.key | ||
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.' ] | ||
```yaml | ||
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 | ||
|
@@ -38,37 +42,41 @@ The ```post_up``` and ```pre_down``` directives take an array of arrays of comma | |
|
||
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 : | ||
|
||
``` | ||
```yaml | ||
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 | ||
|
||
``` | ||
```shell | ||
$ go get -u github.com/apognu/wgctl | ||
``` | ||
|
||
or | ||
|
||
``` | ||
```shell | ||
$ 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](https://github.com/apognu/wgctl/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. | ||
|
||
``` | ||
```shell | ||
$ sudo -E go test ./... | ||
``` | ||
|
||
## Usage | ||
|
||
``` | ||
# wgctl help | ||
```shell | ||
$ wgctl help | ||
usage: wgctl [<flags>] <command> [<args> ...] | ||
WireGuard control plane helper | ||
|
@@ -96,36 +104,36 @@ Commands: | |
|
||
### Control the state of tunnels | ||
|
||
``` | ||
# wgctl start vpn | ||
# wgctl start -f vpn | ||
# wgctl stop vpn | ||
# wgctl restart vpn | ||
```shell | ||
$ 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 | ||
$ 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 | ||
$ wgctl status -s | ||
vpn2 | ||
personal | ||
|
||
# wgctl status vpn1 | ||
$ wgctl status vpn1 | ||
[↓] tunnel 'vpn1' is down | ||
``` | ||
### Get configuration and runtime details for an active tunnel | ||
``` | ||
# wgctl info vpn2 | ||
```shell | ||
$ wgctl info vpn2 | ||
tunnel: | ||
interface: Personal VPN tunnel #2 | ||
public key: SqtWXnIGoHWibfqZwAe6iFc560wWuV6zUL+4CqzDxlQ= | ||
|
@@ -142,15 +150,15 @@ tunnel: | |
|
||
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. | ||
|
||
``` | ||
```shell | ||
# Change properties on the interface itself | ||
# wgctl set vpn1 privkey=/etc/wireguard/new.key port=43210 fwmark=1437 | ||
$ 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 | ||
$ 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 | ||
$ 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 | ||
|
@@ -159,8 +167,8 @@ You can export the current configuration of an active tunnel by using the ```wgc | |
|
||
Please note that if the tunnel was not created through ```wgctl```, the private key path will be left blank. | ||
|
||
``` | ||
# wgctl export vpn1 | ||
```shell | ||
$ wgctl export vpn1 | ||
interface: | ||
description: Personal VPN server #1 | ||
address: 192.168.0.1/32 | ||
|
@@ -184,7 +192,7 @@ peers: | |
|
||
### Generate keys to be used by WireGuard | ||
|
||
``` | ||
```shell | ||
$ wgctl key private | ||
nAyxQotWfano6/cC9S6fjSRYe9oQ0/GQn2mK9/PXvyg= | ||
$ wgctl key private | wgctl key public | ||
|
@@ -200,3 +208,23 @@ By default, ```wgctl``` will add routes matching your allowed IP addresses in or | |
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: | ||
|
||
```shell | ||
$ 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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.