LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-30-2019, 04:24 AM   #1
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 283

Rep: Reputation: 8
DHCP cache - Be so kind to explain


I have in LAN, DNSMASQ server with DNS and DHCP services running on it. All network nodes have static assignment in DHCP MAC address to IP address. Lease time is set to infinite. DNSMASQ server is set to ignore unknown MAC address.
I want to catch incoming traffic to DNSMASQ server, like DHCP requests and ICMP echo using such command:
Code:
tcpdump -lni eth0 \( ether host 90:b6:86:38:46:fa or host 192.168.0.23 \) and \( udp port 67 or icmp \) and inbound
It works properly. But only if node (like smartphone) is in range of home WiFi network. That is. When I turn off from Android menu WiFi port and turn it on again, DCHP request is send to DNSMASQ server. But when I go out of range of home WiFi network (so connection is lost even for several hours) and than I am back in the range of home WiFi network, no DHCP requests is recorded but smartphone works properly with proper IP address.
I think that something is cached somewhere. Is it because of phone or server cache? I try to remove manually apropriate entrys from dnsmasq.leased file (stop dnamasq, edit lease file and start dnsmasq again) but the result was the same.
How can I have a situation that each time the connection of smartphone with home network will be lost (because phone will be out of range of home WiFi), after next presence if phone in range if home WiFi, DHCP reqest will be send? Is it possible? Is it possible for example send from server CLI DHCP Relese command? Any other solution?
 
Old 05-30-2019, 10:06 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,211

Rep: Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912
Not an expert with DHCP, but I have to think that if " All network nodes have static assignment in DHCP MAC address to IP address. Lease time is set to infinite." that you're getting the behavior you've configured to get.

That a client goes out of range, and automagically reconnects when back in range is exactly the behavior you want with the configuration you've specified. I think that's good...no problems with the client reconnect 'cause it's instantaneous...no DHCP request required. He already knows his IP address.
 
1 members found this post helpful.
Old 05-30-2019, 10:16 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,522

Rep: Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589
I agree with scasey, In addition Android OS has a special network smart switch capability to seamlessly switch between mobile data and wifi data. Not sure exactly how it works but assume the wifi stays active which means when the phone is back within range of your home network it automatically connects. And as stated since the lease never expires no DHCP requests.
 
2 members found this post helpful.
Old 05-31-2019, 12:12 AM   #4
Bewildered Penguin
LQ Newbie
 
Registered: May 2019
Location: Calgary, Alberta
Distribution: Mint
Posts: 14

Rep: Reputation: 1
Quote:
Originally Posted by mackowiakp View Post
I think that something is cached somewhere. Is it because of phone or server cache?
This has to be due to a cache on the phone.

If you turn your phone's WiFi off then back on again, versus moving out of range of the wireless network, both of these situations would appear exactly the same to the network's DHCP server. I.e. the phone disconnected from the network for unknown reasons.

On the other hand, the phone does know whether or not its WiFi was disabled versus it simply moved out of range of the network. Therefore, if you experience different behavior between the two situations, the cache on the phone must be responsible as only the phone would be able to actually distinguish between the two sets of conditions and behave differently for each of them.

It appears that turning the phone's WiFi off then back on again purges its DHCP cache, whereas keeping WiFi turned on and simply moving out of range does not purge its DHCP cache.

So here are the two situations:

Phone's WiFi turned off then on:

- phone's DHCP cache is purged
- phone forgets that it had a reserved IP address with an infinite lease time
- phone must request a new address from the DHCP server
- DHCP request sent from phone to DHCP server
- phone is assigned the same IP address as before, due to the reservation on the DHCP server

Phone moved out of range but WiFi not turned off then back on:

- phone's DHCP cache is not purged, even though it temporarily disconnects from the wireless network
- when phone comes within range again, it recognizes the network and remembers that it has a valid IP address with an infinite lease time, due to its cached DHCP information
- DHCP clients only renew their DHCP lease at the half-way point of their lease time. Half of infinite is infinite, so the phone will never need to renew its lease as long as its DHCP cache is not purged for any reason
- no DHCP request sent from phone to DHCP server
- phone continues using the same IP address as before

Last edited by Bewildered Penguin; 05-31-2019 at 12:51 AM.
 
1 members found this post helpful.
Old 05-31-2019, 04:52 AM   #5
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 283

Original Poster
Rep: Reputation: 8
Quote:
Phone moved out of range but WiFi not turned off then back on:

