nixos/firewall: DNAT by IP instead of incoming interface

This commit is contained in:
Jack O'Sullivan 2023-04-21 15:44:30 +01:00
parent 4d8935ffd6
commit d427de57fe
2 changed files with 6 additions and 5 deletions

View File

@ -324,6 +324,7 @@ in
nat = {
enable = true;
externalInterface = "wan";
externalIP = assignments.internal.ipv4.address;
forwardPorts = [
{
port = "http";

View File

@ -62,7 +62,7 @@ in
nat = with options.networking.nat; {
enable = mkBoolOpt' true "Whether to enable IP forwarding and NAT.";
inherit externalInterface;
inherit externalInterface externalIP;
forwardPorts = mkOpt' (listOf (submodule forwardOpts)) [ ] "List of port forwards.";
};
};
@ -143,8 +143,8 @@ in
(mkIf cfg.nat.enable {
assertions = [
{
assertion = (cfg.nat.forwardPorts != [ ]) -> (cfg.nat.externalInterface != null);
message = "my.firewall.nat.forwardPorts requires my.firewall.nat.externalInterface";
assertion = with cfg.nat; (forwardPorts != [ ]) -> (externalInterface != null && externalIP != null);
message = "my.firewall.nat.forwardPorts requires my.firewall.nat.external{Interface,IP}";
}
];
@ -198,8 +198,8 @@ in
}
chain prerouting {
${optionalString
(cfg.nat.externalInterface != null)
"iifname ${cfg.nat.externalInterface} jump port-forward"}
(cfg.nat.externalIP != null)
"ip daddr ${cfg.nat.externalIP} jump port-forward"}
}
}
'';