How to install DHCP on Ubuntu?

What is DHCP?

Dynamic Host Configuration Protocol (DHCP) is network protocol for automatically assigning TCP/IP information to client machines. Each DHCP client connects to the centrally-located DHCP server which returns that client's network configuration including IP address, gateway, host name, and DNS servers.

Why do we need DHCP server?

DHCP is useful for fast delivery of client network configuration. When configuring the client system, the administrator can choose DHCP and not have to enter an IP address, netmask, gateway, or DNS servers. The client retrieves this information from the DHCP server. DHCP is also useful if an administrator wants to change the IP addresses of a large number of systems. Instead of reconfiguring all the systems, he can just edit one DHCP configuration file on the server for the new set of IP address. If the DNS servers for an organization changes, the changes are made on the DHCP server, not on the DHCP clients. Once the network is restarted on the clients (or the clients are rebooted), the changes will take effect.

Furthermore, if a laptop or any type of mobile computer is configured for DHCP, it can be moved from office to office without being reconfigured as long as each office has a DHCP server that allows it to connect to the network.

Installing DHCP server

Become a super user

user@server:~# sudo su -
Password:

Install DHCP server using apt-get
root@server:~# apt-get install dhcp3-server

Configure the DHCP server. The main Configuration file for DHCP server is /etc/dhcp3/dhcpd.conf. Below is the sample file.
root@server:~# vim /etc/dhcp3/dhcpd.conf

# Sample DHCP Configuration File.
ddns-update-style none;
authoritative;
log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {
   option subnet-mask 255.255.255.0;
   #Domain name that client should use when resolving host names
   option domain-name "mydomain.com.my"
   #IP address of DNS server
   option domain-name-servers 192.168.0.1;
   #IP address of router
   option routers 192.168.0.1;
   option broadcast-address 192.168.0.255;
   #IP address of NTP server
   option ntp-servers 192.168.0.1;
 
   group GENERAL {
 	host HOST1 {
	    hardware ethernet 00:0D:29:A9:D0:CB;
	    fixed-address 192.168.0.100;
	}
	host HOST2 {
	    hardware ethernet 00:AC:29:A4:C0:CB;
	    fixed-address 192.168.0.101;
	}
    }
}

You need to restart the DHCP daemon to take effect of your new changes.
root@server:~# /etc/init.d/dhcp3-server restart

If the service restarted without any errors, it means you've successfully installed and configured the DHCP Server installation for your LAN.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <b> <i> <p> <br> <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.