How to install a DHCP-SERVER in Linux Debian Lenny
Categories: Tutorials - Tags: Debian DHCP-Server, Debian Lenny DHCP Server, installing dhcp3 server, Linux DHCP3 server configurationThis is my second post on my blog, it has bin a while you know busy with school work etc.. But well let’s begin…
Installing a DHCP-Server is not that hard actually…
I assume you have the following configuration on your machine:
- 2 internal nics:
- eth0 (For the internet)
- eth1 (for the internal network)
1. Setting up your eth1 for dhcp use
The most important thing you need to do is configuring static ip adresses.
I will use the following IP address 192.168.1.x as my ip-adress range.
We type the following command: nano /etc/network/interfaces (I use nano cause in my opinion nano is much more easier then vi and it does the same job for me)
And be sure the settings are the same as below:
auto eth1 iface eth1 inet static address 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255
After you have modified the file press control+x you will get a confirmation telling you to save the file yes or no.. We do Y and press Enter
restart the network interface type:
/etc/init.d/networking restart
And press enter.
2. Installing and configuring the dhcp server
If you have completed the step above we are going to install the dhcp and configure it.
First lets install the module:
apt-get install dhcp3-server
After a while it gives a blue screen with a warning. Just press enter and let him install.
When it finished installing the server will not start. We need to bind him to a interface and give a IP range to lease.
2.1 Binding the interface
Enter the following command
nano /etc/default/dhcp3-server
Press enter
Edit the following line
INTERFACES=""
To
INTERFACES="eth1"
After you have modified the file press control+x you will get a confirmation telling you to save the file yes or no.. We do Y and press Enter
2.2 configuring the DHCP-Lease
We are at the final step and after that we have a full DHCP Server Running!
We are not going to use the default config file of the dhcp server however we are going to keep a copy of the config file.
go to the following directory:
cd /etc/dhcp3/
Make a backup copy of the following config file by typing the following command:
cp dhcpd.conf dhcpd.old.conf
And press Enter.
Now remove the file that you have backuped (we are going to make a new one in the next step)
rm dhcpd.conf
We make the new dhcpd.conf in this step as I promised type:
nano dhcpd.conf
Now copy/paste the following data into the file
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option domain-name-servers 192.168.1.1;
option domain-name "Failserver.nl";
option netbios-name-servers 192.168.1.1;
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
default-lease-time 86400;
max-lease-time 676800;
}
After you have modified the file press control+x you will get a confirmation telling you to save the file yes or no.. We do Y and press Enter
Now restart the DHCP3 server
/etc/init.d/dhcp3-server restart
And now you have your own linux DHCP SERVER! Easy huh?

You have a typo in the range of IP’s… 192.168.1.10 192.168.0.100… change the zero to one.
Thanks! Didn’t saw that typo :$
thanks!
just one question:
what does mean “routers”?
Thats one if you use a route ip (Thats your gateway address)
IP
MASK
(ROUTE IP)GATEWAY
DNS
Thanks for your tuto,
it was good for us.
Your welcome!
The DHCP worked perfect after these steps, but then I cannot connect to internet.
eth0 is 192.168.2.1
eth1 is 192.168.1.1
ADSL modem is 192.168.2.2
I’ve tried them all as option routers value, but it still failed
Dear Foozie,
To share a connection you need to use ipmasq and dnsmasq:
# apt-get install dnsmasq ipmasq -y
# dpkg-reconfigure ipmasq
After this run:
#ipmasq
Test it first before using it in a working environment
After installing ipmasq and dnsmasq via apt-get install, is there any configuration that is required so that PCs on eth1 can get to internet on eth0?
thx
Your guide is one of the best, however it’s not complete. I’d recommend you to add this
# Make sure that ip forwarding is running
# Add this to rc.local for automatic start
echo 1 > /proc/sys/net/ipv4/ip_forward
# Or uncomment this line in /etc/sysctl.conf
net.ipv4.ip_forward=1
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
# add to stop section in /etc/init.d/rc.local
iptables-save > /etc/iptables.rule
# add to /etc/rc.local
iptables-restore < /etc/iptables.rule
Happy routing
is ip forwading have a mounting with dhcp ?
and why dhcp configuration must configure the postrouting ?
IP forwarding does not mount with the DHCP it’s a module that routes IP addresses and DNS request to an other NIC in the machine.
For information about postrouting pleas read this article: http://www.centos.org/docs/4/4.5/System_Administration_Guide/postrouting-ipmasquerading.html
Does you linux dhcp server work with a cisco router with a helper address? i cannot get mine to work
I only get…
Oct 21 21:54:13 ubuntu-10 dhcpd: DHCPOFFER on 10.115.50.4 to 00:10:4e:07:02:d1 via 10.115.50.1
Oct 21 21:54:15 ubuntu-10 dhcpd: DHCPDISCOVER from 00:10:4e:07:02:d1 via 10.115.50.1
Oct 21 21:54:15 ubuntu-10 dhcpd: DHCPOFFER on 10.115.50.4 to 00:10:4e:07:02:d1 via 10.115.50.1
Oct 21 21:54:17 ubuntu-10 dhcpd: DHCPDISCOVER from 00:10:4e:07:02:d1 via 10.115.50.1
Oct 21 21:54:17 ubuntu-10 dhcpd: DHCPOFFER on 10.115.50.4 to 00:10:4e:07:02:d1 via 10.115.50.1
You must set the IP helper per cliënt ethernet port:
ip helper-address
Example:
interface FastEthernet 1
ip helper-address 192.168.36.25
But this should work normally…