What is DHCP
The Dynamic Host Configuration Protocol (DHCP) is a network configuration protocol for hosts on Internet Protocol (IP) networks. Computers that are connected to IP networks must be configured before they can communicate with other hosts. The most essential information needed is an IP address, and a default route and routing prefix. DHCP eliminates the manual task by a network administrator. It also provides a central database of devices that are connected to the network and eliminates duplicate resource assignments.
In addition to IP addresses, DHCP also provides other configuration information, particularly the IP addresses of local caching DNS resolvers, network boot servers, or other service hosts.
Installing DHCP Server
At the command prompt type the following to install dhcp server.
sudo apt-get update
sudo apt-get install dhcp3-server
Configuring DHCP Server
dhcp3-server by default listens on eth0 interface. You can change the default configuration by editing /etc/default/dhcp3-server
sudo nano /etc/default/dhcp3-server
All other configuration files are located in /etc/dhcp3/ directory. Before editing the dhcpd.conf configuration file make backup copy of it.
sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.bkup
Now edit /etc/dhcp3/dhcpd.conf file using the following command
sudo nano /etc/dhcp3/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option domain-name “myisp.com”;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.21 192.168.0.200;
}
save and exit the file and restart the service using the following command
sudo /etc/init.d/dhcp3-server restart
This will configure the DHCP server with the range 192.168.0.21-192.168.0.200 . The IP address will be leased for 600 seconds if the client doesn’t ask for a specific time frame otherwise the maximum lease will be 7200 seconds. The subnet mask to be used will be 255.255.255.0, 192.168.0.255 as its broadcast address and gateway will be 192.168.0.1. The DNS servers that the client will use will be 8.8.8.8 and 8.8.4.4.
Reservation
You can reserve or bind a IP address to a particular MAC address. To achieve this add the following lines in /etc/dhcp3/dhcpd.conf file below the subnet range declaration.
host client1 {
hardware ethernet 00:23:12:04:16:0d;
fixed-address 192.168.0.22;
}
host client2 {
hardware ethernet 00:23:12:04:16:bc;
fixed-address 192.168.0.23;
}
save and exit the file and restart the service using the following command
sudo /etc/init.d/dhcp3-server restart
Configuring DHCP Client
To configure your ubuntu desktop or server as DHCP edit /etc/network/interfaces file
sudo nano /etc/network/interfaces
to configure eth0 interface as a dhcp client interface add this lines
auto eth0
iface eth0 inet dhcp
Save and exit the file and restart networking services using the following command
sudo /etc/init.d/networking restart
0 comments:
Post a Comment