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 adress 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?
10 Comments for this entry
![]()
Subscribe
May 31st, 2009 on 22:30
You have a typo in the range of IP’s… 192.168.1.10 192.168.0.100… change the zero to one.
May 31st, 2009 on 22:59
Thanks! Didn’t saw that typo :$
February 8th, 2010 on 12:30
thanks!
just one question:
what does mean “routers”?
February 20th, 2010 on 18:13
Thats one if you use a route ip, you can remove the line if you want.
March 15th, 2010 on 12:03
Thanks for your tuto,
it was good for us.
March 15th, 2010 on 12:05
Your welcome!
June 1st, 2010 on 08:34
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
June 2nd, 2010 on 10:22
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
June 13th, 2010 on 19:08
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
June 13th, 2010 on 23:32
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