Virtualization

KVM guests suffer one‑way UDP audio loss after nf_conntrack_udp timeout lowered on Linux NAT host

Environment

Environment

Ubuntu 22.04 host running KVM/QEMU with libvirt, guests NATed to external network via iptables MASQUERADE on host. nf_conntrack_udp_timeout has been reduced from default (30s) to 10s system-wide to try to reduce conntrack table growth.

Symptoms

Symptoms

VoIP and game UDP traffic from guests experiences one-way audio or packet loss after ~12 seconds of silence; after resuming traffic, audio returns but then drops again after similar intervals. ICMP pings sometimes show replies from remote but guests do not receive them intermittently.

Observations

Observations

Host conntrack entries for guest flows disappear ~10–12s after last packet when timeout is set low. Restoring default nf_conntrack_udp_timeout immediately restores stable connectivity. iptables NAT entries show mappings created but then removed when conntrack entry expires. No CPU or memory pressure observed on host.

Already attempted

Already attempted

Raised nf_conntrack table size; temporarily set timeout back to default which fixed the issue in quick test. Tried pinning flows with conntrack --helper but not used for these UDP flows. No asymmetric routing present; masquerade rules correct.

Question

Question

Why do UDP flows to/from guests drop when UDP conntrack timeout is shortened, and what is the safe way to fix this while keeping conntrack resource usage reasonable?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
juliajava Answer
user
Posted 4w ago • 0 confirmations

When you shorten the UDP conntrack timeout, the host removes NAT state for idle UDP flows; if a remote peer sends packets after the mapping expired, the host has nowhere to forward them and you see one‑way audio. Easiest fix: raise nf_conntrack_udp_timeout back to 30s (or 60–120s for VoIP), or implement light keepalives from guests so mappings stay alive. If conntrack memory is a concern, increase nf_conntrack_max and monitor table usage; alternatively, move guests to routed networking to avoid host NAT. All changes are reversible: set the timeout back and confirm audio stability or revert nf_conntrack_max if memory pressure appears.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

nf_conntrack_udp_timeout set too low causing NAT mapping expiry while remote still sends packets after idle periods 95%
Conntrack table churn due to many short-lived flows combined with aggressive GC causing premature removal 45%
Offloading (GRO/GSO) or iptables conntrack helpers interfering with correct tracking for encapsulated guest packets 30%

Summary

Shortening nf_conntrack_udp_timeout causes NAT mappings to be removed while a flow remains 'idle' longer than the timeout; when remote sends packets after mapping expiry, the host lacks the NAT mapping to forward them to the guest, producing one-way loss. KVM/NAT scenarios rely on conntrack entries to maintain NAT state. Lowering timeout below expected idle intervals for protocols like VoIP or games triggers this behavior. Restoring timeout fixed it, indicating conntrack timeout was causal.

Suggested Fixes

Diagnostic step 1
Increase nf_conntrack_udp_timeout to the upstream default (e.g., 30s) or a value appropriate for the expected idle time of your UDP applications (60–120s for VoIP), then monitor conntrack table size.
Diagnostic step 2
If conntrack memory usage is the reason for lowering timeouts, raise nf_conntrack_max and ensure vm.max_map_count and net.netfilter settings allow the larger table, or implement per‑flow keepalive from guests to keep mappings alive.
Diagnostic step 3
Consider using hairpin NAT or a routed network for guests to avoid host NAT where possible; migrating guests to a routed setup eliminates NAT mapping expiry issues.

Continue troubleshooting

Matched from the title, description and tags