From 20b73b364c1400b21d80d05b49e0c1a01ac0d2e8 Mon Sep 17 00:00:00 2001 From: coolneng Date: Fri, 12 Mar 2021 12:06:26 +0100 Subject: [PATCH] Assign static IP to server --- modules/networking.nix | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/modules/networking.nix b/modules/networking.nix index b570b9b..46505be 100644 --- a/modules/networking.nix +++ b/modules/networking.nix @@ -1,6 +1,23 @@ { config, lib, pkgs, ... }: { + # Assign a static IP + networking = { + interfaces.eth0 = { + useDHCP = false; + addresses = { + address = "10.0.1.3"; + prefixLength = 24; + }; + }; + defaultGateway = { + address = "10.0.1.1"; + interface = "eth0"; + }; + nameservers = [ "1.1.1.1" "8.8.8.8" ]; + enableIPv6 = false; + }; + # Enable zeroconf services.avahi = { enable = true; @@ -16,11 +33,18 @@ # Firewall configuration networking.firewall = { - # Samba - allowedTCPPorts = [ 445 139 ]; - allowedUDPPorts = [ 137 138 ]; + allowedTCPPorts = [ + 445 # Samba + 139 # Samba + ]; + allowedUDPPorts = [ + 137 # Samba + 138 # Samba + 1194 # Wireguard + ]; + extraCommands = '' + iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE + ''; }; - # Disable IPv6 - networking.enableIPv6 = false; }