Reply
Highlighted
New Member
Posts: 30
Registered: ‎07-03-2014
Kudos: 5
Accepted Solution

hostfile-update enable doesn't clear expired leases

I have hostfile-update enabled on my DHCP server service and it initially is seemed to working fine.

However, after a while I noticed that expired DHCP leases remain in the hosts file, which clutters the file.

 

my current hosts file:

Admin@EdgeRouter:/etc$ more hosts

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.1.1        EdgeRouter      #vyatta entry
172.16.0.20      ds1511          #vyatta entry
172.16.0.20      laibalion.synology.me           #vyatta entry
172.16.0.85      Vangrieken      #on-dhcp-event 60:45:bd:7e:74:5c
172.16.0.86      PC_van_Jos      #on-dhcp-event 0:26:5e:5c:24:b9
172.16.0.87      Android_355067040082356         #on-dhcp-event 7c:61:93:a7:bc:9
4
172.16.0.88      iPhonevanJannes         #on-dhcp-event 48:74:6e:c9:b2:91
172.16.0.78      android-89ba5dee3df63abe        #on-dhcp-event 20:54:76:70:6e:5
5
172.16.0.51      Surface-Geert   #on-dhcp-event 60:45:bd:67:a:6
172.16.0.89      android-ea1f87e87ffd8dda        #on-dhcp-event c:96:bf:e1:cd:81
172.16.0.84      android-5a651c5cb43957cf        #on-dhcp-event c4:43:8f:a9:19:b
c
172.16.0.71      DUNE    #on-dhcp-event 0:16:e8:7d:2d:75
172.16.0.68      PC-EVI  #on-dhcp-event 0:25:22:64:3a:8f
172.16.0.76      Surface-Evi     #on-dhcp-event 50:1a:c5:e:cf:2
172.16.0.77      Brother_MFC-J6510W      #on-dhcp-event 30:5:5c:b:f3:a7
172.16.0.53      Lumia-920-Geert         #on-dhcp-event a8:44:81:a3:12:c4
172.16.0.62      Geert-Desktop   #on-dhcp-event 90:2b:34:57:34:c0
172.16.0.80      Unifi-AP-LR     #on-dhcp-event 24:a4:3c:98:25:eb

 

my current DCHP leases:

Admin@EdgeRouter:/etc$ show dhcp leases
IP address      Hardware Address   Lease expiration     Pool       Client Name
----------      ----------------   ----------------     ----       -----------
172.16.0.53     a8:44:81:a3:12:c4  2014/08/19 16:15:16  EdgeRouter-DHCP Lumia-920-Geert
172.16.0.61     74:e5:43:d3:4d:68  2014/08/18 20:19:33  EdgeRouter-DHCP Geert-Desktop
172.16.0.68     00:25:22:64:3a:8f  2014/08/19 06:23:42  EdgeRouter-DHCP PC-EVI
172.16.0.71     00:16:e8:7d:2d:75  2014/08/18 20:27:43  EdgeRouter-DHCP DUNE
172.16.0.76     50:1a:c5:0e:cf:02  2014/08/19 06:44:53  EdgeRouter-DHCP Surface-Evi

 

my current DHCP server service configuration:

Admin@EdgeRouter# show service dhcp-server
 disabled false
 hostfile-update enable
 shared-network-name EdgeRouter-DHCP {
     authoritative enable
     subnet 172.16.0.0/24 {
         default-router 172.16.0.1
         dns-server 172.16.0.1
         lease 86400
         start 172.16.0.50 {
             stop 172.16.0.254
         }
         static-mapping ATGS950-24 {
             ip-address 172.16.0.10
             mac-address EC:CD:6D:81:A5:CC
         }
         static-mapping Brother_MFC-J6510W {
             ip-address 172.16.0.77
             mac-address 30:05:5c:0b:f3:a7
         }
         static-mapping DS1511 {
             ip-address 172.16.0.20
             mac-address 00:11:32:0b:d6:2b
         }
         static-mapping Geert-Desktop {
             ip-address 172.16.0.62
             mac-address 90:2b:34:57:34:c0
         }
         static-mapping Unifi-AP-LR {
             ip-address 172.16.0.80
             mac-address 24:a4:3c:98:25:eb
         }
     }
 }

 

As you can see, there a bunch of #on-dhcp-event entries present that are no longer valid.

Is this expected behavior? Or is a bug? Or perhaps my configuration is wrong?

 

Any help is appreciated.


Accepted Solutions
Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5467
Solutions: 1656
Contributions: 2

Re: hostfile-update enable doesn't clear expired leases

Yeah in that case we'll need to see if we can replicate the issue here and look into it. Thanks for reporting.

