Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Install DHCP server on Debian

Leer en espanol
Install DHCP server on Debian

Table of contents

DHCP (Dynamic Host Configuration Protocol) It is a ===

Before starting to install, let's remember some basic but important concepts.

DHCP (Dynamic Host Configuration Protocol)

It is a client/server type protocol in which a server generally has a list of dynamic IP addresses and assigns them to clients as they become free, knowing at all times who has been in possession of that IP, how long they have had it and to whom it has been assigned afterwards.

LISTEN BY THE PORT: 68 UDP
TRABSNUTE THROUGH THE PORT: 67 UDP

What is a DHCP Relay Agent: It is a software that relays messages DHCP and BOOTP between clients and servers on different subnets.

How the Relay Agent works

DHCPDISCOVER: It is a request that a machine makes when it turns on. (just by pressing the power button on the device you can do it)

DHCPOFFER: It is the connection that the DHCP server gives to the PC.

DHCPREQUEST: The client requests the connection.

DHCPACK or NOT ACK: That is, it gives you the assignment or It does not give you the assignment.

MAP:

Dhcp debian red orbita

The DHCP database


There is no defined limit to the number of records that a DHCP server can store. The size of the database depends on the number of DHCP clients on the network. The DHCP database grows over time as clients start and end sessions on the network

Address Range

This method is based on defining a pool of IP addresses for DHCP clients (also called IP address pool) that supply their configuration properties dynamically as requested by client computers. When a DHCP client is no longer on the network for a certain period, the configuration expires and the poll's IP address is released for use by other DHCP clients.


MAC address

This method is based on using the DHCP protocol to identify the unique hardware address of each network card connected to the network and then assigning a constant configuration as well as the same IP address each time the client's DHCP configuration makes a request to the DHCP server from the same network device.


Before starting to install the DHCP server, you might be interested in seeing how install DNS server

Install DHCP

In a console we execute:

Bash
rokitoh@redorbita:~# apt-get install dhcp3-server
Configure DHCP

Before starting we will make a backup of the configuration file… just in case

Bash
rokitoh@redorbita:~# cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.back
Configure using the address range method (IP pool)

We access dhcp.confg
Bash
rokitoh@redorbita:~# nano /etc/dhcp2/dhcp.confg
We go to the end of the file and add
text
default-lease-time 600;

max-lease-time 7200;

option subnet-mask 255.255.255.0;

option broadcast-address 192.168.1.255;

option routers 192.168.1.1;

option domain-name-servers 192.168.1.233;

option domain-name “redorbita.com”;

subnet 192.168.1.0 netmask 255.255.255.0 {

range 192.168.1.2 192.168.1.200;

}
We save the file by giving: ctrl + O
default-lease-time 600; indicates the allocation time in seconds.
max-lease-time 7200; indicates the maximum allocation time in seconds.
option subnet-mask 255.255.255.0; We define the general network mask that we are going to use.option broadcast-address We define the broadcast address of the network.option routers 192.168.1.1; We define the network gateway. 

option domain-name-servers 192.168.1.233; We define the address of the DNS server of the network.

option domain-name “redorbita.com”; We define the DNS domain name that is added to the host names.

range 192.168.1.2 192.168.1.200; We define the range of IP assignment to clients.

Configure using the MAC address method

With this method you can reserve some or all of the IP addresses on our network for certain machines. As you can see, the configuration is very similar to the previous one, with the exception that to reserve the assignment of an IP to a certain NIC (network card interface) we must use the label host

text
default-lease-time 600;

max-lease-time 7200;

option subnet-mask 255.255.255.0;

option broadcast-address 192.168.1.255;

option routers 192.168.1.1;

option domain-name-servers 192.168.1.233;

option domain-name “redorbita.com”;

subnet 192.168.1.0 netmask 255.255.255.0 {

range 192.168.1.2 192.168.1.200;

}
host oracle{ hardware ethernet 00:03:47:31:e1:7f; fixed-address 192.168.1.20; } host printer { hardware ethernet 00:03:47:31:e1:b0; fixed-address 192.168.1.21; }
We restart our DHCP server
CODE
Bash
rokitoh@redorbita:~# /etc/init.d/dhcp3-server restart Starting DHCP server: dhcp3
Configure the DHCP client in GNU/Linux

If you want to configure a desktop or machine with Linux as a DHCP client, follow the following steps:

  • We edit the network interfaces file
Bash
rokitoh@redorbita:~# nano /etc/network/interfaces

We must have the following lines, taking into account that eth0 is an example

text
auto lo eth0
iface eth0 inet dhcp
iface lo inet loopback

We save and exit the file

We configure the /etc/resolv.conf file

Bash
rokitoh@redorbita:~# gedit /etc/resolv.conf

and we add the domain name and ip:

text
domain redorbita.com
nameserver 192.168.1.233

We restart

Bash
rokitoh@redorbita:~# /etc/init.d/networking restart

In order to know the addresses assigned to client machines

Bash
rokitoh@redorbita:~# tail -n 15 /var/lib/dhcp3/dhclient.*.leases

Popularity: 16%

Sources:

http://dns.bdat.net/dhcp/x84.html

http://tecnoloxiaxa.blogspot.com/2008/10/instalar-y-configurar-un-servidor-dhcp.html

http://www.guatewireless.org/os/linux/distros/debian/ubuntu/como-instalar-y-configurar-un-servidor-dhcp-en-linux-ubuntu-debian/

Comments