1. Introduction to DHCP Service
DHCP is Dynamic host Configuration Protocol, which is a way to assign IP addresses to hosts in a physical network, distinguishing them from BOOTP, and assigning a lifetime use disadvantage.
The concept of a DHCP-proposed lease makes it possible to dynamically determine the IP address required by the host as needed, and the IP address can be reused.
2. DHCP structure
DHCP is a typical C/s structure, requires the server to start the daemon to ensure that requests from the client segment can be responded to, the principle of DHCP work as follows:
Can be remembered by Dora:
Client:dhcp DISCOVER #客户端向相同网络发送广播包, attempting to find a DHCP server
Server:dhcp offer# If the DHCP service segment receives a discover packet, reply to the client for an offer broadcast packet
CLIENT:DHCP request# Client receives an offer broadcast packet from DHCP, the DHCP server is determined to continue sending the request package to the DHCP server to request IP information
SERVER:DHCP ACK#DHCP server sends ACK packets to the client, carries IP and lease information to the client, and the DHCP discovery process ends
Note: DHCP is on the other side of the router across the network segment, the router needs to turn on DHCP relay to support forwarding the client Discover broadcast packets to the DHCP server, which are unicast via router forwarding
Because the connection between the router and DHCP has IP information.
DHCP Server Port UDP 67
DHCP Client Port UDP 68
DHCP Reservation: Address reservation:
Addresses that are specific to a particular client should not be used in the address pool, 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 mode of boot-start service differs, but the configuration file, the Help document is very similar
3.1 CentOS 6 DHCP Installation:
#yum Install DHCP
#通过rpm-ql dhcp to query the files created by the HDCP package, we can analyze how he uses it:
Here are a few more important documents:
#DHCP服务配置文件:
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
#服务脚本, control the start of DHCP service, shutdown, status inquiries, reload, etc.
/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 extents for the dhcpd daemon to be used during system boot, and the DHCPD daemon automatically assigns IP addresses to the host using DHCP and BOOTP protocols
/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 profile 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, then automatically inherit the option at the top level
} #子网配置格式
When you finish editing, save exit, you can use this command to detect syntax errors:
Service DHCPD Configtest
4.1.2 Configure IP Address reservation:
Required within subnet {}, the configuration host{} format is as follows:
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 routers value without inheriting gateway information at the upper level
}
}
Finally, save the exit
Service DHCPD Force-reload
Test effect:
Linux client:
dhclient-d eth0
Window client:
Ipconfig/renew
4.1.3 Configuration boot from:
or the old command. Chkconfig dhcpd on, by default, the init level 2,3,4,5 is set to power on, or you can use Chkconfig--level 2,3,4 to specify the run level you want to boot
4.1.4 Manage DHCP Service
Service DHCPD {Start|stop|restart|force-reload|condrestart|try-restart|configtest|status}
DHCP service management under 4.2 CentOS 7
4.2.1 Configuration file:
Configuration on the same CentOS6, see 4.1.1
4.2.2 Configure IP Address reservation:
Configuration on the same CentOS6, see 4.1.2
4.2.3 Configuration boot from:
Because of the different CENTOS6/7 system service management mechanism, CENTOS7 introduced SYSTEMD to manage all the services, so it is no longer possible to use the Chkconfig command to set the:
# systemctl is-enabled daemon.service View DHCP service status, equivalent to C5 chkconfig--list
# Systemctl Enable Daemon.service enables the power-on from boot DHCP service, equivalent to C5 chkconfig dhcpd on
# systemctl Disable Daemon.service disables the power-on boot DHCP service, which is equivalent to C5 chkconfig dhcpd off
4.2.4 Manage DHCP Service
# systemctl {Start|stop|restart|status} daemon.service
5. DHCP Configuration Command Summary
A configuration file for a simple DHCP service needs to 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;
}
}
Note : More wonderful tutorials Please pay attention to the triple computer tutorial section, triple Computer office group: 189034526 welcome you to join