Merge pull request 'fix(tailscale-router): actually insert MASQUERADE rule via extraCommands' (#70) from worktree-lovely-spinning-bubble into main
Check NixOS configurations / eval-hosts (push) Successful in 10m34s

Reviewed-on: #70
This commit was merged in pull request #70.
This commit is contained in:
2026-07-25 23:56:11 +00:00
+23 -11
View File
@@ -16,17 +16,29 @@
# Must also be approved in the Tailscale admin console (Machines → Edit route settings). # Must also be approved in the Tailscale admin console (Machines → Edit route settings).
services.tailscale.extraUpFlags = [ "--advertise-routes=${vars.lanCidr}" ]; services.tailscale.extraUpFlags = [ "--advertise-routes=${vars.lanCidr}" ];
# Forwarded subnet-router traffic arrives on tailscale0 already networking = {
# tailscale-authenticated -- the firewall's normal per-port allow-list # SNAT traffic from LAN machines going out through Tailscale so the remote
# would otherwise drop it. Standard NixOS/Tailscale subnet-router guidance. # peer sees it sourced from this router's Tailscale IP (100.x.x.x) rather
networking.firewall.trustedInterfaces = [ "tailscale0" ]; # than a raw LAN IP. Without this, Tailscale drops the forwarded packets
# because the source is not a recognised Tailscale address.
#
# networking.nat.externalInterface alone does not insert a MASQUERADE rule
# (it only does so when internalInterfaces is also set). We use
# extraCommands to add the rule into the nixos-nat-post chain that
# networking.nat.enable creates, and extraStopCommands to clean it up.
nat.enable = true;
# SNAT traffic from LAN machines going out through Tailscale so the remote firewall = {
# peer sees it sourced from this router's Tailscale IP (100.x.x.x) rather # Forwarded subnet-router traffic arrives on tailscale0 already
# than a raw LAN IP. Without this, Tailscale drops the forwarded packets # tailscale-authenticated -- the firewall's normal per-port allow-list
# because the source is not a recognised Tailscale address. # would otherwise drop it. Standard NixOS/Tailscale subnet-router guidance.
networking.nat = { trustedInterfaces = [ "tailscale0" ];
enable = true; extraCommands = ''
externalInterface = "tailscale0"; iptables -t nat -A nixos-nat-post -s ${vars.lanCidr} -o tailscale0 -j MASQUERADE
'';
extraStopCommands = ''
iptables -t nat -D nixos-nat-post -s ${vars.lanCidr} -o tailscale0 -j MASQUERADE 2>/dev/null || true
'';
};
}; };
} }