The dhclient command on Linux is used to renew an IP address for a network interface. Here i am using Fedora 19 with the new standardised network interface names.
root@neo homer# dhclient -v wlp0s26f7u5 Internet Systems Consortium DHCP Client 4.2.5 Copyright 2004-2013 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/wlp0s26f7u5/e0:91:f5:23:fd:ad Sending on LPF/wlp0s26f7u5/e0:91:f5:23:fd:ad Sending on Socket/fallback DHCPDISCOVER on wlp0s26f7u5 to 255.255.255.255 port 67 interval 4 (xid=0x3791798e) DHCPREQUEST on wlp0s26f7u5 to 255.255.255.255 port 67 (xid=0x3791798e) DHCPOFFER from 192.168.1.1 DHCPACK from 192.168.1.1 (xid=0x3791798e) bound to 192.168.1.3 -- renewal in 41575 seconds. |
This command will attempt to set a new IP address for your network adapter.
Here is another example of the usage of this command.
Stopping the network interface.
homer@hal9000:~$ sudo dhclient -r avahi-daemon start/running, process 2643 |
Checking that we have no IP address now.
homer@hal9000:~$ ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:85:68:81 inet6 addr: fe80::a00:27ff:fe85:6881/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:52 errors:0 dropped:0 overruns:0 frame:0 TX packets:93 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6987 (6.9 KB) TX bytes:12712 (12.7 KB) Interrupt:19 Base address:0xd000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:12 errors:0 dropped:0 overruns:0 frame:0 TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:868 (868.0 B) TX bytes:868 (868.0 B) |
Bringing the network interface back up.
homer@hal9000:~$ sudo dhclient eth0 avahi-daemon stop/waiting |
And checking the IP address again gives us what we want.
homer@hal9000:~$ ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:85:68:81 inet addr:192.168.1.7 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe85:6881/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:58 errors:0 dropped:0 overruns:0 frame:0 TX packets:105 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8093 (8.0 KB) TX bytes:14235 (14.2 KB) Interrupt:19 Base address:0xd000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:28 errors:0 dropped:0 overruns:0 frame:0 TX packets:28 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2124 (2.1 KB) TX bytes:2124 (2.1 KB) |
Another way is to use the ipfdown command to bring down the network interface.
homer@hal9000:~$ sudo ifdown eth0 Internet Systems Consortium DHCP Client 4.2.4 Copyright 2004-2012 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/eth0/08:00:27:85:68:81 Sending on LPF/eth0/08:00:27:85:68:81 Sending on Socket/fallback DHCPRELEASE on eth0 to 192.168.1.1 port 67 (xid=0x69c9cbce) avahi-daemon start/running, process 3209 |
And then it will not be active.
homer@hal9000:~$ ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:108 errors:0 dropped:0 overruns:0 frame:0 TX packets:108 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:8404 (8.4 KB) TX bytes:8404 (8.4 KB) |
Then bring it back up with the ifup command and it will be assigned an IP address.
homer@hal9000:~$ ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:85:68:81 inet addr:192.168.1.7 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe85:6881/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:111 errors:0 dropped:0 overruns:0 frame:0 TX packets:178 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:15329 (15.3 KB) TX bytes:21615 (21.6 KB) Interrupt:19 Base address:0xd000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:124 errors:0 dropped:0 overruns:0 frame:0 TX packets:124 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:9660 (9.6 KB) TX bytes:9660 (9.6 KB) |
This is not too difficult at all.