[HowTo][Linux/Debian] Setting up a DHCP server

DON'T post new tutorials here! Please use the "Pending Submissions" board so the staff can review them first.
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

[HowTo][Linux/Debian] Setting up a DHCP server

Post by ayu »

There might come a situation when you need a DHCP server in your network to hand out the TCP/IP configuration for your workstations. This HowTo will show you how it's done in Linux/Debian (Works the same in Ubuntu).


What is a DHCP?

Every computer that is connected to a network and that uses TCP/IP, needs TCP/IP configurations, and since it's not practical and effective to be giving these out manually every time you start your computers in your network, DHCP servers exists. DHCP stands for Dynamic Host Control Protocol, and is a service that simply delivers TCP/IP configurations for computers in a network and "lends" them IP addresses.


Installing the DHCP server

First of all you have to of course install the server itself, and in Debian this can easily be done by using the apt-get command to download and install it from the Debian repository.

Code: Select all

apt-get install dhcp3-server


Configuring the DHCP server

Then you have to configure the DHCP server to fit your needs, you have to invoke the following command to edit the config file, also take your time to discover the other files that are located in the /etc/dhcp3 folder.

Code: Select all

nano /etc/dhcp3/dhcpd.conf
Add these settings at the top of dhcpd.conf

Code: Select all

ddns-update-style none;
ddns-updates off;
deny client-updates;
one-lease-per-client false;
allow bootp;
option T150 code 150 = string;

ddns-update-style none : ddns or Dynamic DNS is a method for clients to tell a DNS server to change it's configurations. This option can either be interim, none or ad-hoc. I recommend using none for starters.

ddns-updates off : same as above, simply shuts it off completely

deny client-updates : If this is set, a client can not update it's configuration. It will have to either drop the leasing of the IP address or wait until the leasing time goes out.

one-lease-per-client false : if this is set to false, a client can have more then one lease.

allow bootp : bootp is commonly used by nodes that doesn't have a harddrive to get a configuration, it basically means that your computer can get the configurations during startup.


And these at the bottom, in this example they are specifik for my network, so you will have to edit the file to fit your needs.

Code: Select all

subnet 10.0.0.0 netmask 255.255.255.0 {
    interface eth1;
    range 10.0.0.10 10.0.0.254;
    default-lease-time 6000;
    max-lease-time 7200;
    option subnet-mask 255.255.255.0;
    option broadcast-address 10.0.0.255;
    option routers 10.0.0.1;
    option domain-name-servers 192.168.0.1;
    option time-offset -3600;
}
This is the default settings for any machine that requests a configuration.

subnet 10.0.0.0: The network id

netmask 255.255.255.0: The netmask for the network, netmasks are often used to split ip ranges in smaller networks, but this one is a default one (for the wrong IP class but, meh ^^)

interface eth1: The network interface the server till be listening on.

range 10.0.0.10 10.0.0.254: The IP range it will deliver.

default-lease-time 6000: the default time a lease is held, the default time a computer can borrow an IP before the server checks if it still wants it. You should set this to a higher number, to reduce errors and traffic.

max-lease-time 7200: maximum time it can borrow an IP.

The options below are the configurations that the DHCP server will send to the client requesting the configuration.

option subnet-mask 255.255.255.0: This one was explained before ^^

option broadcast-address 10.0.0.255: The address the computer will broadcast on. Broadcast is used for different things, for example when the client wants to find another clients name, or if it wants a DHCP server to respond when it doesn't have one, it will send out a broadcast on the network.

option routers 10.0.0.1: The default router/gateway. A router is a node that divides a network in two basically, this is almost always your "broadband router". A router has 2 IP's for your information, but I wont explain that here.

option domain-name-servers 192.168.0.1: If you have a DNS server on the network you can use this option. Notice that the IP is of a totally different class then the ones given out by the DHCP. This is because that is the IP of a second router on my home network, which is the primary one that I use.

option time-offset -3600: Explains itself, note that the time offset is set in seconds.



These are simply specific configurations for some of my computers, most of them should be easy to understand now since I just explained them above. But I will explain those that I didn't

Code: Select all

host Enma {
    hardware ethernet xx:xx:xx:xx:xx:xx;
    fixed-address 10.0.0.2;
}
host Teresa {
    hardware ethernet xx:xx:xx:xx:xx:xx;
    fixed-address 10.0.0.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 10.0.0.255;
    option routers 10.0.0.1;
    option domain-name-servers 192.168.0.1;
}
hardware ethernet xx:xx:xx:xx:xx:xx : this is the MAC address of the specified computer, this is very important for the DHCP server to know which computer is to be given the special settings.


Well, the rest, I leave to you now. Have fun, I had ^^
"The best place to hide a tree, is in a forest"

User avatar
Swan
Knight of the Sword
Knight of the Sword
Posts: 827
Joined: 18 Oct 2006, 16:00
17
Contact:

Post by Swan »

capital work cats, simply capital.

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Swan wrote:capital work cats, simply capital.
ey chap
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post by bad_brain »

sweet, good work! :)

User avatar
Still_Learning
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 1040
Joined: 11 Jun 2008, 16:00
15
Location: Trigger City

Post by Still_Learning »

Very good tutorial! Any links on where we can find out what the code means or how to create / edit our own code for the config file?

My routers also use DHCP, right now i am having a DHCP problem, i think since i have 2 routers ones default is 192.168.2.1 one is 192.168.1.1 so it is creating two subnets and making it where i cannot file share locally from my pc's on one of the routers. I was told to turn off dhcp on one of the routers, reboot the router and pc and it should work. I tried that and it gave me limited connectivity issue :?:

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post by bad_brain »

what is the private IP of your computer?

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

itzm3 wrote:Very good tutorial! Any links on where we can find out what the code means or how to create / edit our own code for the config file?

My routers also use DHCP, right now i am having a DHCP problem, i think since i have 2 routers ones default is 192.168.2.1 one is 192.168.1.1 so it is creating two subnets and making it where i cannot file share locally from my pc's on one of the routers. I was told to turn off dhcp on one of the routers, reboot the router and pc and it should work. I tried that and it gave me limited connectivity issue :?:

Turning off DHCP wont solve that though, you would have to turn of the routing function as well as the firewall if present in the second router, basically turning it into a switch.
"The best place to hide a tree, is in a forest"

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
18
Location: In your eye floaters.
Contact:

Post by bad_brain »

yeah, or try setting the subnet of both routers (and your computer) to 255.255.0.0 so all can be in the same subnet... :wink:

Post Reply