enable wireguard

This commit is contained in:
Ivan Dimitrov 2023-11-18 15:32:14 +02:00
parent cac62944b3
commit 7a31488abd
2 changed files with 35 additions and 1 deletions

View File

@ -1,4 +1,4 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = [ ./configuration.nix ./mailserver.nix ./roundcube.nix ./postgres.nix ]; imports = [ ./configuration.nix ./mailserver.nix ./roundcube.nix ./postgres.nix ./wireguard.nix ];
} }

34
mailserver/wireguard.nix Normal file
View File

@ -0,0 +1,34 @@
{ pkgs, ... }: {
networking = {
nat = {
enable = true;
externalInterface = "eth0";
internalInterfaces = [ "wg0" ];
};
firewall = {
allowedUDPPorts = [ 51820 ];
};
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 = "/etc/wireguard/privatekey";
generatePrivateKeyFile = true;
peers = [
{
publicKey = "28yXYLk4U0r6MdWFEZzk6apI8uhg962wMprF47wUJyI=";
allowedIPs = [ "10.100.0.2/32" ];
}
];
};
};
};
}