You Are Reading

0

How to install a DHCP-SERVER in Linux Debian Lenny

Bay | Site Selasa, 10 Agustus 2010

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

  • VilleWitt

    You have a typo in the range of IP’s… 192.168.1.10 192.168.0.100… change the zero to one.

  • Bombaci

    Thanks! Didn’t saw that typo :$

  • printsy

    thanks!
    just one question:
    what does mean “routers”?

  • Bombaci

    Thats one if you use a route ip, you can remove the line if you want.

  • Mark

    Thanks for your tuto,
    it was good for us.

  • 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

0 komentar:

Posting Komentar

 
Copyright 2010 Bay | Site - vault YUI Lovers Community