2

FreeBSD: network interface address: dhcp or static

Followup question now:

I've decided to go with looking at leases files: /var/db/dhclient.leases.. What does it tell me exactly? Existence of /var/db/dhclient.leases.em0 signifies em0 has address by DHCP? This file does not seem to go away with reboot.

Community
  • 1
  • 1
hari
  • 9,439
  • 27
  • 76
  • 110

2 Answers2

3

You should read the manual page for dhclient. This will answer most of your questions. And if that fails, you can browse the source in /usr/src/sbin/dhclient.

Another possibility might be to to use devd(8). This is a daemon that can execulte a script or program if a certain event occurs. It can e.g. note when a network interface goes "up" or "down". From the default /etc/devd.conf (see also devd.conf(5)):

# Try to start dhclient on Ethernet-like interfaces when the link comes
# up.  Only devices that are configured to support DHCP will actually
# run it.  No link down rule exists because dhclient automatically exits
# when the link goes down.
#
notify 0 {
    match "system"          "IFNET";
    match "type"            "LINK_UP";
    media-type              "ethernet";
    action "/etc/rc.d/dhclient quietstart $subsystem";
};
Roland Smith
  • 42,427
  • 3
  • 64
  • 94
1

A client is supposed to remember a DHCP lease across reboots and is supposed to remember past leases on a particular network when requesting an address. Therefore, the file should not go away across boots.

Perry
  • 4,363
  • 1
  • 17
  • 20
  • Thanks Perry. So, before reboot I am using intf1 and after reboot I am using intf2. Now, I want identify this fact. How can I do it using this file? Or I can't. – hari Mar 01 '12 at 19:32
  • Also, if intf2 is reconfigured with static ip (removing DHCP), would its lease file go away? – hari Mar 01 '12 at 19:35
  • I think you might be better off explaining what you are actually trying to do here overall. In particular, there are programatic and script interfaces available in the ISC dhcp suite. – Perry Mar 01 '12 at 21:51