WireGuard: Difference between revisions
systemd.network permissions |
fix grammar |
||
Line 2: | Line 2: | ||
= Configuration Modules = | = Configuration Modules = | ||
WireGuard-related NixOS options exist for the following networking modules: | |||
* NetworkManager | * NetworkManager | ||
Line 15: | Line 8: | ||
* networking.wireguard | * networking.wireguard | ||
* systemd.network | * systemd.network | ||
Depending on how your computer is configured, you need to refer to the | |||
relevant section for setting up WireGuard. | |||
= Use cases = | = Use cases = | ||
The first use case is Virtual Private Network, which makes several peers | The first use case is Virtual Private Network, which makes several peers | ||
available on | available on the same private subnet. This is the basis for the proxy | ||
configuration. | configuration below. | ||
The second use case is Internet proxy, which allows you to access the | The second use case is Internet proxy, which allows you to access the | ||
Internet via another peer. | Internet via another peer. | ||
== External DNS with dnscrypt == | == External DNS with dnscrypt == | ||
Line 64: | Line 40: | ||
== Proxy DNS with dnsmasq == | == Proxy DNS with dnsmasq == | ||
You can also use the proxy server as DNS server with | |||
dnsmasq. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 81: | Line 58: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
For wg-quick peer, use the | |||
following | following option | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 94: | Line 71: | ||
= AllowedIPs = | = AllowedIPs = | ||
Each peer can handle traffic destined for a certain IP range. | |||
This range is called AllowedIP. | |||
Common forms of allowed IPs include | |||
* 192.168.26.9/32, a single internal IPv4 address | * 192.168.26.9/32, a single internal IPv4 address | ||
Line 106: | Line 83: | ||
* ::/0, entire IPv6 address space, for proxying | * ::/0, entire IPv6 address space, for proxying | ||
Notice that, in | Notice that, in specifying its subnet mask, some configuration | ||
modules can automatically configure network routes. | modules can automatically configure network routes. | ||
Allowed IPs | Allowed IPs should be unique to each peer. If there are peers whose | ||
allowed IPs, | allowed IPs overlap, traffic will only reach one of them. | ||
= | = UDP Port = | ||
The default port is 51820. Some literature recommends changing this | The default port is 51820. Some literature recommends changing this | ||
port to circumvent | port to circumvent blocking of WireGuard traffic. | ||
= Generate keys = | = Generate keys = | ||
WireGuard works with public-private key pairs | WireGuard works with public-private key pairs. | ||
Computer (peer) is identified by its public key. | |||
this | Only connections from peers with known public keys are accepted. | ||
For this reason, you can not reuse keys on multiple peers. | |||
To generate a private key, and | To generate a private key, and derive the public key from it, you | ||
need the <code>wg</code> utility, available in | need the <code>wg</code> utility, available in | ||
<code>wireguard-tools</code> package. | <code>wireguard-tools</code> package. | ||
Line 138: | Line 114: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
You need to generate a new key for each peer | You need to generate a new key for each peer. | ||
Make sure the private key has the correct file permission as required | |||
cause the | by the WireGuard service. Wrong file permission may | ||
cause the service to fail. Check system log to rule out | |||
this scenario. | this scenario. | ||
Line 452: | Line 427: | ||
Optionally, configure proxy server as DNS server as described above. | Optionally, configure proxy server as DNS server as described above. | ||
Note, systemd.network client seems to have issues. Use wg-quick | Note, systemd.network client seems to have issues wit routing. Use wg-quick | ||
client instead. | client instead. | ||