enable forwarding on vpn

This commit is contained in:
Tim Schubert 2022-04-27 19:30:58 +02:00
parent d415aa10be
commit b8f2c5c531
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA
2 changed files with 27 additions and 14 deletions

View file

@ -134,6 +134,11 @@ in
networking.interfaces.ens3.useDHCP = true; networking.interfaces.ens3.useDHCP = true;
networking.interfaces.ens7.useDHCP = false; networking.interfaces.ens7.useDHCP = false;
boot.kernel.sysctl = {
# Enable forwarding for VPN
"net.ipv6.conf.ens3.forwarding" = true;
};
fileSystems."/mnt/storage" = { fileSystems."/mnt/storage" = {
device = "/dev/disk/by-uuid/a34e36fc-d7dd-4ceb-93c4-48f9c2727cb7"; device = "/dev/disk/by-uuid/a34e36fc-d7dd-4ceb-93c4-48f9c2727cb7";
mountPoint = "/mnt/storage"; mountPoint = "/mnt/storage";

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { config, pkgs, lib, ... }:
with lib; with lib;
let let
@ -32,19 +32,27 @@ in
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
networking.wireguard.enable = true; networking.wireguard = {
networking.wireguard.interfaces."wg0" = { enable = true;
allowedIPsAsRoutes = true; interfaces."wg0" = {
privateKeyFile = "/var/lib/wireguard/wg0-key"; allowedIPsAsRoutes = true;
ips = [ "fd42:9c3b:f96d:0200::0/64" ]; privateKeyFile = "/var/lib/wireguard/wg0-key";
listenPort = 51234; ips = [ "fd42:9c3b:f96d:0200::0/64" ];
peers = map listenPort = 51234;
(peer: ( peers = map
{ (peer: (
allowedIPs = [ "fd42:9c3b:f96d:0200::${peer.id}/128" ]; {
publicKey = peer.key; allowedIPs = [ "fd42:9c3b:f96d:0200::${peer.id}/128" ];
})) publicKey = peer.key;
(attrValues cfg.peers); }))
(attrValues cfg.peers);
postSetup = ''
wg set wg0 fwmark 51234
ip rule add table 2468
ip route add default dev ens3 table 2468
ip route add fwmark 51234 table 2468
'';
};
}; };
}; };
} }