How to Install and Configure DHCP Server in Ubuntu Server

Sponsored Link
A DHCP Server assigns IP addresses to client computers. This is very often used in enterprise networks to reduce configuration efforts. All IP addresses of  all computers are stored in a database that resides on a server machine.

A DHCP server can provide configuration settings using two methods

Address Pool

This method entails defining a pool (sometimes also called a range or scope) of IP addresses from which DHCP clients are supplied their configuration properties dynamically and on a fist come first serve basis. When a DHCP client is no longer on the network for a specified period, the configuration is expired and released back to the address pool for use by other DHCP Clients.

MAC Address

This method entails using DHCP to identify the unique hardware address of each network card connected to the network and then continually supplying a  constant configuration each time the DHCP client makes a request to the DHCP server using that network device.

Install DHCP server in ubuntu

sudo apt-get install dhcp3-server

This will complete the installation.

Configuring DHCP server

If you have two network cards in your ubuntu server you need to select which interface you want to use for  DHCP server listening.By default it listens to eth0.

You can change this by editing  /etc/default/dhcp3-server file

sudo vi /etc/default/dhcp3-server

Find this line


Replace with the following line


Save and exit.This is optional.

Next you need to make a backup copy of /etc/dhcp3/dhcpd.conf file

cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.back

Edit /etc/dhcp3/dhcpd.conf file using the following command

sudo vi /etc/dhcp3/dhcpd.conf

Using address pool method

You need to change the following sections in /etc/dhcp3/dhcpd.conf file

default-lease-time 600;
max-lease-time 7200;

option subnet-mask;
option broadcast-address;
option routers;
option domain-name-servers,;
option domain-name "";

