stickyimage

Felici is packed with a cool notification manager, alert your visitors the smart way.

Learn More Close

How to install a DHCP-SERVER in Linux Debian Lenny

This 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?

1154 days ago by in Howto. You can follow any responses to this entry through the | RSS feed. You can leave a response, or trackback from your own site.
About

Just a man in Linux and Windows!

14 Comments to How to install a DHCP-SERVER in Linux Debian Lenny
    • Foozie
    • 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 :(

    • Bombaci
    • 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

    • Teste
    • 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

    • Trikks
    • 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

    • holic
    • is ip forwading have a mounting with dhcp ?
      and why dhcp configuration must configure the postrouting ?

    • John
    • 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

    • Bombaci
    • 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…

Leave A Response

Required


*

Spam Protection by WP-SpamFree