# Network via LAN



## vince66 (Sep 16, 2018)

Hello guys,
I've installed FreeBSD on a USB stick avoiding to use the guided configuration procedure of any network (LAN and WIFI).

Successively I've used dhclient to dinamically set up the DHCP.

Please, can you tell me which files are updated using dhclient ?

Thanks very much.


----------



## jiml8 (Sep 16, 2018)

You will find the lease files in /var/db.  If the dhclient defaults do not work for you (they should) then you will need to edit /etc/dhclient.conf.


----------



## vince66 (Sep 16, 2018)

jiml8 said:


> lease files



Who fills the /var/db/dhclient.leases.xxx (xxx is the name of the card).

Does dhclient read the leases file to set-up the LAN ?

In which a way the LAN can ne set-up at boot, insted Evert time manually invoking dhclient ?


----------



## `Orum (Sep 17, 2018)

Most of this is covered in the handbook, but the leases file is both written and read by dhclient, depending on the circumstances.  It's written when it receives a new lease, and it's read if it can't contact a DHCP server (as a fallback if the lease is still valid and the DHCP server is down).

Read the "11.5.2. Configuring the Network Card" section of the handbook for how to get DHCP at boot.


----------



## kpa (Sep 17, 2018)

You need to read on how DHCP works. The client will try to use an existing lease from /var/db/dhclient.leases.xxx if it hasn't yet expired, that sole purpose of the file is to keep the lease information so that is survives reboots. If the file has no valid leases dhclient(8) will start the DHCP server discovery and lease negotiation from scratch.


----------



## vince66 (Sep 17, 2018)

`Orum said:


> leases file is both written and read by dhclient





kpa said:


> The client will try to use an existing lease from /var/db/dhclient.leases.xxx



My question is:

If I change network, is dhclient able to over-write the file /var/db/dhclient.leases.xxx updating the info inside it and connecting the machine to the new network ?

Or .... what can I do ? .....  (my apologize .... I'm asking the question before I did a test).


----------



## kpa (Sep 17, 2018)

If you change to another network dhclient will first try to use the old lease but the DHCP server in the new network will reject the request to use the old lease and the negotiation returns to the state where the client has no lease.


----------



## sko (Sep 20, 2018)

vince66 said:


> If I change network, is dhclient able to over-write the file /var/db/dhclient.leases.xxx updating the info inside it and connecting the machine to the new network ?


Have you actually looked at the file and its manpage dhclient.leases(5)?
The very first 4 sentences in the description already answer your question:


> The Internet Software Consortium DHCP client keeps a persistent database
> of leases that it has acquired that are still valid.  The database is a
> free-form ASCII file containing one valid declaration per lease.  If more
> than one declaration appears for a given lease, the last one in the file
> ...



Re your initial question:


vince66 said:


> Please, can you tell me which files are updated using dhclient ?


dhclient(8):


> In order to keep track of leases across system reboots and server
> restarts, dhclient keeps a list of leases it has been assigned in the
> /var/db/dhclient.leases.IFNAME file.





vince66 said:


> Or .... what can I do ?


Reading the manpages of the tools/files you want to understand. If this doesn't answer all your questions, go through the other manpages and RFCs mentioned in the "SEE ALSO" section.


----------



## vince66 (Sep 20, 2018)

sko said:


> The very first 4 sentences in the description already answer your question



If you like and enjoy, can you also search for the answer to the following my question.
I prefer to discuss the problem and ask what I don't know.




kpa said:


> If you change to another network dhclient will first try to use the old lease but the DHCP server in the new network will reject the request to use the old lease and the negotiation returns to the state where the client has no lease.




I came back home from work, Ive connected the PC to to the LAN cable , I've run the dhclient re0 command and the PC did not connect anymore.

Why ?
Nothing I've changed. 
I've tried with the follow commands:

service netif restart

ifconfig re0 down
ifconfig re up 
dhclient re0

but ping google.com doesn't work.

Tips are welcome.


----------



## Beastie (Sep 20, 2018)

Run `/etc/rc.d/dhclient quietstart re0`.

Did you add *ifconfig_re0="DHCP"* to /etc/rc.conf?


----------

