[ explain ] dhclient.eth0.leases file .

Hey lovely ppl at Diet-Pi forum ! It’s me again seeking some help ,

can anyone explain for me this file ( dhclient.eth0.leases ) in var/lib/dhcp and how it’s work and the purpose of this file ?

and i have couple of questions about it :

  • do this file catch dhcp infos ? " even if the device on static ip state " and i changed the dhcp server " DHCP server = router "

  • is it possible to read this file as if you read the ’ interface ’ file ?

  • this file have 2 parts , first one is old and the second one is updated one , the catche here both parts have identical names , can i read the second part only using ( bash ) ?

  • Yeah I’m still a newbie XD

Thanks for the future answers you all !

  • Shout-out to the legend " Joulinar " i know he speed ruining this forum topics and answer all of them ,

As you are still looking on “how to detect the DHCP server”, you might have a look to following web site https://www.putorius.net/find-dhcp-server-ip-linux.html

basically 2 options you have

journalctl | grep -m1 DHCPACK


grep -m1 "dhcp-server" /var/lib/dhcp/dhclient.eth0.leases

Probably the first option might be best as it is independent from any file being present or not

What a great information !
but i need my bash script to " read " from a file that contains the dhcp info ,
Idk if " journalctl | grep -m1 DHCPACK " is capable of that ,

– i tried " journalctl | grep -m1 DHCPACK " in my putty in the command line but nothing shows up can you explain it a bit more ?

thanks a lot !

If there is nothing showing up, you might run a static IP? Could it be?

Oh , here is the problem , i want to get the dhcp info even when I’m on " Static IP " mode , is that possible tho ?

in this case you could try to use nmap tool

nmap --script broadcast-dhcp-discover -e eth0

Nice ! ,

– 2 questions , is there a way to know if eth0 is contacted ( whether it’s have internet access or not ) like only hardware wise ?

We use a simple ping to check if a device is connected to internet.