- phone's DHCP cache is not purged, even though it temporarily disconnects from the wireless network
- when phone comes within range again, it recognizes the network and remembers that it has a valid IP address with an infinite lease time, due to its cached DHCP information
- DHCP clients only renew their DHCP lease at the half-way point of their lease time. Half of infinite is infinite, so the phone will never need to renew its lease as long as its DHCP cache is not purged for any reason
- no DHCP request sent from phone to DHCP server
- phone continues using the same IP address as before
OK. Sounds logically. But lets imagine situation when phone goes out of range of WiFi network for several hours. During this time admin change static assignment MAC to IP to any other IP address. So when phone is back to the range of WiFi net, it must check if cached IP assignment is still valid or not. Because of that I add -vvv option to tcpdump call for more info about data exchange between client and DHCP server. What can I see is that sometimes DHCP request is send from such phone to DHCP server. But it is very rare.

So the only solution which solve that problem is WiFi geofencing and turn on/of WiFi in Android, depending on geo localisation. Now I am looking for appropriate app in Play Store. I tested maybe 10 of such apps, but still did not find reliable one. Maybe somebody knows one? Of course without GPS turn on because of battery drain.

Last edited by mackowiakp; 05-31-2019 at 04:53 AM.
 
Old 05-31-2019, 05:29 AM   #6
Bewildered Penguin
LQ Newbie
 
Registered: May 2019
Location: Calgary, Alberta
Distribution: Mint
Posts: 14

Rep: Reputation: 1
Quote:
Originally Posted by mackowiakp View Post
What can I see is that sometimes DHCP request is send from such phone to DHCP server. But it is very rare.
And those rare instances probably happened for a reason, like maybe the phone was restarted during that time to install updates (which may also purge the DHCP cache, in the same way as temporarily disabling WiFi).

Quote:
Originally Posted by mackowiakp View Post
So the only solution which solve that problem is WiFi geofencing and turn on/of WiFi in Android, depending on geo localisation

I've tried one of those apps, also on Android, with mixed results.

The problem I was trying to solve was that my phone would automatically switch from cellular data to any random "open" (i.e. no password) WiFi hotspot that would actually not allow me to actually use it until I logged in on the captive portal. This issue caused my WhatsApp video calls to drop when I walked past train stations or certain restaurants (anywhere with an open hotspot with a captive portal). So I thought I could use geofencing to automatically disable my WiFi when I left my house, so I didn't have to keep manually turning it on and off.

Unfortunately, the app I tried was unreliable even when using GPS for location detection. I would often be at home, close to my router, and my phone's WiFi would be disabled by the app, as the GPS was telling it I was halfway down the street. All it takes is for your phone to be unable to communicate with a GPS satellite for a while (maybe you go to the basement) and suddenly, the perceived location becomes inaccurate and the app starts applying the wrong WiFi rules.

I believe the apps are sometimes unreliable not because of glitches in the apps themselves, but because of occasionally inaccurate location information that they rely upon. Maybe things have improved since I tried it a couple of years ago, but I am hesitant to go back to using them because I found them to sometimes introduce a worse problem than the one I was trying to solve.

Out of curiosity, what is the purpose of your network configuration? If you do, one day, change the reserved IP address for your cell phone at the DHCP server, wouldn't it be better to just manually refresh your phone's DHCP information by briefly disabling its WiFi adapter, rather than dealing with all the additional complexity, battery drain and possible unreliability that a geofencing app might introduce?

Personally, I would never use an unlimited DHCP lease time! I don't think it's a good idea. The network overhead is very small in a DHCP handshake and I like all my DHCP client devices (including those with reserved IP addresses) to check in with the router from time to time. I use a seven-day lease time in my house and everything works great. In a busy office, or place with a high turnover of people, I would use 24 hours or less, to avoid running out of available IPs.

Last edited by Bewildered Penguin; 06-01-2019 at 10:41 AM.
 
Old 05-31-2019, 10:00 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,522

Rep: Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589Reputation: 3589
The DHCP client will save leases and the file name will contain the SSID. As far as I know this is the "DHCP cache". I do not how the Andorid DHCP client works but I assume since the lease is infinite it will not automatically send a DHCP request when it reconnects to your wifi.

As stated it really does not make sense to use an infinite lease time.
 
1 members found this post helpful.
Old 05-31-2019, 10:22 AM   #8
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 283

Original Poster
Rep: Reputation: 8
I have the same experience as @Bewildered Pengiun. So my goal is to have some kind o "geofencing" based in traffic between phone and home LAN. If I am near my house, phone will detect home SSID and try to log in to network. Ping each 5 min confirm presence of particular mobile in network. So is good idea to set lease time for mobile to 10 min for example?
 
Old 06-01-2019, 01:15 AM   #9
Bewildered Penguin
LQ Newbie
 
Registered: May 2019
Location: Calgary, Alberta
Distribution: Mint
Posts: 14

