TechnitiumSoftware/DnsServer · error · ArgumentException

The address must be an IPv4 address: {ip}

Error message

The address must be an IPv4 address: {ip}

What it means

ValidateIpv4 (collection overload) checks every IPAddress in a collection is IPv4 (AddressFamily == InterNetwork). Any IPv6 or other family member triggers ArgumentException with the offending IP and paramName.

Source

Thrown at DnsServerCore/Dhcp/Scope.cs:456

        }

        private static bool IsAddressInRange(IPAddress address, IPAddress startingAddress, IPAddress endingAddress)
        {
            uint addressNumber = address.ConvertIpToNumber();
            uint startingAddressNumber = startingAddress.ConvertIpToNumber();
            uint endingAddressNumber = endingAddress.ConvertIpToNumber();

            return (startingAddressNumber <= addressNumber) && (addressNumber <= endingAddressNumber);
        }

        private static void ValidateIpv4(IReadOnlyCollection<IPAddress> value, string paramName)
        {
            if (value is not null)
            {
                foreach (IPAddress ip in value)
                {
                    if (ip.AddressFamily != AddressFamily.InterNetwork)
                        throw new ArgumentException("The address must be an IPv4 address: " + ip.ToString(), paramName);
                }
            }
        }

        private static void ValidateIpv4(IPAddress value, string paramName)
        {
            if ((value is not null) && (value.AddressFamily != AddressFamily.InterNetwork))
                throw new ArgumentException("The address must be an IPv4 address: " + value.ToString(), paramName);
        }

        #endregion

        #region private

        private async Task<AddressStatus> IsAddressAvailableAsync(IPAddress address)
        {
            if (address.Equals(_routerAddress))
                return AddressStatus.FALSE;

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Filter the collection to IPv4 only before assigning (where(a => a.AddressFamily == InterNetwork)).
  2. Remove IPv6 entries from the scope's DNS server / gateway / exclusions lists.
  3. Use a dedicated IPv6 scope type if IPv6 DHCP is needed.

Example fix

// before
scope.DnsServers = System.Net.Dns.GetHostAddresses('resolver'); // may include IPv6
// after
scope.DnsServers = System.Net.Dns.GetHostAddresses('resolver')
    .Where(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToList();
Defensive patterns

Strategy: validation

Validate before calling

if (addresses.Any(a => a.AddressFamily != AddressFamily.InterNetwork))
    throw new ArgumentException("Only IPv4 addresses are allowed", nameof(addresses));

Type guard

static bool AllIPv4(IEnumerable<IPAddress> ips) => ips == null || ips.All(a => a.AddressFamily == AddressFamily.InterNetwork);

Try / catch

try { scope.DnsServers = list; }
catch (ArgumentException ex) when (ex.Message.Contains("IPv4"))
{ /* filter list to IPv4, retry */ }

Prevention

When it happens

Trigger: Setting an IPv4-only scope property (e.g. DNS servers / gateways list) with a collection containing an IPAddress whose AddressFamily != InterNetwork.

Common situations: Mixing IPv6 addresses (e.g. '::1' or link-local fe80::) into an IPv4-only DHCP scope config. Auto-detecting system resolvers and passing an IPv6 one. Resolving a hostname to IPv6.

Related errors


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