parameterize main nic and dmz bridge interface names

firewall some services to particular interfaces
This commit is contained in:
Pim Kunis 2024-01-13 00:05:25 +01:00
parent 6bcdd774ac
commit 76501362f7
5 changed files with 44 additions and 28 deletions

View file

@ -50,7 +50,7 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ networking.firewall.interfaces.${config.lab.networking.dmzBridgeName}.allowedTCPPorts = [
2049 # NFS 2049 # NFS
5432 # PostgeSQL 5432 # PostgeSQL
111 # NFS 111 # NFS

View file

@ -47,6 +47,22 @@ in {
The IPv4 address of the DHCP server on the DMZ network. The IPv4 address of the DHCP server on the DMZ network.
''; '';
}; };
dmzBridgeName = lib.mkOption {
default = "bridgedmz";
type = lib.types.str;
description = ''
The name of the DMZ bridge.
'';
};
mainNicNamePattern = lib.mkOption {
default = "en*";
type = lib.types.str;
description = ''
Pattern to match the name of this machine's main NIC.
'';
};
}; };
config = { config = {
@ -77,18 +93,14 @@ in {
"20-bridgedmz" = { "20-bridgedmz" = {
netdevConfig = { netdevConfig = {
Kind = "bridge"; Kind = "bridge";
Name = "bridgedmz"; Name = cfg.dmzBridgeName;
# TODO: This does not seem to work? Unsure what the problem is.
# We don't necessary need this though: we simply use DNS as the host.
# MACAddress = lib.mkIf cfg.allowDMZConnectivity "CA:FE:C0:FF:EE:0A";
# MACAddress = "ca:fe:c0:ff:ee:0a";
}; };
}; };
}; };
networks = { networks = {
"30-main-nic" = { "30-main-nic" = {
matchConfig.Name = "en*"; matchConfig.Name = cfg.mainNicNamePattern;
vlan = [ "vlandmz" ]; vlan = [ "vlandmz" ];
networkConfig = { networkConfig = {
@ -103,12 +115,12 @@ in {
networkConfig = { networkConfig = {
IPv6AcceptRA = false; IPv6AcceptRA = false;
LinkLocalAddressing = "no"; LinkLocalAddressing = "no";
Bridge = "bridgedmz"; Bridge = cfg.dmzBridgeName;
}; };
}; };
"40-bridgedmz" = { "40-bridgedmz" = {
matchConfig.Name = "bridgedmz"; matchConfig.Name = cfg.dmzBridgeName;
linkConfig.RequiredForOnline = "carrier"; linkConfig.RequiredForOnline = "carrier";
networkConfig = { networkConfig = {

View file

@ -21,7 +21,7 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
networking.firewall = { networking.firewall.interfaces.${config.lab.networking.dmzBridgeName} = {
allowedTCPPorts = [ 53 5353 ]; allowedTCPPorts = [ 53 5353 ];
allowedUDPPorts = [ 53 67 5353 ]; allowedUDPPorts = [ 53 67 5353 ];
}; };

View file

@ -4,34 +4,38 @@ let
in in
{ {
no-resolv = true; no-resolv = true;
server = [
dmzRouterIPv4
"/geokunis2.nl/${dmzDHCPIPv4}"
"/kun.is/${dmzDHCPIPv4}"
];
local = "/dmz/"; local = "/dmz/";
dhcp-fqdn = true; dhcp-fqdn = true;
no-hosts = true; no-hosts = true;
expand-hosts = true; expand-hosts = true;
domain = "dmz"; domain = "dmz";
dhcp-authoritative = true; dhcp-authoritative = true;
dhcp-range = [
"192.168.30.50,192.168.30.127,15m"
];
dhcp-host = [
"b8:27:eb:b9:ab:e2,esrom"
"ca:fe:c0:ff:ee:08,maestro,${dockerSwarmInternalIPv4}"
];
dhcp-option = [
"3,${dmzRouterIPv4}"
"option:dns-server,${dmzRouterIPv4}"
];
ra-param = "*,0,0"; ra-param = "*,0,0";
alias = "${publicIPv4},${dockerSwarmInternalIPv4}"; alias = "${publicIPv4},${dockerSwarmInternalIPv4}";
log-dhcp = true; log-dhcp = true;
log-queries = true; log-queries = true;
# interface-name = "hermes.dmz,ens3";
port = "5353"; port = "5353";
server = [
dmzRouterIPv4
"/geokunis2.nl/${dmzDHCPIPv4}"
"/kun.is/${dmzDHCPIPv4}"
];
dhcp-range = [
"192.168.30.50,192.168.30.127,15m"
];
dhcp-host = [
"b8:27:eb:b9:ab:e2,esrom"
"ca:fe:c0:ff:ee:08,maestro,${dockerSwarmInternalIPv4}"
];
dhcp-option = [
"3,${dmzRouterIPv4}"
"option:dns-server,${dmzRouterIPv4}"
];
address = [ address = [
"/ns.pizzapim.nl/ns.geokunis2.nl/${dmzDHCPIPv4}" "/ns.pizzapim.nl/ns.geokunis2.nl/${dmzDHCPIPv4}"
]; ];

View file

@ -10,7 +10,7 @@ in {
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ 5432 ]; networking.firewall.interfaces.${config.lab.networking.mainNicNamePattern}.allowedTCPPorts = [ 5432 ];
services.postgresql = { services.postgresql = {
enable = true; enable = true;