View solution in original post


All Replies
Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5467
Solutions: 1656
Contributions: 2

Re: hostfile-update enable doesn't clear expired leases

Which version is the router running? If it's not the latest v1.5.0, you probably want to upgrade to 1.5.0 first since there were quite a few enhancements/fixes for hostfile-update. If it's already 1.5.0 then that sounds like  it could be a bug and we need to look into it.

New Member
Posts: 30
Registered: ‎07-03-2014
Kudos: 5

Re: hostfile-update enable doesn't clear expired leases

Yup, I'm already running 1.5.0 on my router.
Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5467
Solutions: 1656
Contributions: 2

Re: hostfile-update enable doesn't clear expired leases

Yeah in that case we'll need to see if we can replicate the issue here and look into it. Thanks for reporting.

New Member
Posts: 3
Registered: ‎08-20-2014

Re: hostfile-update enable doesn't clear expired leases

[ Edited ]

I got the same problem, running 1.5. It does update existing entries on new leases, but does not clear expired non-renewed ones. For example, guests aren't cleared.

Also, I since added a ".lan" domain in my DHCP config, so old entries without ".lan" are not cleared either (even on renewed leases).

Hope it helps troubleshooting.

Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5467
Solutions: 1656
Contributions: 2

Re: hostfile-update enable doesn't clear expired leases

Could you clarify if you mean only some expired leases are not cleared (and some are)?

New Member
Posts: 3
Registered: ‎08-20-2014

Re: hostfile-update enable doesn't clear expired leases

Sorry for the delay.

 

In my case, expired leases never seems to get cleared from /etc/hosts.

If a host exists in /etc/hosts, it gets updated, it does not create a duplicate entry.

 

Here are my leases and my /etc/hosts.

 

Spoiler
admin@ubnt:~$ show dhcp leases
IP address      Hardware Address   Lease expiration     Pool       Client Name
----------      ----------------   ----------------     ----       -----------
192.168.2.100   00:1e:ec:55:91:c8  2014/08/29 20:27:22  LAN2       media-server
192.168.1.102   c4:85:08:a2:05:4e  2014/08/30 03:52:39  LAN1       JC-PC
192.168.1.148   64:20:0c:a5:e1:66  2014/08/30 03:53:00  LAN1       iPad-Mymy
192.168.1.149   20:d3:90:b7:b1:42  2014/08/30 03:53:20  LAN1       android-b0ca743b80f564dc
192.168.1.150   90:18:7c:4a:ed:2c  2014/08/29 23:29:13  LAN1       android-333d1108624b70cd
192.168.1.152   08:fc:88:99:99:3d  2014/08/29 20:30:37  LAN1       android-7adba05eb6886792
192.168.1.153   30:05:5c:48:ae:13  2014/08/30 03:52:27  LAN1       printer
192.168.1.154   00:1e:ec:55:91:c8  2014/08/30 03:52:32  LAN1       media-server

 

Spoiler
admin@ubnt:~$ cat /etc/hosts
127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

192.168.2.50     printer         #on-dhcp-event 30:5:5c:48:ae:13
192.168.1.10     UnifiAP         #on-dhcp-event 4:18:d6:a:5e:36
192.168.1.148    iPad-Mymy       #on-dhcp-event 64:20:c:a5:e1:66
192.168.1.102    JC-PC   #on-dhcp-event c4:85:8:a2:5:4e
192.168.1.105    media-server    #on-dhcp-event 0:16:ea:73:9d:a6
192.168.1.106    iPad-Nicole     #on-dhcp-event 64:20:c:97:4d:f6
127.0.1.1        ubnt    #vyatta entry
192.168.1.106    iPad-Nicole.lan         #on-dhcp-event 64:20:c:97:4d:f6
192.168.1.151    kali.lan        #on-dhcp-event 8:0:27:10:e0:4
192.168.1.104    android-51369a6fb7a16b9c.lan    #on-dhcp-event 5c:a:5b:65:7d:93
192.168.1.152    android-7adba05eb6886792.lan    #on-dhcp-event 8:fc:88:99:99:3d
192.168.1.150    android-333d1108624b70cd.lan    #on-dhcp-event 90:18:7c:4a:ed:2c
192.168.1.10     UnifiAP.lan     #on-dhcp-event 4:18:d6:a:5e:36
192.168.1.153    printer.lan     #on-dhcp-event 30:5:5c:48:ae:13
192.168.1.154    media-server.lan        #on-dhcp-event 0:1e:ec:55:91:c8
192.168.1.102    JC-PC.lan       #on-dhcp-event c4:85:8:a2:5:4e
192.168.1.148    iPad-Mymy.lan   #on-dhcp-event 64:20:c:a5:e1:66
192.168.1.149    android-b0ca743b80f564dc.lan    #on-dhcp-event 20:d3:90:b7:b1:42

 

