2009-04-18

FreeBSD networking - IP address automatically assign aka DHCP

This is another follow up post on DHCP aka Dynamic Host Configuration Protocol, which posted first in here and then here. FreeBSD are commonly used as a server. One might ask why does it needs to auto assign IP using DHCP ? Should not it running static IP so that the server are contacted by the host always on that particular IP? To answer the question, the server could be in testing mode so any IP will do. Or the DHCP server have statically map the server's MAC address to a particular IP in its table or pool. The DHCP server will only assign that particular IP to that MAC address when the DHCP client (which in this case is the FreeBSD server) sends out a broadcast requesting info to setup the IP assignment.

In short, just follow the below and IP will be assigned, if there is any DHCP server already configure within the network :
1. First, use :
ifconfig
command to find out the NIC's interface name.
e.g. rl0, em0, bce0, fxp0 and etc

2.
dhclient <interface name>
e.g.
dhclient em0

3. to make it permanently obtain IP automatically from DHCP server, put :
ifconfig_<interfacename>="dhcp"
into /etc/rc.conf.

e.g.
ifconfig_em0="dhcp"

use,
ifconfig
to verify that the address have been assigned.

Ciao !!!

1 comment:

Eyesly5 said...

This was EXACTLY what I was looking for, and now my server autoconnects to the network on reboot, no more pluging in the monitor and keyboard... Thanks!