Search The Site

Setup and Configure A DHCP Server In Debian

Dynamic Host Configuration Protocol (DHCP) simplifies the management of a network of Internet-connected computers. It's a method for assigning Internet Protocol (IP) addresses permanently or on the fly to individual computers in an organization's network or on your local area LAN. DHCP gives you a central way to configure the network settings for all the computers on your network. As long as your operating system is configured to use DHCP then all you need to do is plug in the network cable. With DHCP you can configure the following.

  • The IP address
  • The network mask
  • The address of the Domain Name Server
  • The address of the WINS server
  • The Host name
  • The Domain Name
  • The Gateway address
  • The Time Server address
  • The Print Server address

Installing a DHCP Server in Debian:

I assume you have 2 Nics with the following configuration:

2 internal nics:
eth0 (For the internet)
eth1 (for your internal network)

Setting up your eth1 nic for dhcp:

The most important thing you need to do is configure your Nic adapter to use a static IP. View my tutorial on how to setup and configure a static IP on Debian for more information.

After you have configured your machine to use a static IP make sure you restart your network interface. To restart the interface open a terminal window and type the following:

/etc/init.d/networking restart and then press Enter

Now we begin installing and configuring the dhcp server. For this tutorial I will be using the following network address: 192.168.8.x .

Install the DHCP module by opening a terminal window and typing the following:

apt-get install dhcp3-server

When the installation process is finished the server will not start automatically. Next, we need to BIND the service to an interface and type in an IP address range for leases.

Binding the interface

Enter the following command in a terminal window:

nano /etc/default/dhcp3-server and press Enter.

Edit the following line

INTERFACES=”"
To
INTERFACES=”eth1″

After you have modified the file press control+x to exit editing the file, you will get a confirmation asking you if you want to save the file. Select Y and press Enter

Next, we need to configure the DHCP-Lease

Next, we need to make a copy of the default configuration file for backup purposes.

Navigate to the following directory in a terminal window: /etc/dhcp3/

Make a backup copy of the configuration file by typing the following command:

cp dhcpd.conf dhcpd.old.conf and press Enter

Now move the backup configuration file to a safe location and remove the original by typing the following: rm dhcpd.conf

Next, create a new dhcp.conf file by typing the following: nano dhcpd.conf

Next copy/paste the following data into the new config file:

subnet 192.168.8.0 netmask 255.255.255.0 {
range 192.168.8.100 192.168.8.149;
option domain-name-servers 192.168.8.1;
option domain-name “seowebz.com”;
option netbios-name-servers 192.168.8.1;
option routers 192.168.8.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.8.255;
default-lease-time 86400;
max-lease-time 676800;
}

After you have modified the file press control+x to exit editing the file, you will get a confirmation asking you if you want to save the file. Select Y and press Enter

Now restart the DHCP server by typing the following: /etc/init.d/dhcp3-server restart

Next, we need to make sure IP forwarding is configured and running.

Launch a terminal window and type the following: nano /etc/sysct1.conf and uncomment the following line: #net.ipv4.ip_forward=1

Open a terminal window and type the following to update the IPTables:

  • iptables -A FORWARD -i eth0 -o eth1 -m state –state ESTABLISHED,RELATED -j ACCEPT
    iptables -A FORWARD -i eth0 -o eth1 -j REJECT
  • iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Next, type the following in a terminal window: nano /etc/init.d/rc.local and add the following information to the stop section

  • iptables-save > /etc/iptables.rule
  • Add the following to /etc/rc.local
  • iptables-restore < /etc/iptables.rule

Congratulations on the successful setup of your own DHCP Server on your Debian box.