That day, I plugged media-server from LAN2 to LAN1. You can see it has 2 leases, but only 1 entry in /etc/hosts (the most recent). The behavior is correct here.

 

The following entries are expired non-renewed leases, that I would expect to be cleared from /etc/hosts.

  • All entries that do not have the ".lan" prefix (the first 6 ones).
  • One of the android devices and iPad-Nicole.lan. This was a guest.
  • kali.lan, a virtual machine.

 

UnifiAP.lan and printer.lan are static mapping, so I guess these are correct.

 

Hope this helps!

 

Emerging Member
Posts: 59
Registered: ‎05-23-2014
Kudos: 3
Solutions: 2

Re: hostfile-update enable doesn't clear expired leases

As for the clearning of old hosts - it could be that the script that modifies the /etc/hosts file is trigered only when a DHCP event occurs (ie new lease). Simply put, if a MAC address simply disappears from the network, there is no event to trigger an update. I would think a weekly or monthly cron job could solve this, however it's a double edge sword since some users may not want to clear old data - especially in the event you only use a particular device every so often. If this is classified as a 'bug', I suggest having an on/off switch or making it so that the /etc/hosts file always matches the current DHCP leases, that way if you extend the lease time, you don't risk losing your hosts.

New Member
Posts: 3
Registered: ‎08-20-2014

Re: hostfile-update enable doesn't clear expired leases

[ Edited ]

@macguy25 wrote:

As for the clearning of old hosts - it could be that the script that modifies the /etc/hosts file is trigered only when a DHCP event occurs (ie new lease). Simply put, if a MAC address simply disappears from the network, there is no event to trigger an update.


There is no event for when a MAC address disappears from the network, but there might be one for when a DHCP lease expires. Can't confirm though.


@macguy25 wrote:

I would think a weekly or monthly cron job could solve this, however it's a double edge sword since some users may not want to clear old data - especially in the event you only use a particular device every so often.


Is there a use case where you would want to keep old data? If you need a device to always have the same IP, you should assign a static lease.

Member
Posts: 105
Registered: ‎03-28-2013
Kudos: 26
Solutions: 1

Re: hostfile-update enable doesn't clear expired leases

[ Edited ]

have also run into this same situation. I have set up some pcs initially with DHCP then converted them to static ips. The dhcp ip adresses didnt get removed. Im not sure what the proper way to clear out the host files is but what i've done to work around this is to run the following commands. It will clear all dhcp entries and leave static entires alone. Then when client get ne leases they will start populating again.

 

set service dhcp-server hostfile-update disable

commit

set service dhcp-server hostfile-update enable

commit

cat /etc/hosts

save

New Member
Posts: 30
Registered: ‎07-03-2014
Kudos: 5

Re: hostfile-update enable doesn't clear expired leases

Great, was also wondering about the same thing and I wasn't very comfortable with manually editing it with VI.

Thanks for the great find!

Emerging Member
Posts: 61
Registered: ‎09-10-2013
Kudos: 4
Solutions: 1

Re: hostfile-update enable doesn't clear expired leases

