Skip to content
Esti Lederer edited this page Sep 7, 2022 · 6 revisions

This section includes the following:

DHCP (Dynamic Host Configuration Protocol) is a protocol used to dynamically assign an IP address to a device on a network.

DHCP Client

DHCP client can be used with a switchport, bridge, bond, or a VLAN sub-interface.

To start a DHCP client on a switchport:

dhclient swp1

To start a DHCP client on a bridge:

ip link add name br0 type bridge
ip link set swp1 master br0
ip lint set swp1 up
dhclient br0

To start a DHCP client on a bond:

ip link add bond1 type bond mode 802.3ad
ip link set swp1 master bond1
ip lint set swp1 up
dhclient bond1

To start a DHCP client on a VLAN sub-interface:

ip link add name br0 type bridge vlan_filtering 1
ip link set dev br0 up
ip link set dev swp1 master br0
bridge vlan add vid 10 dev swp1
bridge vlan add vid 10 dev br0 self 
ip link add link br0 name br0.10 type vlan id 10
dhclient br0.10

For more information about dhclient option, see man page

DHCP Server

A DHCP server listens to UDP port 67 and dynamically assigns IP addresses and other network parameters to DHCP clients.

A DHCP server can be used with a switchport, bridge, bond, or a VLAN sub-interface.

The following is an example configuration of a DHCP server for a network 10.0.0.0/24

Contents of "/etc/dhcp/dhcpd.conf"

option domain-name "example";
option domain-name-servers 10.0.0.1;
subnet 10.0.0.0 netmask 255.255.255.0 {
    range 10.0.0.100 10.0.0.200;
    option subnet-mask 255.255.255.0;
    option broadcast-address 10.0.0.255;
    option routers 10.0.0.01;
}
default-lease-time 600;
max-lease-time 7200;
authoritative;

For more information on DHCP Server options, see wiki page

DHCP Relay

The DHCP Relay Agent (dhcrelay) is a service that forwards DHCP packets between clients and servers that are not on the same physical subnet. It is defined by RFC3046.

dhcrelay enables the relay of DHCP and BOOTP requests from a subnet with no DHCP server on it, to one or more DHCP servers on other subnets.

When a DHCP client requests information, dhcrelay forwards the request to the list of DHCP servers specified when the dhcrelay was started. When a DHCP server returns a reply, the reply is broadcast or unicast on the network that sent the original request.

To configure DHCP relay on an interface, this interface must have an IP address assigned.

ip address add dev <interface_1> <IP_ADDR>
dhcrelay -4 -d -i <interface_1> <dhcp server ip> 

Where <interface_1> can be a switchport, bridge, bond, or a VLAN sub-interface.

Clone this wiki locally