Rep: Reputation: 1
I think it's better to keep things simple, as much as possible. This is a "high-tech solution for a low-tech problem". There are a lot of "moving parts" (working components), and many ways that it could fail.

What happens if your internet goes down due to an outage? The pings will fail and your phone will turn off its WiFi, when it should not!

What happens when you return home? The phone will be unable to ping the home network as the WiFi radio was turned off when you left, so how will it now sense that you have returned if it relies on these same pings to your WiFi network to confirm that you are home again?

Maybe I'm missing something here!

And we're also going from one extreme with DHCP lease time to the other. I've never heard of anyone using an infinite lease time before... and now we're going all the way down to 10 MINUTES! I haven't heard of such a short lease time before.

Now, there's nothing technically wrong with short lease time, other than it will create some network overhead if there are many devices on the network, all renewing their leases at the halfway point (so every 5 minutes). But I don't really understand the benefit of using an exceptionally short DHCP lease time, especially when there is, as far as I can tell, only one or a small number of devices, and the one that you are most concerned about has a reserved address anyway. Short lease times are typically used to avoid busy networks running out of free IP addresses within the DHCP scope. Even in those situations, one hour, combined with a large pool, is generally good.

I've been here before: using complex and convoluted solutions to try to solve unusual problems, but I have found that complex solutions tend to have a lot of working parts and can be unreliable and prone to failure. I recommend trying to avoid making things more involved than they need to be.

Personally, I just manually turn my phone's WiFi off if public hotspots interfere with the reliability of my internet when I'm away from my house.

Last edited by Bewildered Penguin; 06-01-2019 at 10:45 AM.
 
Old 06-01-2019, 06:53 AM   #10
mackowiakp
Member
 
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 283

Original Poster
Rep: Reputation: 8
Hmmm. It is more philosophic entry than technical. 20 years ago it was simply unbelievable that not only computers will have an operating system. Today embedded Linux`s (or Linux clone) are present even in vacuum cleaner and refrigerator.

Quote:
What happens if your internet goes down due to an outage? The pings will fail and your phone will turn off its WiFi, when it should not!
Nothing. Because I am talking about transmission between mobile phone and internal home LAN only as far as it will be in range of my home network, not via Internet. And source of ping packets is computer controlling my house not mobile phone. But, it is true. There is possibility that vacuum cleaner will not start automatically because it is driven (scheduled) via dedicated cloud of producer. And it is possible that refrigerator will not place automatically order of new products from Tesco. Will be hungry a little bit.

Quote:
What happens when you return home? The phone will be unable to ping the home network as the WiFi radio was turned off when you left, so how will it now sense that you have returned if it relies on these same pings to your WiFi network to confirm that you are home again?
Nothing. It is matter of logic embedded in RPi cluster controlling my house (using Domoticz). If something will not go according to pre-defined rules, it will do nothing and will inform me by push info to smartphone.

Quote:
Personally, I just manually turn my phone's WiFi off if public hotspots interfere with the reliability of my internet when I'm away from my house.
The system must be "housewife proof". For some people it is too complicated to turn on/off WiFi in mobie. Simply all must run automatically.

But I understand Your philosophy. Keep it ASAP. In that case that means "As SIMPLE as possible". But why do not have some fun?

Last edited by mackowiakp; 06-01-2019 at 07:22 AM.
 
Old 06-02-2019, 09:51 AM   #11
Bewildered Penguin
LQ Newbie
 
Registered: May 2019
Location: Calgary, Alberta
Distribution: Mint
Posts: 14

Rep: Reputation: 1
Talking

Quote:
Originally Posted by mackowiakp View Post
Nothing. Because I am talking about transmission between mobile phone and internal home LAN only as far as it will be in range of my home network, not via Internet. And source of ping packets is computer controlling my house not mobile phone.
Okay, now I understand your situation better. Maybe it could work.

I have some networking knowledge but I'm a Linux noob so won't be able to help with implemening that solution myself.

Good lucking getting it to work!
 
  


Reply

Tags
dhcp, dnsmasq, wifi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ram wiht suse, cache Disk cache??? fadelhomsi Linux - Newbie 2 02-05-2006 11:29 PM
clearing cache, web cache on linux varunbihani Linux - General 2 12-08-2005 12:02 PM
Error: Caching enabled and local cache: //var/cache/yum/base/primary.xml.gz does... dr_zayus69 Linux - Software 2 07-06-2005 04:32 AM
I have a cache directory, I am not sure if that is squid's cache directory Niceman2005 Linux - Software 1 11-26-2004 02:46 AM
kind of a programming quesion...kind of not tho jhorvath Programming 2 06-30-2003 10:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration