zion/modules/networking.nix

115 lines
2.3 KiB
Nix
Raw Normal View History

2019-11-06 23:04:16 +01:00
{ config, pkgs, lib, ... }:
2022-06-06 19:03:18 +02:00
let wireguard_port = 443;
in {
2022-01-05 13:54:59 +01:00
# Assign a static IP
networking = {
hostName = "zion";
hostId = "4e74ea68";
interfaces.eth0 = {
useDHCP = false;
ipv4.addresses = [{
address = "192.168.1.2";
prefixLength = 24;
}];
};
defaultGateway = {
address = "192.168.1.1";
interface = "eth0";
};
nameservers = [ "195.10.195.195" "165.22.224.164" ];
enableIPv6 = false;
};
2020-02-21 12:25:43 +01:00
# Enable zeroconf
services.avahi = {
enable = true;
nssmdns = true;
publish = {
enable = true;
userServices = true;
2020-06-09 21:53:20 +02:00
domain = true;
workstation = true;
2020-02-21 12:25:43 +01:00
};
2020-04-17 00:47:17 +02:00
reflector = true;
2020-02-21 12:25:43 +01:00
};
2019-11-06 23:04:16 +01:00
# Dynamic DNS configuration
services.ddclient = {
enable = true;
quiet = true;
2019-11-10 17:47:46 +01:00
protocol = "duckdns";
domains = [ "coolneng.duckdns.org" ];
2021-11-29 10:38:29 +01:00
passwordFile = "/var/keys/ddclient";
2019-11-06 23:04:16 +01:00
};
# Firewall configuration
networking.firewall = {
allowedTCPPorts = [
2020-11-30 02:03:58 +01:00
80 # HTTP
443 # HTTPS
53 # DNS
2021-02-03 18:38:41 +01:00
8448 # Matrix
];
2020-02-21 12:25:43 +01:00
allowedUDPPorts = [
2022-06-06 19:03:18 +02:00
wireguard_port # Wireguard
2020-11-30 02:03:58 +01:00
53 # DNS
2020-02-21 12:25:43 +01:00
];
extraCommands = ''
2020-06-09 21:53:20 +02:00
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
'';
2019-11-06 23:04:16 +01:00
};
2019-11-11 14:30:45 +01:00
2020-02-21 12:25:43 +01:00
# Enable NAT for wireguard
networking.nat = {
enable = true;
externalInterface = "eth0";
internalInterfaces = [ "wg0" ];
};
# Wireguard setup
networking.wireguard.interfaces = {
wg0 = {
ips = [ "10.8.0.1/24" ];
2022-06-06 19:03:18 +02:00
listenPort = wireguard_port;
2020-02-21 12:25:43 +01:00
privateKeyFile = "/home/coolneng/.wg/keys/privatekey";
peers = [
2020-12-14 02:52:04 +01:00
# panacea
2020-02-21 12:25:43 +01:00
{
2020-06-09 21:53:20 +02:00
publicKey = "XMkTztU2Y8hw6Fu/2o4Gszij+EmNacvFMXuZyHS1n38=";
2020-02-21 12:25:43 +01:00
allowedIPs = [ "10.8.0.2/32" ];
}
2020-12-14 02:52:04 +01:00
# caravanserai
2020-09-24 16:13:02 +02:00
{
2020-12-10 13:59:02 +01:00
publicKey = "eFykHmnMALRUluApRfSM32Xw80kTNo7yUsxs47URkX4=";
2020-09-24 21:56:25 +02:00
allowedIPs = [ "10.8.0.3/32" ];
2020-09-24 16:13:02 +02:00
}
2020-02-21 12:25:43 +01:00
];
};
};
2020-11-30 02:03:58 +01:00
# DNS server with ad-block
services.dnsmasq = {
enable = true;
2022-01-05 13:54:59 +01:00
servers = config.networking.nameservers;
2020-11-30 02:03:58 +01:00
extraConfig = ''
domain-needed
bogus-priv
no-resolv
2022-01-05 13:54:59 +01:00
listen-address=127.0.0.1,192.168.1.2,10.8.0.1
2020-11-30 02:03:58 +01:00
bind-interfaces
cache-size=10000
local-ttl=300
conf-file=/var/lib/dnsmasq/dnsmasq.blacklist.txt
2020-12-01 11:03:01 +01:00
2022-01-05 13:54:59 +01:00
address=/coolneng.duckdns.org/192.168.1.2
2020-11-30 02:03:58 +01:00
'';
};
2019-11-06 23:04:16 +01:00
}