My goal is to create a VPN so
- Clients have static IP addresses.
- Clients are able to communicate with each other and the server,
- Clients can reach global Internet through the VPN.
- Also, I’d like to setup DNS and private domain names (working with NginX).
Here is config of the server:
[Interface]
Address = 10.0.0.1/24
ListenPort = 5555
PrivateKey = xxxxx
[Peer]
PublicKey = xxxxx
AllowedIPs = 0.0.0.0/0
And client’s config:
[Interface]
PrivateKey = xxxxx
ListenPort = 5555
Address = 10.0.0.2/32
DNS = 8.8.8.8
[Peer]
PublicKey = xxxxx
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = <server ip>:5555
But when I’m trying to load server’s config wg setconf wg0 /etc/wireguard/wg0.conf
I get this error:
Line unrecognized: `Address=10.0.0.1/24'
Configuration parsing error
Thus I commented this line. But it probably makes WG choose random IP addresses for the server and clients.
To make WireGuard work, I also ran these commands:
ip link add dev wg0 type wireguard
ip address add dev wg0 10.0.0.1/24
ip link set up dev wg0
After all, wg
commands provides the following output:
interface: wg0
public key: xxxxx
private key: (hidden)
listening port: 5555
peer: xxxxx
endpoint: <my IP address>:6228
allowed ips: 0.0.0.0/0
latest handshake: 2 minutes, 11 seconds ago
transfer: 26.02 KiB received, 248 B sent
From the client (which is MacOS with WireGuard GUI) I’m able to connect, but:
- I get no Internet connection. I even can’t ping the server by global IP address, though I can with the private one,
10.0.0.1
. - I’m able to get connected to VPN even if I change the port in client’s config. I think it means that it doesn’t really get connected.
So, how can I achieve my goals? And what’s wrong with my configs??
PS. Neither iptables
nor firewalls are installed on the server, so it can’t be a problem. Also, I have specified net.ipv4.ip_forward=1
& net.ipv6.conf.all.forwarding=1
in the /etc/sysctl.conf
.
Software versions. OS is Ubuntu 18.04.4 LTS
, Kernel: 4.15.0-20-generic
, WG: wireguard-tools v1.0.20200206
.
Update
I removed Address
from server’s config, and set AllowedIPs = 10.0.0.2/24
in the client’s one, I finally got connected to the server’s NginX from client by private IP, and able to reach the Internet (coz traffic goes outside VPN).
But if I set AllowedIPs = 0.0.0.0/0
on the client, I have no Internet access, though still can reach server by VPN’s IP address 10.0.0.1. I tried solving it with ifconfig wg0 broadcast/multicast
, but had no success. Now the command ip address show wg0
provides the following output:
4: wg0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.10.10.1/24 scope global wg0
valid_lft forever preferred_lft forever
inet 10.10.10.1 peer 10.10.10.2/32 scope global wg0
valid_lft forever preferred_lft forever
In addition, I cannot access one client from another, I think it’s the same problem. How can I fix WireGuard configs or server network settings to solve the problem?
Hi there,
i hope you can help me as i saw there are a few Wireguard Users here as well.
I did setup Armbian 20.05.4 Buster on my Cubietruck and configured Wireguard. After a few mistakes the connection from outside (iOS Client) is stable but very slow. I went to the obvious roads and found the MTU setting on the client side could be an issue as well some PostUp command parameters can improve performance. But for any reason my wireguard doesn´t want to accept anything with PostUp, Safeconfig etc in my wg0.conf file: Parsing error. But without that been solved i assume i can´t work on the Performance improvement. Here a few lines of code showing the relevant config Files and the Error:
root@cubietruck:/etc/wireguard# cat wg0.conf
[Interface]
ListenPort=40404
PrivateKey=blablablaServerKey
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; iptables -A FORWARD -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; iptables -D FORWARD -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
[Peer]
PublicKey=blablabla Public Key
AllowedIPs=192.168.42.100,fd00:42::100
root@cubietruck:/etc/wireguard# cat clients/omasiphone.conf
[Interface]
PrivateKey=blablablaclientkey
Address=192.168.42.100/24,fd00:42::100/64
DNS=1.1.1.1,2606:4700:4700::1111
MTU = 1412
PostUp = ip route add SERVER_PUBLIC_IP/32 via 192.168.1.200 dev eth0; iptables -A FORWARD -i wg0 -m state --state RELATED,ESTABLISHED -j ACCEPT; iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
PostDown = ip route del SERVER_PUBLIC_IP/32 via 192.168.1.200 dev eth0; iptables -D FORWARD -i wg0 -m state --state RELATED,ESTABLISHED -j ACCEPT; iptables -D FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
[Peer]
PublicKey=blablablaclientkey
Endpoint=ganzgeheim.myfritz.net:40404
AllowedIPs=0.0.0.0/0,::/0
root@cubietruck:/etc/wireguard# wg setconf wg0 /etc/wireguard/wg0.conf
Line unrecognized: `PostUp=iptables-AFORWARD-iwg0-jACCEPT;iptables-tnat-APOSTROUTING-oeth0-jMASQUERADE;iptables-AFORWARD-ieth0-mstate--stateRELATED,ESTABLISHED-jACCEPT'
Configuration parsing error
Can you help me here a bit?
Мне нужно создать VPN такой, чтобы
- У клиентов были стические IP адреса.
- Клиенты могли взаимодействовать друг с другом и сервером,
- Клиенты могли выходить в интернет из-под VPN.
- Также, хотелось бы настроить собственный DNS и приватные домены (обрабатываемые NginX).
Конфигурационные сервера у меня такой:
[Interface]
Address = 10.0.0.1/24, fd86:ea04:1115::1/64
ListenPort = 5555
PrivateKey = xxxxx
[Peer]
PublicKey = xxxxx
AllowedIPs = 0.0.0.0/0
А это конфигурации клиента:
[Interface]
PrivateKey = xxxxx
ListenPort = 5555
Address = 10.0.0.2/32
DNS = 8.8.8.8
[Peer]
PublicKey = xxxxx
AllowedIPs = 0.0.0.0/0, ::/0
Но при попытке загрузить конфигурации сервера через wg setconf wg0 /etc/wireguard/wg0.conf
я получаю такую ошибку:
Line unrecognized: `Address=10.0.0.1/24,fd86:ea04:1115::1/64'
Configuration parsing error
Поэтому я закомментировал ту строку. Но это вероятно заставляет WG выбирать себе и клиентам случайные IP адреса.
Для запуска WireGuard я выполняю такие команды:
ip link add dev wg0 type wireguard
ip address add dev wg0 10.0.0.1/24
ip link set up dev wg0
После, команда wg
даёт такой вывод:
interface: wg0
public key: xxxxx
private key: (hidden)
listening port: 5555
peer: xxxxx
endpoint: <my IP address>:6228
allowed ips: 0.0.0.0/0
latest handshake: 2 minutes, 11 seconds ago
transfer: 26.02 KiB received, 248 B sent
С клиента (моя MacOS с WireGuard GUI) у меня получается подключиться, но:
- Нет соединения с интернетом. Я даже не могу пинговать сервер по глобальному адресу, хотя по приватному
10.0.0.1
получается. - Я могу подключиться к VPN даже если укажу в конфиге клиента другой порт. Думаю, это значит, что он не подключается на самом деле.
Как мне заставить WireGuard работать нужным образом? И что не так с моими конфигами??
PS. На сервере нет ни iptables
, ни файерволов, так что это не может быть проблемой. Также, в файле /etc/sysctl.conf
я указал net.ipv4.ip_forward=1
и net.ipv6.conf.all.forwarding=1
, и выполнил systemctl restart systemd-networkd
.
Версии ПО. ОС: Ubuntu 18.04.1 LTS
, Kernel: 4.15.0-20-generic
, WG: wireguard-tools v1.0.20200206
.
#1 2020-12-28 12:03:54
- Der Chefkoch
- Member
- Registered: 2020-12-05
- Posts: 94
Wireguard fails to start at bootup
While I got Wireguard to work nicely, an issue remains with having the service start automatically at bootup (I run Arch on a laptop).
The service is enabled via
sudo systemctl enable wg-quick@ARCH.service
After a reboot,
sudo systemctl status wg-quick@ARCH.service
returns
wg-quick@ARCH.service - WireGuard via wg-quick(8) for ARCH
Loaded: loaded (/usr/lib/systemd/system/wg-quick@.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2020-12-27 08:56:25 CET; 18s ago
Docs: man:wg-quick(8)
man:wg(8)
https://www.wireguard.com/
https://www.wireguard.com/quickstart/
https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
Process: 1108 ExecStart=/usr/bin/wg-quick up ARCH (code=exited, status=1/FAILURE)
Main PID: 1108 (code=exited, status=1/FAILURE)
Dez 27 08:56:24 arch systemd[1]: Starting WireGuard via wg-quick(8) for ARCH...
Dez 27 08:56:24 arch wg-quick[1108]: [#] ip link add ARCH type wireguard
Dez 27 08:56:25 arch wg-quick[1108]: [#] wg setconf ARCH /dev/fd/63
Dez 27 08:56:25 arch wg-quick[1130]: Name or service not known: `[URL:port]' #EDITED
Dez 27 08:56:25 arch wg-quick[1130]: Configuration parsing error
Dez 27 08:56:25 arch wg-quick[1108]: [#] ip link delete dev ARCH
The last 3 lines led me to assume that Wireguard was trying to connect while the network was still down. So I checked in the respective config file in folder /etc/systemd/system/multi-user.target.wants/:
[Unit]
Description=WireGuard via wg-quick(8) for %I
Wants=network-online.target nss-lookup.target
After=network-online.target nss-lookup.target
PartOf=wg-quick.target
Documentation=man:wg-quick(8)
Documentation=man:wg(8)
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wg-quick up %i
ExecStop=/usr/bin/wg-quick down %i
ExecReload=/bin/bash -c 'exec /usr/bin/wg syncconf %i <(exec /usr/bin/wg-quick strip %i)'
Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity
[Install]
WantedBy=multi-user.target
I would have assumed that these lines
Wants=network-online.target nss-lookup.target
After=network-online.target nss-lookup.target
would let Wireguard wait for the network (wifi in my case) to be up, but it doesn’t seem to work. What am I missing?
#2 2020-12-28 12:05:33
- schard
- Member
- From: Hannover
- Registered: 2016-05-06
- Posts: 1,610
- Website
Re: Wireguard fails to start at bootup
Well, you edited out the source of the error:
Dez 27 08:56:25 arch wg-quick[1130]: Name or service not known: `[URL:port]' #EDITED
Dez 27 08:56:25 arch wg-quick[1130]: Configuration parsing error
Please post the respective configuration file, so that we can see any possible error.
In any case, Name or service not known indicates, that DNS resultion is not (yet) available.
Requires=network-online.target nss-lookup.target
Might solve that.
How do you connect to the internet anyways? systemd-networkd, netctl, dhcpcd, NetworkManager, …?
Last edited by schard (2020-12-28 12:07:53)
#3 2020-12-28 12:22:48
- Der Chefkoch
- Member
- Registered: 2020-12-05
- Posts: 94
Re: Wireguard fails to start at bootup
schard wrote:
Well, you edited out the source of the error:
Dez 27 08:56:25 arch wg-quick[1130]: Name or service not known: `[URL:port]' #EDITED Dez 27 08:56:25 arch wg-quick[1130]: Configuration parsing error
Please post the respective configuration file, so that we can see any possible error.
Thanks for your input. I only edited out my IP and port which are correct, as I can connect with this config file just fine otherwise.
schard wrote:
In any case, Name or service not known indicates, that DNS resultion is not (yet) available.
Requires=network-online.target nss-lookup.target
Might solve that.
How do you connect to the internet anyways? systemd-networkd, netctl, dhcpcd, NetworkManager, …?
I will give that a try, do I replace
Wants=network-online.target nss-lookup.target
with your suggestion?
I haven’t bothered with the network connection in over a month after installation, I think it is NetworkManager as I have a config file for the service.
Last edited by Der Chefkoch (2020-12-28 12:23:44)
#4 2020-12-28 12:28:25
- schard
- Member
- From: Hannover
- Registered: 2016-05-06
- Posts: 1,610
- Website
Re: Wireguard fails to start at bootup
Der Chefkoch wrote:
I will give that a try, do I replace
Wants=network-online.target nss-lookup.target
with your suggestion?
Exactly.
Der Chefkoch wrote:
I haven’t bothered with the network connection in over a month after installation, I think it is NetworkManager as I have a config file for the service.
systemctl list-unit-files --state enabled
Will give you an (incomplete) idea of what it mght be.
#5 2020-12-28 12:38:35
- Der Chefkoch
- Member
- Registered: 2020-12-05
- Posts: 94
Re: Wireguard fails to start at bootup
UNIT FILE STATE VENDOR PRESET
bluetooth.service enabled disabled
getty@.service enabled enabled
lightdm.service enabled disabled
NetworkManager-dispatcher.service enabled disabled
NetworkManager-wait-online.service enabled disabled
NetworkManager.service enabled disabled
systemd-resolved.service enabled enabled
systemd-timesyncd.service enabled enabled
tlp.service enabled disabled
cups.socket enabled disabled
remote-fs.target enabled enabled
fstrim.timer enabled disabled
jup, NetworkManager.
Unfortunately, the suggested change to the service file did not resolve the issue (below the edit).
[Unit]
Description=WireGuard via wg-quick(8) for %I
Requires=network-online.target nss-lookup.target
After=network-online.target nss-lookup.target
PartOf=wg-quick.target
#6 2020-12-28 12:46:03
- progandy
- Member
- Registered: 2012-05-17
- Posts: 5,071
Re: Wireguard fails to start at bootup
If I read the manual correctly, then you must not add the «Requires» line, only «After» for nss-lookup
https://www.freedesktop.org/software/sy … ecial.html
nss-lookup.target
A target that should be used as synchronization point for all host/network name service lookups. Note that this is independent of UNIX user/group name lookups for which nss-user-lookup.target should be used. All services for which the availability of full host/network name resolution is essential should be ordered after this target, but not pull it in. systemd automatically adds dependencies of type After= for this target unit to all SysV init script service units with an LSB header referring to the «$named» facility.
Last edited by progandy (2020-12-28 12:46:44)
| alias CUTF=’LANG=en_XX.UTF-8@POSIX ‘ |
#7 2020-12-28 12:51:57
- schard
- Member
- From: Hannover
- Registered: 2016-05-06
- Posts: 1,610
- Website
Re: Wireguard fails to start at bootup
As @progandy noted, undo the last change and add:
After=NetworkManager-wait-online.service
Requires=NetworkManager-wait-online.service
to the dependencies.
Last edited by schard (2020-12-28 12:53:53)
#8 2020-12-28 13:49:33
- Der Chefkoch
- Member
- Registered: 2020-12-05
- Posts: 94
Re: Wireguard fails to start at bootup
I enabled the suggested service via
sudo systemctl enable NetworkManager-wait-online.service
Changed the config file
[Unit]
Description=WireGuard via wg-quick(8) for %I
Wants=network-online.target nss-lookup.target
After=network-online.target nss-lookup.target
After=NetworkManager-wait-online.service
Requires=NetworkManager-wait-online.service
PartOf=wg-quick.target
Documentation=man:wg-quick(8)
Documentation=man:wg(8)
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wg-quick up %i
ExecStop=/usr/bin/wg-quick down %i
ExecReload=/bin/bash -c 'exec /usr/bin/wg syncconf %i <(exec /usr/bin/wg-quick strip %i)'
Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity
[Install]
WantedBy=multi-user.target
Unfortunately, did not work.
#9 2021-01-06 04:52:18
- 1b3r1c0
- Member
- Registered: 2021-01-06
- Posts: 1
Re: Wireguard fails to start at bootup
maybe try
sudo systemctl enable wg-quick@wg0.service
I think «%i» is the bit in between the «@» and the «.service» and in this case its supposed to be wiregaurd’s tunnel interface (maybe you named your interface «ARCH»?)
From https://blog.fruxlabs.com/setting-up-wireguard-vpn/
To start WireGuard automatically on system startup
systemctl enable wg-quick@wg0
#10 2021-01-28 14:14:19
- smirky
- Member
- From: Bulgaria
- Registered: 2013-02-23
- Posts: 273
- Website
Re: Wireguard fails to start at bootup
Hi!
I’ve hit the same problem. I find it odd, but in my case, it appears to be a race condition. On random (re)boots, the wg-quick service fails. What’s also odd is that a restart of the service doesn’t make it work either, considering it should be having at that point what we suspect here to be the problem (Network Manager). Rebooting obviously fixes it, but I’m not sure why restarting of the service doesn’t. Anyway, does anyone have any ideas how to troubleshoot this? Is it perhaps something that needs to be modified in the service file and reported upstream?
Personal spot :: https://www.smirky.net/ :: Try not to get lost!
#11 2021-02-05 06:52:25
- smirky
- Member
- From: Bulgaria
- Registered: 2013-02-23
- Posts: 273
- Website
Re: Wireguard fails to start at bootup
I just found my cause for wireguard to fail at boot in random boots. As per:
Jan 07 21:03:10 archy systemd[1]: Stopping WireGuard via wg-quick(8) for wg0...
Jan 07 21:03:10 archy wg-quick[451985]: [#] ip link delete dev wg0
Jan 07 21:03:11 archy wg-quick[451985]: [#] iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o enp0s31f6 -j MASQUERADE
Jan 07 21:03:11 archy wg-quick[452171]: Another app is currently holding the xtables lock. Perhaps you want to use the -w option?
Jan 07 21:03:11 archy systemd[1]: wg-quick@wg0.service: Control process exited, code=exited, status=4/NOPERMISSION
Jan 07 21:03:11 archy systemd[1]: wg-quick@wg0.service: Failed with result 'exit-code'.
Jan 07 21:03:11 archy systemd[1]: Stopped WireGuard via wg-quick(8) for wg0.
The important message is xtables lock being obtained and obviously WireGuard needs it. So I searched a little bit and found that perhaps something that manages iptables can be causing this.
Immediately, I thought of fail2ban and that was exactly the problem. After stopping fail2ban, wg-quick@wg0.service started just fine and of course I started fail2ban afterwards without a problem, but manually.
Question now is, how to prevent this from happening in the most clean way or perhaps I shouldn’t and this could be a bug?
Last edited by smirky (2021-02-05 07:09:19)
Personal spot :: https://www.smirky.net/ :: Try not to get lost!
Topic: Wireguard not working after upgrade from 21.1.2 to 21.1.4 (Read 4549 times)
Hi All,
I have upgraded my Opnsense instance to 21.1.4 from 21.1.2 and since then Wireguard is not working, I think the service is not running or some other issue. I see WG handshake timing out on the client side, but there is no traffic seen on the firewall end. I tried capturing packets on the WAN side on port udp 51820 (default port) but it’s not even showing any hits. I can see other traffic from same IP and IPSec vpn is also working fine. Was there any changes in 1.5? Do I need to reconfigure WG from scratch after this upgrade?
Thanks in advance.
Regards,
Bobby Thomas
« Last Edit: April 01, 2021, 07:13:25 pm by bobbythomas »
Logged
Ok, this is kind of weird, I tried connecting from inside network and it connected fine, then I tried connecting from WAN again and this time it connected fine. Not sure what’s going one with WG.
Going to mark this as Solved.
Logged
Golden rule for VPN: Don’t every use standard ports…
Logged
kind regards
chemlud
____
«The price of reliability is the pursuit of the utmost simplicity.»
C.A.R. Hoare
Logged
Golden rule for VPN: Don’t every use standard ports…
That’s called security by obscurity …
Logged
This seems to be reoccurring, I am unable to connect to WG from outside (WAN) if try to establish a new session (mostly after some hours after establishing a WG vpn sesison). But after connecting from inside (LAN) I am able to establish a WG session from outside. This is kind of weird. As this is reoccurring I changed the status of this post.
Any idea what could be causing the issue?
Thank you,
Regards,
Bobby Thomas
Logged
Suggest you post screenshots of your WG setup and relevant FW rules. The behaviour you are reporting is indeed very strange and points to some configuration issue. I have no issues at all connecting with WG under 21.1.4 (whether into OPNsense or out)
Logged
Same here, Wireguard is working fine for me, the upgrade was problem-free.
Logged
After upgrade to 21.1.4 my wireguard-go service shows as not started and when I try to restart nothing happens. On the other hand, wireguard appears to be working when I connect. I have tried reinstalling the wireguard services and still have the same behavior.
Logged
After upgrade to 21.1.4 my wireguard-go service shows as not started and when I try to restart nothing happens. On the other hand, wireguard appears to be working when I connect. I have tried reinstalling the wireguard services and still have the same behavior.
/usr/local/etc/rc.d/wireguard restart
Please post the output
Logged
See below
root@opnsense:~ # /usr/local/etc/rc.d/wireguard restart
- ifconfig wg0 destroy
- resolvconf -d wg0
- ifconfig wg create name wg0
- wg setconf wg0 /dev/stdin
- ifconfig wg0 inet 10.0.0.1/24 alias
- ifconfig wg0 mtu 1420
- ifconfig wg0 up
- resolvconf -a wg0 -x
- route -q -n add -inet 10.0.0.4/32 -interface wg0
- route -q -n add -inet 10.0.0.3/32 -interface wg0
- route -q -n add -inet 10.0.0.2/32 -interface wg0
- Backgrounding route monitor
root@opnsense:~ #
Logged
Logged
AAhhh
Me too
On my side i got this :
# /usr/local/etc/rc.d/wireguard restart
wg-quick: `wg0′ is not a WireGuard interface
- ifconfig wg create name wg0
- wireguard-go wg0
- wg setconf wg0 /dev/stdin
[!] Missing WireGuard kernel support (ifconfig: SIOCIFCREATE2: Invalid argument). Falling back to slow userspace implementation.
Line unrecognized: `PublicKey=’
Configuration parsing error
- rm -f /var/run/wireguard/wg0.sock
Logged
AAhhh
Me tooOn my side i got this :
# /usr/local/etc/rc.d/wireguard restart
wg-quick: `wg0′ is not a WireGuard interface
- ifconfig wg create name wg0
[!] Missing WireGuard kernel support (ifconfig: SIOCIFCREATE2: Invalid argument). Falling back to slow userspace implementation.
- wireguard-go wg0
- wg setconf wg0 /dev/stdin
Line unrecognized: `PublicKey=’
Configuration parsing error
- rm -f /var/run/wireguard/wg0.sock
So this is unrelated to the update and happened also before
Logged
Ah?
Because i got it after the update .
but any way i remove all conf and package, reboot and reinstall package, it’s work now.
Logged
A few days ago I spun up a Windows Dev VM to have a play with WireGuard for Windows.
I didn’t really have a clear goal in mind when I started playing with this — part of it was in trying to create and launch a tunnel without using the GUI. Mostly I was just trying to learn more about a new implementation of a tool that I really like.
If you read my previous article, you’ll recall that I started off trying to do this with just wireguard.exe
. Here are some things I’ve discovered:
wireguard.exe does a whole lot of stuff
Wireguard.exe isn’t just a GUI, which I originally thought it was. It’s also the piece of software that shouts out to WinTun to create the interface, as well as the utility that reads the ‘extended’ attributes in your .conf file (e.g. the stuff that wg-quick takes care of), as well as the utility that sets up your routes, DNS, etc, etc, etc.
wireguard.exe doesn’t create private/public keypairs
… To do this, you instead need to use wg.exe, which is installed under your System32 folder (so it’s in your path, so it’s accessible anywhere):
PS C:> wg genkey | tee $ENV:APPDATAWireGuard.priv | wg pubkey > $ENV:APPDATAWireGuard.pub
I did figure this out the other day, but I’m reiterating here.
wg.exe can read .conf files — but you don’t really want it to
Last time, I was having trouble reading a .conf file from wg.exe:
PS C:Users> wg setconf wg0 .wg0.conf
Line unrecognized: ` ■['
Configuration parsing error
I’m not entirely sure what this was — I’ve since been able to read in a .conf file perfectly fine (for the record this is UTF-8 with Windows CRLF line-endings).
However … my breakthrough kinda sucks.
Wireguard for Windows stores it’s config files in the Windows DPAPI-encrypted vault. This is vastly better than just bunging a file in C:UsersBlah
and hoping for the best. Maybe it’s not perfect — I don’t know much about DPAPI — but it’s a far cry better than nothing.
When you use wireguard.exe to import a tunnel from a .conf file, it will read it in, sanity-check it (mine failed because I accidentally hit the keyboard during copy/pasta, so it rejected the Base64 encoding), and then safely store it away in the DPAPI storage. You can then delete your original .conf file. Just do this, it’s better.
You need both wireguard.exe and wg.exe
OK so here’s the bit that I only fully realised tonight: wireguard.exe is like wg-quick, but it also provides the interface into the Windows network stack and the Windows DPAPI storage of your sensitive conf files. You can’t even run wg set
without it, because wireguard.exe is even responsible for creating the IPC Server that interfaces with WinTun.
Honestly the Windows world is so much more complicated than the Linux world*. 🙄
(* some caveats apply)
Conclusion
What’s my plan now?
I’m going to make a thing that:
- Installs wireguard.msi silently
- Uses wg.exe to create a private/public keypair
- Uses that keypair to create a temporary .conf file
- Uses wireguard.exe to import that .conf file from some predetermined location
- Deletes the .conf file (probably using cipher.exe to scrub it)
- Uses wireguard.exe to install the tunnel so it opens automatically on login
I’m hoping that this will create us something like an always-on-VPN connection that can be deployed easily by an IT support person, and require no end-user interaction.