TechnitiumSoftware/DnsServer · error · ArgumentOutOfRangeException

Invalid EDNS UDP payload size: valid range is 512-4096 bytes

Error message

Invalid EDNS UDP payload size: valid range is 512-4096 bytes.

What it means

Thrown by the UdpPayloadSize property setter when the value is below 512 or above 4096 bytes. This controls the EDNS(0) UDP payload size advertised in DNS responses; values below 512 would break baseline DNS and values above 4096 risk IP fragmentation issues on the network.

Source

Thrown at DnsServerCore/Dns/DnsServer.cs:7292

                            else
                                UdpClientConnection.DisposeSocketPool();
                        }
                        catch (Exception ex)
                        {
                            _log.Write(ex);
                        }
                    });
                }
            }
        }

        public ushort UdpPayloadSize
        {
            get { return _udpPayloadSize; }
            set
            {
                if ((value < 512) || (value > 4096))
                    throw new ArgumentOutOfRangeException(nameof(UdpPayloadSize), "Invalid EDNS UDP payload size: valid range is 512-4096 bytes.");

                _udpPayloadSize = value;
            }
        }

        public bool DnssecValidation
        {
            get { return _dnssecValidation; }
            set
            {
                if (_dnssecValidation != value)
                {
                    if (!_dnssecValidation)
                        _cacheZoneManager.Flush(); //flush cache to remove non validated data

                    _dnssecValidation = value;
                }
            }

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Set UdpPayloadSize to a value between 512 and 4096 (1232 is the common recommended value to avoid fragmentation).
  2. If loading from config, clamp the value before assignment: Math.Clamp(value, 512, 4096).

Example fix

// before
server.UdpPayloadSize = 8192; // throws

// after
server.UdpPayloadSize = 1232; // DNS Flag Day recommended
Defensive patterns

Strategy: validation

Validate before calling

ushort safeSize = (ushort)Math.Clamp(value, 512, 4096);
server.UdpPayloadSize = safeSize;

Type guard

static bool IsValidUdpPayloadSize(ushort s) => s >= 512 && s <= 4096;

Try / catch

try { server.UdpPayloadSize = value; }
catch (ArgumentOutOfRangeException) { server.UdpPayloadSize = 1232; }

Prevention

When it happens

Trigger: Setting server.UdpPayloadSize to any ushort value < 512 or > 4096.

Common situations: Tuning for large DNS responses (DNSSEC) by increasing payload; loading a config with an out-of-range value; copying a value from another DNS implementation with different bounds.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/870556ddb3210448. Report an issue: GitHub.