Tuesday, February 3, 2015

FreeBSD Force DHCP Client (dhclient) to Renew IP Address To Get A New Lease

I have a Linux DD-WRT router DHCP server running on my network. How can I force my FreeBSD based dhcp client to get a new lease from this Linux based router? What is the command in FreeBSD equivalent to Windows' "ipconfig /renew" command?
The dhclient command, provides a means for configuring one or more network interfaces using the Dynamic Host Configuration Protocol, BOOTP protocol, or if these protocols fail, by statically assigning an address.



FreeBSD renew ip command

The syntax is:
 
dhclient interface-name-here
dhclient [options] interface-name-here
 
The name of the interface must be specified on the command line. You must run this command as the root user.

How can I see the current IP address settings?

Type the following command:
 
ifconfig
ifconfig interface
ifconfig em0
ifconfig em0 | grep inet
 
Sample outputs:
Fig.01: FreeBSD Display Current IP Address, Netmask and Ethernet Options
Fig.01: FreeBSD Display Current IP Address, Netmask and Ethernet Options

How can I renew or release an IP in FreeBSD for em0 interface?

The syntax is:
$ sudo dhclient em0
#######################################
## OR first use 'su -' and then type ##
#######################################
# dhclient em0
Sample outputs:
Fig.02: Renew an IP address on FreeBSD using dhclient
Fig.02: Renew an IP address on FreeBSD using dhclient

Other options in FreeBSD to renew dhcp IP address

You can also use the following command to renew dhcp IP address for em0:
service dhclient restart em0
 
## OR ##
/etc/rc.d/dhclient restart em0
 
Sample outputs:
Stopping dhclient.
Starting dhclient.
DHCPREQUEST on em0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.254
bound to 192.168.1.142 -- renewal in 43200 seconds.

dhclient log file

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. IFNAME represents the network interface of the DHCP client (e.g., em0), one for each interface:
tail -f /var/db/dhclient.leases.em0
OR
less /var/db/dhclient.leases.em0
Sample outputs:
lease {
  interface "em0";
  fixed-address 192.168.1.142;
  next-server 192.168.1.254;
  option subnet-mask 255.255.255.0;
  option routers 192.168.1.254;
  option domain-name-servers 192.168.1.254;
  option host-name "freebsd10";
  option broadcast-address 192.168.1.255;
  option dhcp-lease-time 86400;
  option dhcp-message-type 5;
  option dhcp-server-identifier 192.168.1.254;
  option dhcp-renewal-time 43200;
  option dhcp-rebinding-time 75600;
  renew 0 2015/2/1 21:38:04;
  rebind 1 2015/2/2 06:38:04;
  expire 1 2015/2/2 09:38:04;
}
lease {
  interface "em0";
  fixed-address 192.168.1.142;
  next-server 192.168.1.254;
  option subnet-mask 255.255.255.0;
  option routers 192.168.1.254;
  option domain-name-servers 192.168.1.254;
  option host-name "freebsd10";
  option broadcast-address 192.168.1.255;
  option dhcp-lease-time 86400;
  option dhcp-message-type 5;
  option dhcp-server-identifier 192.168.1.254;
  option dhcp-renewal-time 43200;
  option dhcp-rebinding-time 75600;
  renew 0 2015/2/1 21:44:47;
  rebind 1 2015/2/2 06:44:47;
  expire 1 2015/2/2 09:44:47;
}
References
See dhclient man page for more info on a FreeBSD server:
$ man dhclient

0 comments:

Post a Comment