ghacks Technology News

Configure your Ubuntu Server as a DHCP server


In my recent Ubuntu Server articles I have covered the following topics:

Installing Ubuntu Server 9.04

Set up your new Ubuntu Server as a Samba server

Add FTP service to your Ubuntu Server

Now it’s time to get a bit deeper in the trenches by configuring that same Ubuntu server to serve up DHCP addresses. You might think this is a difficult setup, but it’s not. And many might be asking “Why do this when my router does the trick?” Most routers do a good job of serving up DHCP addresses. But there are times when those routers aren’t as configurable as we’d like them. Or maybe you want your DHCP server/router to also act as a much stronger firewall than what a standard router can handle. In these cases it’s nice to be able to set up your own DHCP server. And in this article, we will do just that.

Nuts and bolts

The information you should know about the DHCP server in this article looks like this (for examples’ sake):

  • ethernet device: eth0
  • IP Address range: 192.168.1.100 – 192.168.1.200
  • Subnet address: 192.168.1.0
  • Netmask: 255.255.255.0
  • DNS Servers: 208.67.222.222 and 208.67.220.220 (OpenDNS for those who do not know)
  • Domain: my.example.net
  • Gateway Address: 192.168.1.1
  • Broadcast Address: 192.168.1.255

What you will need to do install the dhcp3-server package in order to serve up the addresses. To install this issue the command:

sudo apt-get install dhcp3-server

You will need to enter your sudo password for the installation to begin. When the installation is complete you will have the configuration file (dhcp3-server) located in /etc/default/ and the executable command (dhcp3-server) will be located in /etc/init.d/.

Before you fire up the server you first must handle some configuration.

Configuration

The first configuration is to set the ethernet device. Open up the configuration file with the command:

nano /etc/default/dhcp3-server

On line 11 of this file (Which is actually the last line because this file is basically empty) you will see the line:

INTERFACES=”"

Change this line to read:

INTERFACES=”eth0″

You are finished with this file. Save the file and then open up the file /etc/dhcp3/dhcpd.conf. The first line you will need to edit is line 16. This line will look like this:
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

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

You need to comment out all of those lines so they look like:
# option definitions common to all supported networks...
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

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

Now go down to line 53. Here you will see this section:
# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}

This section needs to be uncommented out and edited to reflect this:
# A slightly different configuration for an internal subnet.
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option domain-name-servers 208.67.222.222, 208.67.220.220;
option domain-name "my.example.net";
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;
}

Save this file and you are ready to fire up your DHCP server.

Starting the service

To start the DHCP server issue the command:

/etc/init.d/dhcp3-server start

You should see no errors. Once your server is up and running go to one of your machines and restart the networking. You should get a new IP address as well as the DNS addresses configured. If your machine does not find the server you may have to configure the DHCP server IP address. This should not be necessary, but it’s good to know in a pinch.

Final thoughts

You probably didn’t realize how simple it would be to set up a DHCP server did you? Now you know. This set up should make for a very reliable DHCP server for your internal network.




Tags: , ,
Categories: Linux, Networks, Open Source, Server, Tutorials Advanced, Tutorials Basic


Read Related Posts


7 Responses to “Configure your Ubuntu Server as a DHCP server”

  1. Manju says:

    Helpful article as usual.

    I do have a few questions. Forgive my noobness.

    1. So will this DHCP server replace my router for assigning addresses to my local LAN .

    2. And if my Ubuntu server is not using eth0 but the wireless interface instead I just have to replace “eth0″, will that be enough.

    3. And I have Ubuntu 8.10. So the config files are the same or is there a difference.

  2. jack says:

    Manju:

    Yes the DHCP server will replace you router. You would want to log into your router and make sure it is configured to no longer assign IP addresses.

    If you are using it with wireless you should just have to replace the eth0 with somethin like wlan0.

    The config should be the same.

  3. Dotan Cohen says:

    Jack, will this let me connect with Windows machines in an ad-hoc wired lan? Specifically, if I connect my Ubuntu laptop with a Windows desktop via crossover cable, can I then access an FTP server on the Ubuntu laptop from the Windows machine to transfer files?

    Thanks in advance for any ideas.

  4. Rush says:

    Jack,
    This is an awesome set of articles. It comes at a good time for me also, because I started toying around with Ubuntu server in a VM about 2 weeks before you started these.
    I have a few quick questions. I installed ubuntu-desktop (I’m a windows wussy that DOVE at the GUI like a gunshot had gone off). Since finding your series I have kind of regretted doing that.
    Should I start over? I am a total noob to Linux. I have tried to follow some of your steps through the terminal but when I try to edit config files (even after sudo and password) it wont let me. A permissions issue. I want to be able to follow the series on my server, and have already redone the darn thing like 20 times already, so starting over is no big deal.
    Would that be easier for me to do to follow this series?

  5. Nitin says:

    Hi,
    Now my DHCP sever gets installed started successfully .How I can check it works over lan network.
    Thanx

  6. Charles says:

    i recently install ubuntu on my machine and after assigning ip address to the machine and the gateway of the router i could not browse, what could be the reason

Trackbacks/Pingbacks

  1. [...] but it’s not. And many might be asking “Why do this when my router does the trick?” More here Most routers do a good job of serving up DHCP addresses. But there are times when those routers [...]

Leave a Reply   Follow Ghacks   Subscribe To Comment Rss

© 2005-2009 Ghacks.net. All Rights Reserved. Privacy Policy - About Us