TechnitiumSoftware / DnsServer

Technitium DNS Server
https://technitium.com/dns/
GNU General Public License v3.0
4.47k stars 431 forks source link

Devices with no hostname cause DHCP server not to bind on server restart #69

Closed PonchoPowers closed 4 years ago

PonchoPowers commented 5 years ago

An exception is thrown when enabling the default scope after a reboot of the physical server when devices with no hostname have already been offered a lease that is now saved to the config.

I've tracked it down to the following:

DnsClient.IsDomainNameValid(name, true);

image

image

The lease hostname is null when saved...

image

As you can see in the following, I have two devices on my network which don't have a hostname, not sure if this is normal or not:

image

PonchoPowers commented 5 years ago

The following suggests that the domain if empty is the root zone, but in this cause the same method is being used to test hostnames for devices.

if (domain.Length == 0)
  return true; //domain is root zone

So I'm not really sure how you want to fix this as I'm not sure the following is really valid either.

if (domain == null)
  return **???**;

Setting HostName to an empty string would be a hack as it is null as there is no hostname.

So I propose the following fixes:

Change:

_authoritativeZoneRoot.SetRecords(lease.HostName, DnsResourceRecordType.A, scope.DnsTtl, new DnsResourceRecordData[] { new DnsARecord(lease.Address) });

to:

if (lease.HostName != null)
  _authoritativeZoneRoot.SetRecords(lease.HostName, DnsResourceRecordType.A, scope.DnsTtl, new DnsResourceRecordData[] { new DnsARecord(lease.Address) });

And change:

_authoritativeZoneRoot.SetRecords(Scope.GetReverseZone(lease.Address, 32), DnsResourceRecordType.PTR, scope.DnsTtl, new DnsResourceRecordData[] { new DnsPTRRecord(lease.HostName) });

to:

if (lease.HostName != null)
  _authoritativeZoneRoot.SetRecords(Scope.GetReverseZone(lease.Address, 32), DnsResourceRecordType.PTR, scope.DnsTtl, new DnsResourceRecordData[] { new DnsPTRRecord(lease.HostName) });

You might want to check this first to make sure it doesn't break anything as my knowledge of network technology is rubbish.

ShreyasZare commented 5 years ago

Thanks for the debugging. This can be fixed in UpdateDnsAuthZone() with below check:

if (string.IsNullOrEmpty(lease.HostName))
                return;
PonchoPowers commented 5 years ago

Just tested, the fix you proposed works for me, much simpler than my solution.

ShreyasZare commented 4 years ago

Technitium DNS Server v4.1 is now available that fixes this issue.