mirror of
https://gitlab.com/upRootNutrition/dotfiles.git
synced 2025-08-08 12:54:38 -05:00
feat: wireguard test
This commit is contained in:
parent
8b9ece1b4e
commit
1d9097408c
5 changed files with 24 additions and 59 deletions
|
@ -28,7 +28,7 @@ in
|
||||||
options = ownerExclusiveReadWriteMask;
|
options = ownerExclusiveReadWriteMask;
|
||||||
};
|
};
|
||||||
wireguard = {
|
wireguard = {
|
||||||
ip0 = "10.0.0.1";
|
ip0 = "10.100.0.1";
|
||||||
};
|
};
|
||||||
storage0 = {
|
storage0 = {
|
||||||
mount = "/mnt/media/${ceresStorageDriveName}";
|
mount = "/mnt/media/${ceresStorageDriveName}";
|
||||||
|
|
|
@ -19,7 +19,7 @@ in
|
||||||
options = ownerWriteOthersReadMask;
|
options = ownerWriteOthersReadMask;
|
||||||
};
|
};
|
||||||
wireguard = {
|
wireguard = {
|
||||||
ip0 = "10.0.0.2";
|
ip0 = "10.100.0.2";
|
||||||
};
|
};
|
||||||
storage0 = {
|
storage0 = {
|
||||||
mount = "/mnt/media/games";
|
mount = "/mnt/media/games";
|
||||||
|
|
|
@ -22,6 +22,7 @@ in
|
||||||
address1 = "0.0.0.0"; # All
|
address1 = "0.0.0.0"; # All
|
||||||
address2 = "192.168.50.1"; # Router
|
address2 = "192.168.50.1"; # Router
|
||||||
address3 = "192.168.50.0"; # Router
|
address3 = "192.168.50.0"; # Router
|
||||||
|
address4 = "192.168.1.0"; # Router
|
||||||
};
|
};
|
||||||
remotehost = {
|
remotehost = {
|
||||||
address0 = "24.76.173.0";
|
address0 = "24.76.173.0";
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
{
|
{ config, flake, ... }:
|
||||||
config,
|
|
||||||
flake,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
inherit (flake.config.services.instances) wireGuard;
|
inherit (flake.config.services.instances) wireGuard;
|
||||||
inherit (flake.config.machines.devices) mars ceres;
|
inherit (flake.config.machines.devices) mars ceres;
|
||||||
service = wireGuard;
|
service = wireGuard;
|
||||||
hostIP = "${ceres.wireguard.ip0}/24";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
networking = {
|
networking = {
|
||||||
|
@ -29,36 +23,15 @@ in
|
||||||
internalInterfaces = [ "wg0" ];
|
internalInterfaces = [ "wg0" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
wg-quick.interfaces = {
|
wireguard.interfaces = {
|
||||||
wg0 = {
|
wg0 = {
|
||||||
address = [
|
ips = [ "${ceres.wireguard.ip0}/24" ];
|
||||||
hostIP
|
|
||||||
"fdc9:281f:04d7:9ee9::1/64"
|
|
||||||
];
|
|
||||||
listenPort = service.ports.port1;
|
listenPort = service.ports.port1;
|
||||||
privateKeyFile = config.sops.secrets."${service.name}-private".path;
|
privateKeyFile = config.sops.secrets."${service.name}-private".path;
|
||||||
postUp = ''
|
|
||||||
${pkgs.iptables}/bin/iptables -A FORWARD -i wg0 -j ACCEPT
|
|
||||||
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s ${hostIP} -o eth0 -j MASQUERADE
|
|
||||||
${pkgs.iptables}/bin/ip6tables -A FORWARD -i wg0 -j ACCEPT
|
|
||||||
${pkgs.iptables}/bin/ip6tables -t nat -A POSTROUTING -s fdc9:281f:04d7:9ee9::1/64 -o eth0 -j MASQUERADE
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Undo the above
|
|
||||||
preDown = ''
|
|
||||||
${pkgs.iptables}/bin/iptables -D FORWARD -i wg0 -j ACCEPT
|
|
||||||
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s ${hostIP} -o eth0 -j MASQUERADE
|
|
||||||
${pkgs.iptables}/bin/ip6tables -D FORWARD -i wg0 -j ACCEPT
|
|
||||||
${pkgs.iptables}/bin/ip6tables -t nat -D POSTROUTING -s fdc9:281f:04d7:9ee9::1/64 -o eth0 -j MASQUERADE
|
|
||||||
'';
|
|
||||||
peers = [
|
peers = [
|
||||||
{
|
{
|
||||||
publicKey = "9zfRPxkxTLHM9tABC8lIaDMrzdjcF2l1mtG82uqGKUQ=";
|
publicKey = "9zfRPxkxTLHM9tABC8lIaDMrzdjcF2l1mtG82uqGKUQ=";
|
||||||
presharedKeyFile = config.sops.secrets."${service.name}-mars-public".path;
|
allowedIPs = [ "${mars.wireguard.ip0}/32" ];
|
||||||
allowedIPs = [
|
|
||||||
"${mars.wireguard.ip0}/32"
|
|
||||||
"fdc9:281f:04d7:9ee9::2/128"
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
@ -83,7 +56,6 @@ in
|
||||||
[
|
[
|
||||||
"private"
|
"private"
|
||||||
"public"
|
"public"
|
||||||
"mars-public"
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,30 +5,23 @@ let
|
||||||
service = wireGuard;
|
service = wireGuard;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
networking.wg-quick.interfaces = {
|
networking = {
|
||||||
wg0 = {
|
wireguard.interfaces = {
|
||||||
address = [
|
wg0 = {
|
||||||
"${mars.wireguard.ip0}/24"
|
ips = [ "${mars.wireguard.ip0}/32" ];
|
||||||
"fdc9:281f:04d7:9ee9::2/64"
|
privateKeyFile = config.sops.secrets."${service.name}-mars-private".path;
|
||||||
];
|
peers = [
|
||||||
dns = [
|
{
|
||||||
"${ceres.wireguard.ip0}"
|
publicKey = "fs58+Kz+eG9qAXvvMB2NkW+wa88yP61uam4HHWaBJVw=";
|
||||||
"fdc9:281f:04d7:9ee9::1"
|
allowedIPs = [
|
||||||
];
|
"${ceres.wireguard.ip0}/32"
|
||||||
privateKeyFile = config.sops.secrets."${service.name}-mars-private".path;
|
"${web.localhost.address4}/24"
|
||||||
peers = [
|
];
|
||||||
{
|
endpoint = "${web.remotehost.address0}:${builtins.toString service.ports.port1}";
|
||||||
publicKey = "fs58+Kz+eG9qAXvvMB2NkW+wa88yP61uam4HHWaBJVw=";
|
persistentKeepalive = 25;
|
||||||
presharedKeyFile = config.sops.secrets."${service.name}-public".path;
|
}
|
||||||
allowedIPs = [
|
];
|
||||||
"192.168.1.0/24"
|
};
|
||||||
"0.0.0.0/0"
|
|
||||||
"::/0"
|
|
||||||
];
|
|
||||||
endpoint = "${web.remotehost.address0}:${builtins.toString service.ports.port1}";
|
|
||||||
persistentKeepalive = 25;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,7 +43,6 @@ in
|
||||||
[
|
[
|
||||||
"mars-private"
|
"mars-private"
|
||||||
"mars-public"
|
"mars-public"
|
||||||
"public"
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue