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?

[donotprint]
Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsFreeBSD
Time1m
[/donotprint]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.

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • Victor Coss Mar 13, 2016 @ 2:11

    I hope this post isn’t too old for your attention and hope you will reply. Can you explain why the dhclient.leases file file shows the same lease twice? Why does it do that, it does it on mine too and for ISC’s dhclient as well. Sometimes 3 or 4 times.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.