DHCP service introduction and management configuration of DHCP service under Linux

Source: Internet
Author: User
Tags dhcp reservation

DHCP service introduction and management configuration of DHCP service under Linux


1. Introduction to DHCP Services

DHCP is the Dynamic Host configuration Protocol, which is a way to assign IP addresses to hosts in a physical network, which is distinguished from BOOTP, one-time allocation of the disadvantage of lifetime use.

The concept of a lease proposed by DHCP makes it possible to dynamically determine the IP address required by the host as needed, and the IP address can be recycled.


2. DHCP structure

DHCP is a typical C/s structure that requires the server to start the daemon to ensure that requests from client segments are responded to, and that DHCP works as follows:

Can be remembered by Dora:


Client:dhcp DISCOVER #客户端向相同网络发送广播包, attempting to find a DHCP server

SERVER:DHCP offer#如果DHCP服务段收到DISCOVER包, the client is replied to a send broadcast package

CLIENT:DHCP request#客户端收到来自DHCP的OFFER广播包后, determine the DHCP server and continue sending a request package to the DHCP server to request IP information

Server:dhcp ACK#DHCP服务端向客户端发送ACK包, carry IP and lease information to client, end of DHCP discovery process


Note: DHCP is on the other side of the router across the network segment, and the router needs to turn on DHCP relay to support forwarding client discover broadcast packets to the DHCP server, which are unicast through the router forwarding

Because the connection between the router and DHCP is IP information.


DHCP service-side Port UDP 67

DHCP Client Port UDP 68



DHCP Reservation: Address reserved:

Addresses that are specific to a particular client, should not use addresses in the address pool, and precedence over addresses in the address pool;



3. DHCP service installation configuration under Linux

Since the system management mechanism of CENTOS6/7 is different, the way to boot from the service varies, but the configuration file, the Help document is similar


3.1 CentOS 6 under DHCP installation:

#yum Install DHCP

#通过rpm-ql DHCP to query the installation files created by the HDCP package, we can analyze how he is used:

Here are a few more important documents:


#DHCP服务配置文件:

/etc/dhcp/dhcpd.conf

/etc/dhcp/dhcpd6.conf


#服务脚本, control the start, shutdown, status query, reload, etc. of DHCP service

/etc/rc.d/init.d/dhcpd

/etc/rc.d/init.d/dhcpd6

/etc/rc.d/init.d/dhcrelay

/etc/rc.d/init.d/dhcrelay6


#dhcp命令参数配置文件: This file content provides some sections for the DHCPD daemon to use during system boot, and the DHCPD daemon uses DHCP and BOOTP protocols to automatically assign IP addresses to hosts

/etc/sysconfig/dhcpd

/etc/sysconfig/dhcpd6

/etc/sysconfig/dhcrelay

/etc/sysconfig/dhcrelay6


#dhcp二进制程序

/usr/sbin/dhcpd

/usr/sbin/dhcrelay


#dhcp的ip地址租约库, you can find the IP distribution

/var/lib/dhcpd/dhcpd.leases

/var/lib/dhcpd/dhcpd6.leases


4.1 CentOS6 DHCP service configuration file management:


4.1.1 First edit the DHCP master configuration file:

/etc/dhcp/dhcpd.conf

Option Domain-name "richie.com"; #dhcp主机名

Option Domain-name-servers 192.168.229.141; #名称服务器的地址

Default-lease-time 600; #默认租约秒数

Max-lease-time 7200; #最大租约秒数

Log-facility Local7; #log级别

Subnet 192.168.229.0 netmask 255.255.255.0 {

Range 192.168.229.201 192.168.229.220; #可供分配的ip段

Option Routers 192.168.229.1, 192.168.229.2; #如果在最近配置的option routers then drink directly, if not, it will automatically inherit the upper-level option

} #子网配置格式


When you are finished editing, save exit, you can use this command to detect syntax errors:


Service DHCPD Configtest


4.1.2 Configuring IP Address Reservations:

Need to be inside subnet {}, configure host{} in the following format:

Subnet 192.168.229.0 netmask 255.255.255.0 {


Host WINDOWS1 {

Hardware Ethernet 00:0c:29:0:f3:44;

Fixed-address 192.168.229.222;

Option routers 192.168.0.1 #这里可以针对这台机器设置option The value of routers without inheriting the gateway information on the previous level

}

}


Finally, save the exit

Service DHCPD Force-reload


Test results:

Linux client:

dhclient-d eth0


Window client:

Ipconfig/renew


4.1.3 Configure boot-up:

or the old command chkconfig DHCPD on, the init level 2,3,4,5 is set to boot automatically by default, or you can use the Chkconfig--level 2,3,4 to specify the desired runlevel self-start


4.1.4 Managing DHCP Services

Service DHCPD {Start|stop|restart|force-reload|condrestart|try-restart|configtest|status}



4.2 DHCP service management under CentOS 7

4.2.1 Configuration file:

Configuration on the same CentOS6, see 4.1.1


4.2.2 Configuring IP Address Reservations:

Configuration on the same CentOS6, see 4.1.2


4.2.3 Configure boot-up:

Because of the different system service management mechanism of CENTOS6/7, CentOS7 introduced systemd to manage all the services, so we can no longer use the Chkconfig command to set up, need to use:


# systemctl is-enabled daemon.service View DHCP service status, equivalent to C5 chkconfig--list dhcpd

# Systemctl Enable Daemon.service enabled start-up DHCP service, equivalent to C5 chkconfig dhcpd on

# systemctl Disable Daemon.service disable power On self-starting DHCP service, equivalent to C5 chkconfig dhcpd off


4.2.4 Managing DHCP Services

# systemctl {Start|stop|restart|status} daemon.service




5. Summary of DHCP configuration commands


A configuration file for a simple DHCP service must contain at least the following configuration information:


Dhcpd.conf

Option Domain-name

Option Domain-name-servers

Option routers


Subnet NETWORK netmask MASK {

Range Start_ip end_ip;


Host HOSTID {

Hardware Ethernet 00:11:22:33:44:55;

Fixed-address IP;

}

}



========================================================

Example:

Dhcpd.conf

Option Domain-name "richie.com";

Option Domain-name-servers 192.168.229.141;


Default-lease-time 600;

Max-lease-time 7200;


Log-facility Local7;


Subnet 192.168.229.0 netmask 255.255.255.0 {

Range 192.168.229.201 192.168.229.220;

Option Routers 192.168.229.1, 192.168.229.2;

Host WINDOWS1 {

Hardware Ethernet 00:0c:29:30:f3:44;

Fixed-address 192.168.229.211;

}

}


This article is from the "Richier" blog, make sure to keep this source http://richier.blog.51cto.com/1447532/1665128

DHCP service introduction and management configuration of DHCP service under Linux

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.