From a538f70bf7cc3d0535f1d5996eb8d807b988621e Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Thu, 17 Sep 2026 17:27:56 -0400 Subject: [PATCH] another attempt at fixing it --- modules/host.nix | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/host.nix b/modules/host.nix index 9e70f74..cd78f7a 100644 --- a/modules/host.nix +++ b/modules/host.nix @@ -746,15 +746,22 @@ in networkConfig.Bridge = net.bridge; }; - # ip_forward is required for the guest to reach the internet and for - # inbound DNAT to work. networking.nat used to set this implicitly, but - # its nftables translation of forwardPorts is unreliable when - # networking.nftables.enable = true, so we manage NAT directly. - boot.kernel.sysctl."net.ipv4.ip_forward" = true; + # ip_forward: use the same sysctl keys networking.nat used (mkOverride 99 + # so they win over any lower-priority defaults elsewhere in the config). + boot.kernel.sysctl."net.ipv4.conf.all.forwarding" = lib.mkOverride 99 true; + boot.kernel.sysctl."net.ipv4.conf.default.forwarding" = lib.mkOverride 99 true; # Masquerade outbound guest traffic and DNAT published ports inbound. # We use an explicit nftables table instead of networking.nat so that the # rules are certain to appear in the prerouting/postrouting hooks. + # + # NOTE: DNAT uses 'iifname != bridge' rather than 'iifname externalInterface'. + # Scoping to a single interface means traffic arriving on any other path + # (Tailscale, a second NIC, WiFi, loopback) silently skips DNAT: the + # packet stays addressed to the host's own IP, falls into the INPUT chain, + # and gets dropped because those ports are not in allowedTCPPorts. + # Excluding only the bridge itself prevents loops from inside the guest + # while covering every legitimate external path. networking.nftables.tables.hermenix-nat = lib.mkIf (net.externalInterface != null) { family = "ip"; content = '' @@ -762,7 +769,7 @@ in type nat hook prerouting priority dstnat; '' + lib.concatMapStrings (s: '' - iifname "${net.externalInterface}" ${s.proto} dport ${toString s.hostPort} dnat to ${net.guestAddress}:${toString s.guestPort} + iifname != "${net.bridge}" ${s.proto} dport ${toString s.hostPort} dnat to ${net.guestAddress}:${toString s.guestPort} '') cfg.publish + '' }