2023-06-06 15:01:28 +00:00
# networking.nix
# Import the necessary modules
{ config , pkgs , . . . }:
{
# Set the network interface configuration
# networking.interfaces.eth0.useDHCP = true;
networking . networkmanager . enable = true ;
# Open ports in the firewall.
2023-06-18 14:32:51 +00:00
networking . firewall . allowedTCPPorts = [ 22 ] ;
2023-06-28 18:41:14 +00:00
networking . firewall . allowedUDPPorts = [ 51820 ] ;
2023-06-06 15:01:28 +00:00
# Or disable the firewall altogether.
2023-06-18 14:32:51 +00:00
# networking.firewall.enable = true;
2023-06-06 15:01:28 +00:00
2023-06-28 18:41:14 +00:00
# Enable WireGuard
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 = [ " 1 0 . 1 0 0 . 0 . 2 / 2 4 " ] ;
listenPort = 51820 ; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
# 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 = " / e t c / w i r e g u a r d / p r i v a t e " ;
peers = [
{
# Public key of the server (not a file path).
publicKey = " Q 6 k x h w G h q O y a G y y O 4 l u m 8 3 W p J q j s j 7 1 A b 4 g v U a u 2 z C I = " ;
# Forward all the traffic via VPN.
allowedIPs = [ " 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 = " 1 9 2 . 1 6 8 . 2 . 1 1 : 5 1 8 2 0 " ; # 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 = 25 ;
}
] ;
} ;
} ;
2023-06-06 15:01:28 +00:00
# Set the hostname
2023-06-13 14:12:52 +00:00
networking . hostName = " p c - m a n s " ;
2023-06-06 15:01:28 +00:00
}