netbirdio/netbird · error

delete inbound DNAT rule

Error message

delete inbound DNAT rule: %w

What it means

Deleting the inbound DNAT rule from the nat table failed in RemoveInboundDNAT. The bookkeeping entry is removed only on successful delete, so the kernel rule may outlive the manager's knowledge of it if this persists.

Solutions

  1. Manually delete the matching PREROUTING DNAT rule
  2. Restart the daemon to reconcile kernel state
  3. Address the underlying iptables failure
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at client/firewall/iptables/router_linux.go:1033 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/2bd9f892df12a49d. Report an issue: GitHub.

Appendix: source

Thrown at client/firewall/iptables/router_linux.go:1033

		rule:  dnatRule,
	}

	if err := r.iptablesClient.Append(ruleInfo.table, ruleInfo.chain, ruleInfo.rule...); err != nil {
		return fmt.Errorf("add inbound DNAT rule: %w", err)
	}
	r.rules[ruleID] = ruleInfo.rule

	r.updateState()
	return nil
}

// RemoveInboundDNAT removes an inbound DNAT rule.
func (r *router) RemoveInboundDNAT(localAddr netip.Addr, protocol firewall.Protocol, originalPort, translatedPort uint16) error {
	ruleID := fmt.Sprintf("inbound-dnat-%s-%s-%d-%d", localAddr.String(), protocol, originalPort, translatedPort)

	if dnatRule, exists := r.rules[ruleID]; exists {
		if err := r.iptablesClient.Delete(tableNat, chainRTRDR, dnatRule...); err != nil {
			return fmt.Errorf("delete inbound DNAT rule: %w", err)
		}
		delete(r.rules, ruleID)
	}

	r.updateState()
	return nil
}

// ensureNATOutputChain lazily creates the OUTPUT NAT chain and jump rule on first use.
func (r *router) ensureNATOutputChain() error {
	if _, exists := r.rules[jumpNatOutput]; exists {
		return nil
	}

	chainExists, err := r.iptablesClient.ChainExists(tableNat, chainNATOutput)
	if err != nil {
		return fmt.Errorf("check chain %s: %w", chainNATOutput, err)
	}

View on GitHub (pinned to 93e97f4bf1)