{"record":{"id":"3dbe1a976d98b082","repo":"TechnitiumSoftware/DnsServer","slug":"scope-with-overlapping-range-already-exists-exis","errorCode":null,"errorMessage":"Scope with overlapping range already exists: {existingScope.StartingAddress}-{existingScope.EndingAddress}","messagePattern":"Scope with overlapping range already exists: (.+?)-(.+?)","errorType":"exception","errorClass":"DhcpServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dhcp/DhcpServer.cs","lineNumber":1231,"sourceCode":"            catch (Exception ex)\n            {\n                _log.Write(dhcpEP, \"DHCP Server failed to deactivate scope: \" + scope.Name, ex);\n\n                if (throwException)\n                    throw;\n            }\n\n            return false;\n        }\n\n        private async Task LoadScopeAsync(Scope scope, bool waitForInterface)\n        {\n            foreach (KeyValuePair<string, Scope> entry in _scopes)\n            {\n                Scope existingScope = entry.Value;\n\n                if (existingScope.IsAddressInRange(scope.StartingAddress) || existingScope.IsAddressInRange(scope.EndingAddress))\n                    throw new DhcpServerException(\"Scope with overlapping range already exists: \" + existingScope.StartingAddress.ToString() + \"-\" + existingScope.EndingAddress.ToString());\n            }\n\n            if (!_scopes.TryAdd(scope.Name, scope))\n                throw new DhcpServerException(\"Scope with same name already exists.\");\n\n            if (scope.Enabled)\n            {\n                if (!await ActivateScopeAsync(scope, waitForInterface))\n                    scope.SetEnabled(false);\n            }\n\n            _log.Write(\"DHCP Server successfully loaded scope: \" + scope.Name);\n        }\n\n        private void UnloadScope(Scope scope, bool removeDnsEntries)\n        {\n            if (scope.Enabled)\n                DeactivateScope(scope, removeDnsEntries, false);","sourceCodeStart":1213,"sourceCodeEnd":1249,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dhcp/DhcpServer.cs#L1213-L1249","documentation":"LoadScopeAsync rejects a new scope because its range overlaps an existing one. Overlap is detected when the new scope's starting OR ending address falls inside an existing scope's range (IsAddressInRange). This prevents two DHCP scopes handing out the same addresses.","triggerScenarios":"Adding a scope where existingScope.IsAddressInRange(newScope.StartingAddress) || existingScope.IsAddressInRange(newScope.EndingAddress) is true for any already-loaded scope.","commonSituations":"Creating a second scope that extends or sits inside the first. Mistyped gateway/range. Splitting a /24 into two scopes with overlapping boundaries. Importing scopes from another server.","solutions":["Adjust the new scope's starting/ending addresses so they do not fall inside any existing scope range.","Delete or shrink the conflicting existing scope first.","Recheck the subnet math: ensure ranges are disjoint (end of A < start of B)."],"exampleFix":"// before\nvar scopeA = new Scope('A', Parse('192.168.1.100'), Parse('192.168.1.200'), Parse('255.255.255.0'), ...);\nvar scopeB = new Scope('B', Parse('192.168.1.150'), Parse('192.168.1.250'), ...); // overlaps A\n// after: make ranges disjoint\nvar scopeB = new Scope('B', Parse('192.168.1.201'), Parse('192.168.1.250'), ...);","handlingStrategy":"validation","validationCode":"foreach (var kv in _dhcpServer.GetScopes())\n{\n    if (kv.Value.IsAddressInRange(scope.StartingAddress) || kv.Value.IsAddressInRange(scope.EndingAddress))\n        throw new InvalidOperationException($\"Range overlaps scope '{kv.Key}'\");\n}","typeGuard":"static bool RangeIsDisjoint(Scope existing, IPAddress start, IPAddress end)\n    => !existing.IsAddressInRange(start) && !existing.IsAddressInRange(end);","tryCatchPattern":"try { await _dhcpServer.LoadScopeAsync(scope, true); }\ncatch (DhcpServerException ex) when (ex.Message.Contains(\"overlapping range\"))\n{ /* read reported range from message, adjust new scope boundaries */ }","preventionTips":["Plan disjoint address pools across scopes.","Validate overlap against live scopes before persisting.","Treat exclusions and ranges together when partitioning a subnet."],"tags":["dhcp","scope","validation","configuration"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}