gclayburg / synology-diskstation-scripts

Update Synology DNS records from DHCP IP address reservation
168 stars 41 forks source link

Same device appears twice in the dns list #27

Open HHasenack opened 6 years ago

HHasenack commented 6 years ago

Which is caused eg by my phone sometimes using my 5G wifi and other times my 2G4 network. The Synology DNS has problems coping with this, causing other devices to not resolved. (the devices appearing after the double entry)

Solution would be to ensure entries are uniwue, and in case of double dhcp entries, use the entry with the longest remaining lease time ( thus the youngest, or the bottommost?)

I am quite a noob at shell programming, otherwise I would try fixing this myself 🈂️ image

the galaxy-a5-hans device also appears on my dns server twice (no screenshot since I dropped one to get it working again)

HHasenack commented 6 years ago

By now I have changed the lease time of my DHCP server to 1 hour, which greatly reduces the # of double entries. But for some strange reason, still double entries appear in my DNS server which I cannot explain.

image

Where my DHCP server looks quite normal like this: image

Here's whats in the scrips folder: the b00 folders were for the previous starts of the dns update script. scripts.zip

HHasenack commented 6 years ago

ah sorry hit the wrong button :( hence reopened.

gclayburg commented 6 years ago

I haven't looked at this in quite a while, but I would do 2 things first in troubleshooting this:

  1. make sure you are using the latest scripts in this repo. There were some fixes some time back that addressed some issues like this.
  2. manually delete some of the DNS entries that you know are no longer valid.
HHasenack commented 6 years ago

1 I downloaded the scrips from this repo about 3 days ago, so it is failrly up-to-date 2 What I did (several times) to get rid of the invalid entries was

After doing this, initially all looks well. AFter a day the extra entries appeared. Maybe the attachment (zip) I sent in the 2nd comment can shed some light on it for you. It contanis the dns_backups folder from my system.

I'll do it once more now my dhcp client leases are more or less "clean". I'll let you know.

Otherwise, I'll have to deep-dive into shell script debugging 😱

Regards

Hans

gclayburg commented 6 years ago

Ok, There could likely be an issue if you have the same hostname showing up as 2 different IP address leases. This isn't an issue I've run across before. Pull requests are certainly welcome!

HHasenack commented 6 years ago

Being an experienced programmer (C#, Java, Delphi, C, c++) myself, I thought I'm gonna fix this. But this is really tough. Well... for me it is.

I have no clue where to start. At line 112 is comments that it sorts and removes duplicates, but I cant see where and how.

IMO the entries having the same hostname should be ruled out based on how old the DHCP leases are, or if thats not possible the longest remaining lease time. This is not availble in the leases file unfortunately.

Also I think it would be a lot better if the DNS TTL matches the remaining DHCP lease time. Now, my DNS TTL is 86400 where my DCP lease time is about 3600. I Changed the "hardcoded" value of 86400 into 3600 around line 120. I think should actually be taken from the dhcpd.conf file.

How to accomplish this? - clueless :( Hints and explanations are welcome!

HHasenack commented 6 years ago

You knoiw what... I' try to put it into a c# app , startable using mono or mono-service. That will be a nice excercise to do cross platform development, services and c#. I'll publish it on github if I am happy with the result and let you know. At least your scripts pointed me the doirection of a viable solution, thanks!

gclayburg commented 6 years ago

That would be interesting, @HHasenack . The way I ended up working on this and troubleshooting was basically breaking the script down to individual awk scripts and running them separately on the synology to see what it does. Some troubleshooting can also be done on a normal linux install, but some things are just weird in synology world. They use a customized busybox and not all tools are available.

BTW - the sorting and removing duplicates is implemented on line 139: sort | cut -f 2- | uniq

try running that awk script by itself and see what it does

HHasenack commented 6 years ago

interesting ebough the double source lines appear originate from reading dhcp-leases.log as well as dhcpd.conf.leases which contain the same data on ly system (DSM6).

I would expect to sort / uniq to drop these duplicates. I'll studdy the man pages for these. As said before, I am a noob at shell script programming, and the "nested" awk command is a bit above my level 📦

I'll try executing the steps one by one to take a look at the intermediate results, but am stil unsure how to do that ...

I have started my C# app, and created some models for the DNS and DHCP entrries. Next stop: read the entries them from the approipriate files, After that update DNS entries collection using the DHCP entries collection (and drop missing and oldest duplicates entries) from my DNS entries collection and finally write out a new DNS file and notify the DNS server abiout the new DNS file.

Quite a challenge, but a good exercise.

HHasenack commented 6 years ago

T think I have managed to work around the problem. Problem was actually caused by de script merghing in the static dhcp leases with the dhcp log file, in which the leases were duplicated (DSM 6.0)

I have attached the modified script in here as I dont want to break code for older releases. No clue how to check for DSM versiuon. Changes are marked using HH20180918 diskstation_dns_modify.sh.txt

RichSteele commented 2 years ago

@HHasenack just a huge THANK YOU for posting your fix to this problem. I'd been getting duplicate entries for a while, very frustrating. I installed your patched version a few weeks ago and NO MORE DUPES!