Configure a DHCP Server in Ubuntu 11

Installation and Configuration

To install dhcp server on Ubuntu 11.10 open a terminal (Dash Home > search “terminal”) and follow these steps and terminal commands:

  • sudo apt-get update (update your repositories)
  • sudo apt-get install dhcp3-server (installs dhcp server – after the installation, Linux will try to start the server and it will fail to start, because the server has not been configured yet)
  • Next you need to edit the dhcp configuration file. Put in the following commands to edit in gedit or nano:

    sudo gedit /etc/dhcp/dhcpd.conf
    or
    sudo nano /etc/dhcp/dhcpd.conf

  • In gedit go to Edit > Preferences > and checkmark “display line numbers.” Now you can see line numbers as a reference. In the conf file any line that begins with a “#” character has been commented out. Meaning it does not effect the server. The lines that do not begin with “#” have been uncommented and are active configurations for the dhcp server. To configure your dhcp server you will want to uncomment and alter the following lines in the conf file:

    Lines 38  through 46 make the following changes and remove the “#” comment from the beginning of the lines:

    subnet 192.168.11.0 netmask 255.255.255.0 {
    range 192.168.11.166 192.168.11.170;
    option domain-name-servers 8.8.4.4;
    # option domain-name “myDomain.local”
    option routers 192.168.11.1;
    option broadcast-address 192.168.11.255;
    default-lease-time 600;
    max-lease-time 7200;
    }

    Save the file and close.
    The example above would work on the Linux network in my classroom lab, where all the linux machines are on a 192.168.11.0 network, the addresses to be handed out are were specific to the user (e.g. Daniel handed out the range 192.168.11.166 to 192.168.11.170), the router is 192.168.11.1, there is no local domain/domain controller, and the DNS server 8.8.4.4 is Google’s.

  • Now you need to restart your DHCP server. Type in the following commands:
    sudo /etc/init.d/isc-dhcp-server restart
  • If you want to check to see if your DHCP server has leased any ip addresses type in the following command:
      sudo tail /var/lib/dhcp/dhcpd.leases
    and you should see information if any computer has picked up an ip address!

 

 

Video Tutorial

In this video, I install and configure DHCP server in Ubuntu, and then lease an IP address to a client on the network

Notes on troubleshooting

  • On my dhcp server when I restarted, it failed. Bummer.
  • For my dhcp server, I used a laptop with both a wireless ethernet card and a wired ethernet card. Following the online example I used the line  INTERFACES=”wlan0 eth0″ in the dhcp3-server file, which seemed logical. However, I have enough experience to know that the network cards could be recognized differently by the operating system, so I used the following command in order to check my network configuration:
        ifconfig 

    and I could see that my system had recognized my network cards as “eth0” and “eth1”, with eth1 being the active interface. So I changed my configuration to  INTERFACES=”eth1″, restarted my server and it worked!
  • I put this tutorial together, using the following web page as my reference: https://help.ubuntu.com/community/dhcp3-server
  • In my example, in order to test my Ubuntu DHCP server, I logged into my linksys wireless router, disabled the dhcp server on the “basic setup” page, and from another Windows computer on the network, released and renewed my ip address with an “ipconfig /release” and an “ipconfig /renew”. Afterward, I ran the “ipconfig /all” command a couple times and I noticed I had successfully pulled an ip address from my Ubuntu server and had internet connectivity! If I had been on another Ubuntu computer I could have restarted my network interface cards or used the following commands to restart my network interfaces:
    ifconfig eth0 down
    ifconfig eth0 up

    The example infers my active interface is eth0, otherwise use eth1, wlan0, etc..

Author: Dan

Dan teaches computer networking and security classes at Central Oregon Community College.

Leave a Reply

Your email address will not be published. Required fields are marked *