myNixOSConfig/services/vpn1.nix
2024-09-07 08:36:34 +02:00

68 lines
2.3 KiB
Nix

{ lib,config, pkgs, ...}:
{
networking.firewall = {
allowedUDPPorts = [ 51820 ]; # Clients and peers can use the same port, see listenport
};
networking.wireguard.interfaces = {
# "wg0" is the network interface name. You can name the interface arbitrarily.
wg0 = {
# Determines the IP address and subnet of the client's end of the tunnel interface.
ips = [ "2a01:4f8:c012:59b8:ac1e::3/128" ];
listenPort = 51820; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
#dns = ["1.1.1.1,1.0.0.1,2606:4700:4700::1111,2606:4700:4700::1001"];
mtu = ["1300"];
# Path to the private key file.
#
# Note: The private key can also be included inline via the privateKey option,
# but this makes the private key world-readable; thus, using privateKeyFile is
# recommended.
privateKeyFile = "./secrets/private";
peers = [
# For a client configuration, one peer entry for the server will suffice.
{
# Public key of the server (not a file path).
publicKey = "JTecKVDA3RSfwcbaBtcEUG4RsTEUUJTJyb65aABQAmg=";
presharedKeyFile = "./secrets/pre";
# Forward all the traffic via VPN.
allowedIPs = [ "0.0.0.0/0,::/0" ];
# Or forward only particular subnets
#allowedIPs = [ "10.100.0.1" "91.108.12.0/22" ];
# Set this to the server IP and port.
endpoint = "fumbled.strangled.net:51820"; # ToDo: route to endpoint not automatically configured https://wiki.archlinux.org/index.php/WireGuard#Loop_routing https://discourse.nixos.org/t/solved-minimal-firewall-setup-for-wireguard-client/7577
# Send keepalives every 25 seconds. Important to keep NAT tables alive.
persistentKeepalive = 15;
}
];
};
};
networks.wg0 = {
# See also man systemd.network
matchConfig.Name = "wg0";
# IP addresses the client interface will have
#address = [
# "fe80::3/64"
# "fc00::3/120"
# "10.100.0.2/24"
#];
#DHCP = "no";
#dns = ["1.1.1.1,1.0.0.1,2606:4700:4700::1111,2606:4700:4700::1001"];
#ntp = ["fc00::123"];
#gateway = [
# "fc00::1"
# "10.100.0.1"
#];
#networkConfig = {
# IPv6AcceptRA = false;
#};
};
}