Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to setup dhcpd under linux

DHCP

How to setup dhcpd under linux

by  jsauce  Posted    (Edited  )
This FAQ assumes you have root access to your linux machine, dhcp is installed, and also assumes you have some knowledge of the linux operating system.

You will need to find the dhcpd.conf file, this is the configuration file used to configure DHCP.

Let's assume that the files were already there which would be the case for most default systems.

However, if they were not there you would need to create them like so:


touch /etc/dhcpd.conf
mkdir /var/state/dhcp
touch /var/state/dhcp/dhcpd.leases

The dhcpd.conf file will contain all of the configuration data. The dhcpd.leases file will be used by the daemon to keep track of which machines it has leased IP addresses to.


NOTE: You must have multicast support built into your kernel to support dhcp, if you do not have this you will need to recompile your kernel.

This is what the normal dhcpd.conf file may look like:

ddns-update-style interim
default-lease-time 3600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 192.168.1.252, 192.168.1.253;
option domain-name "yourdomain.com";

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.100;
}


If you are setting up a DHCP server supporting more than one subnet, you must create a subnet entry for each of your subnets. For example adding a second subnet would be simple like this:

ddns-update-style interim
default-lease-time 3600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 192.168.1.252, 192.168.1.253;
option domain-name "yourdomain.com";

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.100;
}

subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.50 192.168.2.100;
}

You might also want to assign a static ip address to a specific client based on mac address this can be accomplished by adding this:

host dhcp-client1 {
hardware ethernet 00:B0:2E:05:A1:E3;
fixed-address 192.168.1.51;
}

This is very useful if you plan to firewall and forward packets to specific machines, but want to use DHCP on the whole network. You will always know which machine has which address, very useful.


Now because Windows handles dhcp in a different way, you will need to make some routing changes if you plan to support windows clients.

route add -host 255.255.255.255 dev eth0

NOTE: Make sure you add this line to your boot up file so it gets activated at boot.

You will also need to make a startup script for dhcp to start or add it your bootup like this:

chkconfig --level 35 dhcpd on
chkconfig --level 01246 dhcpd off
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top