another attempt at fixing it
This commit is contained in:
1 parent
4313e043bc
commit
a538f70bf7
1 file changed
+13
-6
+13
-6
@@ -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
|
||||
+ ''
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user