How to install and configure DHCP servers in CentOS

Source: Internet
Author: User
DHCP (Dynamic Host Configuration Protocol) is a service for centralized management of network information such as IP addresses. Build a Linux host in the Lan as the DHCP server, and set other hosts to obtain the network information of the host from the DHCP server, this can greatly simplify the network configuration of all hosts by the system administrator, as well as reasonable planning and allocation of IP addresses. The main content of this article is to use DHCP for automatic

DHCP (Dynamic Host Configuration Protocol) is a service for centralized management of network information such as IP addresses. Build a Linux host in the Lan as the DHCP server, and set other hosts to obtain the network information of the host from the DHCP server, this can greatly simplify the network configuration of all hosts by the system administrator, as well as reasonable planning and allocation of IP addresses. This document describes how to configure and manage DHCP servers and how to use DHCP clients.

The DHCP concept can be explained as follows:

  • DHCP is a network protocol that enables dynamic configuration of host IP addresses and DNS.
  • DHCP can be implemented in multiple operating systems, including common linux and Windows systems.
  • The structure of the DHCP network service has two roles: server and client.
  • The DHCP server is used to provide network configuration information for all DHCP clients in the network. in the same network, the DHCP server is usually unique.
  • Any host in the network can be configured as a DHCP client, which sends a configuration request to the DHCP server and configures the network according to the information returned by the server.

In practice, the DHCP server can provide the following network configuration information for the client after being configured:

  • The IP address and subnet mask of the network interface.
  • The network address and broadcast address corresponding to the IP address of the network interface.
  • The default gateway address.
  • DNS server address.

The following describes how to install the dhcp server on CentOS and how to set parameters:

1. download and install

In

# tar zxvf dhcp-4.2.1.tar.gz# cd dhcp-4.2.1# ./configure# make# make install

2. network interface configuration

# vim /etc/sysconfig/dhcpd
# Specify the network interface name and enable the dhcp service on the eth0 network interface. DHCPDARGS = eth0

3. create a DHCP server lease file

# touch /var/db/dhcpd.leases

Note: If this file is not created, the following error message is displayed when you start the service:

WARNING: host declarations are global. They are not limited to the scope you declared them in.Can't open lease database /var/db/dhcpd.leases: No such file or directory --

4. manually create the DHCP master configuration file dhcpd. conf

ddns-update-style none;default-lease-time 21600;max-lease-time 43200;option domain-name "linuxde.net";option domain-name-servers 192.168.3.200;subnet 192.168.3.0 netmask 255.255.255.0 {        range 192.168.3.100 192.168.3.200;        option subnet-mask 255.255.255.0;        option routers 192.198.3.1;host server1 {        hardware ethernet b0:c0:c3:22:46:81;        fixed-address 192.168.3.100;}}

There is a configuration file template in the source package, you can refer to: dhcp-4.2.1/server/dhcpd. conf

A detailed description of the dhcpd. conf configuration file:

Global Settings

  • Ddns-update-style parameter: sets the dynamic information update mode between the DHCP server and the DNS server. Generally, the DHCP server does not consider setting this option, however, the global settings must include the ddns-update-style setting dhcpd to enable normal startup. Set interim to interactive updates with DNS. Set to none to disable automatic updates.
  • Default-lease-time parameter: sets the default lease time. the unit of the parameter value is second. The default lease time indicates the default lease time for the client to lease an IP address from the server. after a long time, the client will send a request to the server to continue renting the IP address.
  • Max-lease-time parameter: sets the maximum lease time. the unit of the parameter value is second. When the client lease address reaches this time, you cannot continue to lease this IP address.
  • Option domain-name parameter: Set the name of the domain where the host is located. the domain name and host name together constitute the host's full name.
  • Option domain-name-servers parameter: sets the DNS server address. after this parameter is set, the client DNS uses this address. if you want to set multiple DNS addresses, separate them with commas.

Use subnet declaration to set subnet properties

  • Set the network address after subnet, and set the subnet mask after netmask.
  • Range parameter: sets the range of IP addresses that can be dynamically allocated in subnet. the parameter value must be within the subnet set in subnet; otherwise, it cannot be started.
  • Subnet-mask parameter: sets the subnet mask. after the subnet mask is set, you do not need to set the network address and broadcast address.
  • Routers parameter: set the default gateway.

Host declaration is used to set host properties. it is usually used to assign a fixed IP address to the server.

  • The host name must be set for the DHCP client host.
  • Hardware parameter: sets the physical address (MAC address) of the client host. because ethernet is usually used, the hardware parameter type is set to ethernet.
  • Fixed-address: Set the client specified in the host declaration to assign a fixed IP address.

5. start the DHCP server.

# dhcpdInternet Systems Consortium DHCP Server 4.2.1Copyright 2004-2011 Internet Systems Consortium.All rights reserved.For info, please visit https://www.isc.org/software/dhcp/WARNING: Host declarations are global. They are not limited to the scope you declared them in.Wrote 0 deleted host decls to leases file.Wrote 0 new dynamic host decls to leases file.Wrote 0 leases to leases file.Listening on LPF/eth0/00:0c:29:6b:b5:0d/192.168.3.0/24Sending on LPF/eth0/00:0c:29:6b:b5:0d/192.168.3.0/24Sending on Socket/fallback/fallback-net

It indicates that it has been started successfully. if you want to write a DHCP startup script, you don't think it is necessary. If you have written this article, could you share it with us? :) after the server is configured, check the/var/db/dhcpd. leases file to learn about the IP address lease of the DHCP server.

Configuration of DHCP client (Linux client)

Network interface configuration file

# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0ONBOOT=yesBOOTPROTO=dhcp

Restart network interface

# ifdown eth0 ; ifup eth0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.