Grab a New Address Using DHCP


dhclient

Most home networks and many business networks use the Dynamic Host Control Protocol (DHCP) to parcel out IP addresses and other key information about the network to new machines joining it. Without DHCP, any new machine must have all of its networking information hard-coded in; with DHCP, a new machine simply plugs in to the network, asks the DHCP server to provide it with an IP address and other necessary items, and then automatically incorporates the DHCP server's reply into its networking configurations.

Note

The following discussion assumes that you've already configured your network device to use DHCP instead of hard-coded settings. Various Linux distributions expect that information to be found in different configuration files. Debian-based distributions look for the line iface [interface] inet dhcp in /etc/network/interfaces. Red Hatderived distributions instead want to see BOOTPROTO=dhcp in /etc/sysconfig/network-scripts/ifcfg-[interface]. In these examples, substitute [interface] with the name of your interface. For more inforamtion, search Google for "dhcp your-distro."


Sometimes your machine can't connect at boot to the DHCP server, so you need to manually initiate the DHCP request. Or you might have networking problems that require a new IP address. No matter the reason, the dhclient command attempts to query any available DHCP server for the necessary data (dhclient must be run as root).

#  dhclient eth0 Listening on LPF/eth0/00:0b:cd:3b:20:e2 Sending on   LPF/eth0/00:0b:cd:3b:20:e2 Sending on   Socket/fallback DHCPDISCOVER on eth0 to 255.255.255.255 port 67  interval 8 DHCPOFFER from 192.168.0.1 DHCPREQUEST on eth0 to 255.255.255.255 port 67 DHCPACK from 192.168.0.1 bound to 192.168.0.104 -- renewal in 37250 seconds. #  ifconfig eth0 eth0 Link encap:Ethernet  HWaddr 00:0B:CD:3B:20:E2 inet addr:192.168.0.104  Bcast:192.168.0.255   Mask:255.255.255.0  inet6 addr: fe80::20b:cdff:fe3b:20e2/64 Scope:Link 


To release, or give up, the IP address that the DHCP server has assigned you, use the -r (for release) option.

# dhclient -r eth0 sit0: unknown hardware address type 776 sit0: unknown hardware address type 776 Listening on LPF/eth0/00:0b:cd:3b:20:e2 Sending on   LPF/eth0/00:0b:cd:3b:20:e2 Sending on   Socket/fallback 


Ideally, the dhclient command should run automatically when you boot your computer, plug in a wireless PCMCIA card, or connect an Ethernet cable to your wired jack, but sometimes it doesn't. When DHCP doesn't work like it's supposed to, turn to dhclient. It's especially nice how dhclient is automatically verbose, so you can see what's going on and diagnose as necessary.

Note

Some Linux distributions are still using an older program to perform DHCPpumpinstead of dhclient. For info on pump, take a look at man pump, or read a brief HOWTO for Red Hat and Mandrake at www.faqs.org/docs/Linux-mini/DHCP.html#REDHAT6.




Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net