I am seeing the same issue. my lease pool is around 300 something address, while /etc/hosts has 900+ entries made by this script. Multiple users on my network thinking they've gotten hacked the minute they open up their terminal and see the host name in their bash prompts. I hope there's a fix in the works? (:

New Member
Posts: 33
Registered: ‎12-23-2014
Kudos: 7

Re: hostfile-update enable doesn't clear expired leases

Is this still an issue in 1.6?

 

Thanks

Emerging Member
Posts: 61
Registered: ‎09-10-2013
Kudos: 4
Solutions: 1

Re: hostfile-update enable doesn't clear expired leases

With my issue of host names being rectcled? Yes this is on 1.6.0

New Member
Posts: 33
Registered: ‎12-23-2014
Kudos: 7

Re: hostfile-update enable doesn't clear expired leases

[ Edited ]

What about exprired DHCP leases? Are those still not cleared out of the hosts file?

 

If it is not yet fixed in 1.6, what about the upcomming 1.7 release?

 

Thanks again.

New Member
Posts: 18
Registered: ‎01-22-2015
Kudos: 8
Solutions: 2

Re: hostfile-update enable doesn't clear expired leases

[ Edited ]

New owner of an ERLITE here and I would also love to see this fixed! I'm thinking it could be accomplished by a cron script that compares the entries in the hosts file and removes the entries which no longer appear in the dhcp leases file. It would also need to synchronize entries, for example if you change your computer's hostname it needs to see that the hostname for your computer's MAC in the host file is not the same as the new hostname in the dhcp leases file. So it would need to remove old entries and synchronize current entries

New Member
Posts: 18
Registered: ‎01-22-2015
Kudos: 8
Solutions: 2

Re: hostfile-update enable doesn't clear expired leases

I found another case where this update fails to occur. I installed a refurbished machine yesterday. I did an initial boot on the network to check connectivity and hardware functionality. I was planning to reimage anyways, so upon initial boot I just set the computer name to "testtest". After I reimaged and set a DHCP reservation on the ERL, it still shows the hostname as "testtest" because its still in the hosts file on the ERL. I don't think DHCP reservations are stored in the leases file, but it would be nice to check if hostnames for DHCP reservations have changed as well.

Emerging Member
Posts: 58
Registered: ‎04-18-2014
Kudos: 41
Solutions: 1

Re: hostfile-update enable doesn't clear expired leases

[ Edited ]

I think that this issue is due to the fact that the on-dhcp-event.sh script is broken as I mentioned here.

 

If you are looking for an alternative, check this script that I use for local DNS resolution.

In my next life I will try to be a native speaker of English, in the meantime please forgive my typos.
New Member
Posts: 30
Registered: ‎07-03-2014
Kudos: 5

Re: hostfile-update enable doesn't clear expired leases

Hi, any update regarding an official fix for this.

I'm running 1.8 now, and the behavior is still present:

Admin@ubnt:/etc$ more hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 ubnt #vyatta entry
172.16.0.20 ds1511 #vyatta entry
172.16.0.20 laibalion.synology.me #vyatta entry
172.16.0.182 Tablet-Liliane #on-dhcp-event ec:e:c4:1d:5a:fd
172.16.0.165 Evi-Laptop #on-dhcp-event 0:13:2:ca:b9:c2
172.16.0.142 android-fa089d9395ad991d #on-dhcp-event 10:68:3f:6f:f4:8
f
172.16.0.135 android-69e09635832556fa #on-dhcp-event 4:2:1f:92:5c:63
172.16.0.124 android-49a9261461fc5dba #on-dhcp-event b4:7:f9:27:42:a6
172.16.0.111 Evi-PC #on-dhcp-event 0:25:22:64:3a:8f
172.16.0.121 android-61a2befba41345e5 #on-dhcp-event 84:10:d:16:ba:99
172.16.0.112 DUNE #on-dhcp-event 0:16:e8:7d:2d:75
172.16.0.108 Printer #on-dhcp-event 30:5:5c:b:f3:a7
172.16.0.116 android-e42f8ea368584c05 #on-dhcp-event c:48:85:f6:55:31
172.16.0.117 Windows-Phone #on-dhcp-event 2c:29:97:39:cb:50
172.16.0.102 Lumia-920 #on-dhcp-event a8:44:81:a3:12:c4
172.16.0.101 Home #on-dhcp-event 24:a4:3c:98:25:eb
172.16.0.126 SURFACE-PRO2 #on-dhcp-event 28:18:78:ce:a:6f
172.16.0.63 Geert-Desktop_Intel #on-dhcp-event 90:2b:34:57:35:f
172.16.0.110 Geert-Desktop #on-dhcp-event 74:e5:43:d3:4d:68
172.16.0.103 Surface-Evi #on-dhcp-event 50:1a:c5:e:cf:2
Admin@ubnt:/etc$ show dhcp leases IP address Hardware Address Lease expiration Pool Client Name ---------- ---------------- ---------------- ---- ----------- 172.16.0.102 a8:44:81:a3:12:c4 2016/03/19 16:42:20 LAN Lumia-920 172.16.0.103 50:1a:c5:0e:cf:02 2016/03/19 18:59:31 LAN Surface-Evi 172.16.0.110 74:e5:43:d3:4d:68 2016/03/19 18:25:45 LAN Geert-Desktop 172.16.0.116 0c:48:85:f6:55:31 2016/03/19 10:55:09 LAN android-e42f8ea368584c05 172.16.0.117 2c:29:97:39:cb:50 2016/03/19 16:28:33 LAN Windows-Phone 172.16.0.126 28:18:78:ce:0a:6f 2016/03/19 18:23:03 LAN SURFACE-PRO2 172.16.0.129 a8:e3:ee:26:81:2d 2016/03/19 18:44:24 LAN

 

New Member
Posts: 1
Registered: ‎05-27-2016

Re: hostfile-update enable doesn't clear expired leases

I'm interested in this being fixed too.  Please advise if it is on the roadmap.

Reply