subnet netmask {

save and exit the file

This will result in the DHCP server giving a client an IP address from the range . It will lease an IP address for 600 seconds if the client doesn't ask for a specific time frame. Otherwise the maximum (allowed) lease will be 7200 seconds. The server will also "advise" the client that it should use as its subnet mask, as its broadcast address, as the router/gateway and and as its DNS servers.

Using MAC address method

This method is you can reserver some of the machines or all the machines with fixed ip address.In the following example i am using fixed ip address for server1,server2,printer1 and printer2

default-lease-time 600;
max-lease-time 7200;

option subnet-mask;
option broadcast-address;
option routers;
option domain-name-servers,;
option domain-name "";

subnet netmask {

host server1 {
hardware ethernet 00:1b:63:ef:db:54;

host server2 {
hardware ethernet 00:0a:95:b4:d4:b0;

host printer1 {
hardware ethernet 00:16:cb:aa:2a:cd;

host printer2 {
hardware ethernet 00:0a:95:f5:8f:b3;

Now you need to restart dhcp server using the following command

sudo /etc/init.d/dhcp3-server restart

Configure Ubuntu DHCP Client

If you want to configure your ubuntu desktop as DHCP client following this procedure

You need to open /etc/network/interfaces file

sudo vi /etc/network/interfaces

make sure you have the following lines (eth0 is an example)

auto lo eth0
iface eth0 inet dhcp
iface lo inet loopback

Save and exit the file

You need to restart networking services using the following command

sudo /etc/init.d/networking restart

How to find DHCP server IP address

You need to use the following commands

sudo dhclient


tail -n 15 /var/lib/dhcp3/dhclient.*.leases

Sponsored Link

You may also like...

32 Responses

  1. Humaun says:

    well $ useful link

  2. hiims says:

    very useful and work very good

  3. itics says:

    hurm… look interesting… going to try this …

  4. waheed says:

    how to get the list of dhcp client from dhcp server?

  5. SOUSA says:

    Hi. I followed the instructions above and I got what I wanted: communication between my two computers. But when I configure the DHCP client computer, it looses the Internet connection. I can ping the DHCP server, but not google, for example.

    Can you help me?


  6. admin says:

    which DNS servers and gateways are configured in your DHCP server

  7. vicky kiyuga says:

    thanks so much four help.

  8. Satish says:

    Useful link.. Do I need to remove the ethernet connector to see the MAC address of devices? or I can detect the device IP after connecting to the network..? Any way to get the MAC?

  9. admin says:

    Use ifconfig to check the mac address of your pc or server

  10. Thanks. You’ve taken me 3/4 of the way there. Using your site along with the tests in the following link ( helped me to ensure that my ethernet cards were working and that one of them was acting as a dhcp server. Next step is to get the other ethernet card to act as a router. That part is still not functioning. Can you lead the way to a good link?

  11. Ibrahim says:

    How can I ensure at each step, configuration is done correctly, any snapshots will help me a lot.

    when I installed dhcp3-server at the end it printed

    invoke-rc.d: initscript dhcp3-server, action “start” failed.

    what does that mean?…

  12. Nj3ma says:

    Hey. How do I heck to make sure that the DHCP server’s gateway and DNS Servers are configured correctly.

  13. nkvd says:

    This one really helps, thanks)

  14. mastapat11 says:

    i followed this and everything looks correct…
    except that even tho clients get a unique IP and same DNS as the server, they still can’t connect to the internet.
    The serer does just fine (writing from it now). it gets dhcp from ISP gateway modem on eth1.
    eth0 is connected to lan switch w/ static internal IP.

    All the #’s look good on the clients. ip, dns, router (internal address of server, eth0).
    I’m so stuck at this point. What am i missing??

  15. mjrsnyder says:

    i’ve got 2 interfaces eth0 is internal and eth1 is on another network. Every time i restart dhcp3 it assigns the server itself an IP. It needs to be static. I configured a static one in /etc/network/interfaces but it changes when i restart the dhcp3 server. Any help would be greatly appreciated

  16. Jacky Yeh says:

    I only need to install DHCP server on my Ubuntu and after I type sudo /etc/init.d/dhcp3-server restart, it appears the following message,

    user@user-desktop:~$ sudo /etc/init.d/dhcp3-server restart
    dhcpd self-test failed. Please fix the config file.
    The error was:
    /usr/sbin/dhcpd3: error while loading shared libraries: cannot open shared object file: No such file or directory

    May I know how to solve? Oh babe~~~

    Jacky Yeh

  17. Javier Giron says:

    Nice article, and very usufull. but i have a inocent dude……
    would be the configuration for the gateway as and the domain name server and…..
    And another question above. ¿what mean exactly this paramenters -> subnet netmask

  18. Jason K says:

    sweet article, I usually watch youtube and take notes, but I cant watch youtube in class…lol
    So far i have a DNS and APACHE server up, now time for the DHCP server all in VMworkstation..

    To answers Javiers questions is the network address that marks the beginning of the addresses for that subnet. So = /24 , so you can only have 254 addresses avaliable.

  19. hengky says:

    excuse, is there any1 tat could help me???? i have scul project

    my network topology is my laptop as dhcdp server – laptop clients so the configuration in dhcpd.conf in dhcpd server is enough?? i mean, do i need to change my dhcpd network connetion ip on my dhcp server???? because i dont’t use modem on my network dhcpd server so what should i fill in in my gateway and dns??? plizz help me..

  20. Kashif says:

    Dear Ibrahim,
    This error means that you haven’t configured the DHCP server.

  21. Abby says:

    How do you download and install dhcpv6?

  22. Chandrakanth says:


    Its really great and useful.

  23. techpreacher says:

    Yes, I’ve checked the syntax to the best of my ability and re-wrote the dhcpd.conf file.

    Here is a copy of my dhcpd.conf file:
    subnet netmask {
    option domain-name-servers;
    option domain-name-servers;
    option routers;
    option broadcast-address;
    default-lease-time 600;
    max-lease-time 7200;
    dhcpd.conf (END)
    linuxubuntu preacher is online now Report This Post

  24. Robin says:

    There is no folder named “default”.

  25. Kashif says:

    After installing DHCP packages using apt-get or yum than search for dhcpd.conf file via find or locate command…

  26. George says:

    These instructions dont work for me using Ubuntu 12.4. The only directory under /etc/dhcp3 is dhclient-enter-hooks.d/samba

    There is no /etc/init.d/dhcp3
    There is /etc/init.d/isc-dhcp-server and /etc/init.d/isc-dhcp-server6 and they seem to work starting with: sudo service isc-dhcp-server start

    I’ve tried updating the /etc/dhcp/dhcpd.conf since it is there but I’m not sure its correct…

    Lastly, in the instructions you say to replace ns1 with my DHCP Server Host name. Just to verify that, there should be no “ns1” in any of the zone file examples you gave?


  27. George says:

    Sorry, the “Lastly” part I got mixed up with the setting up DNS instructions.

    I did get it working with the isc-dhcp-server and editing the /etc/dhcp/dhcpd.conf file.

  28. stephen says:


    I have Ubuntu 11 server setup with DRBL server and Clonezilla. I am trying to get the Ubuntu/DRBL/CloneZilla setup to work with my Current Windows DHCP server so I can use Clonezilla on different subnets. Currently CloneZilla will only work on the 203 subnet and I have over 100 different scopes I need CloneZilla to see.

    Eth0 –
    Eth1 –

    Any help/advice would be great.

  29. Iulian says:

    I follow this tutorial and:
    1. i install dhcp server
    2. configure dhcp
    3. set INTERFACES=”eth1?
    4. In /etc/network/interface
    eth0 static ip from router
    eth1 static from dhcp config

    i got 2 netwrk cards and:
    from eth0 i got internet access
    and from eth1 i wanna give internet to clients

    my server have internet from router trough eth0 but din’t give internet to eth1, just network from dhcp.

    Please help !
    Sorry for my bad English !

  30. Robinde67 says:

    @Iulian: from what I gather, you have successfully configured dhcp for eth1, and you want eth1 to connect to internet over eth0? You’ll have to do that in iptables, create a file and insert:

    iptables -F FORWARD
    iptables -F INPUT
    iptables -F OUTPUT
    iptables -t nat -F POSTROUTING
    iptables -t nat -F PREROUTING

    iptables -P FORWARD DROP
    iptables -P INPUT DROP
    iptables -P OUTPUT DROP

    iptables -nat -A POSTROUTING -o eth0 -j MASQUERADE

    iptables -A FORWARD -eth1 -j ACCEPT
    iptables -A FORWARD -m state –state ESTABLISHED,RELATED -j ACCEPT
    iptables -A OUTPUT -j ACCEPT
    iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

    iptables -A INPUT -lo -j ACCEPT

    echo 1 >/proc/sys/net/ipv4/ip_forward

    make it executable with chmod and add it’s path to /etc/rc.local

    note that this configure drop all input to the server in question that isn’t originating from the server as well as any connection to eth1 that isn’t established from eth1, only do this if you don’t connect to it remotely, otherwise add the ports and interfaces that should be accepted as well.
    For example:
    iptables -A INPUT -i eth1 -p tcp –dport 22 -j ACCEPT

Leave a Reply

Your email address will not be published.