Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | FreeBSD |
Time | 1m |
FreeBSD renew ip command to force DHCP client
The syntax is:
## FreeBSD older system syntax ##
dhclient {interface-name-here}
dhclient [options] {interface-name-here}
## Recommend FreeBSD version 11.x/12.x+ syntax / latest version ##
service dhclient restart {interface-name-here}
service dhclient restart em0
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:
How can I renew or release an IP in FreeBSD for em0 interface?
The syntax is:
$ sudo service dhclient restart em0 ## older syntax ## $ sudo dhclient em0 ####################################### ## OR first use 'su -' and then type ## ####################################### # dhclient em0
Sample outputs:
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. The IFNAME represents the network interface of the DHCP client (e.g., em0), one for each interface. Try the tail command/more command/less command as follows:
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; }
Conclusion
You learned how to force DHCP client to renew an IP address on FreeBSD system. See dhclient man page/documenation for more info on a FreeBSD server. We can also type the following man command:
$ man dhclient
🐧 3 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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.
The instructions did not work for me. I specifically wanted to renew immediately to switch to a newly assigned static address. I got the following error message:
The fix is easy, kill the conflicting dhclient process first (pid will vary):
# kill 596
# dhclient interface_name
Thanks for the tip. I updated this page and I appreciate your feedback.