WireGuard server module for mothership
This commit is contained in:
parent
57f3d7645b
commit
dc9f54fb76
6 changed files with 51 additions and 65 deletions
39
modules/wireguard-server/default.nix
Normal file
39
modules/wireguard-server/default.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
networking.nat.enable = true;
|
||||
networking.nat.externalInterface = "enp5s0"; # mothership network interface, shouldn't be hardcoded here
|
||||
networking.nat.internalInterfaces = ["wg0"];
|
||||
networking.firewall = {
|
||||
allowedUDPPorts = [51820];
|
||||
};
|
||||
|
||||
networking.wireguard.interfaces = {
|
||||
wg0 = {
|
||||
ips = ["10.100.0.1/24"];
|
||||
|
||||
listenPort = 51820;
|
||||
|
||||
postSetup = ''
|
||||
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o eth0 -j MASQUERADE
|
||||
'';
|
||||
|
||||
postShutdown = ''
|
||||
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 10.100.0.0/24 -o eth0 -j MASQUERADE
|
||||
'';
|
||||
|
||||
privateKeyFile = config.age.secrets."${config.networking.hostName}-wireguard-private-key".path;
|
||||
|
||||
peers = [
|
||||
{
|
||||
# thinkpad
|
||||
publicKey = "g8wId6Rl0olRFRtAnQ046ihPRYFCtMxOJ+/Z9ARwIxI=";
|
||||
# List of IPs assigned to this peer within the tunnel subnet. Used to configure routing.
|
||||
allowedIPs = ["10.100.0.2/32"];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue