DHCP service in Linux network service

One, understand the DHCP service

1、DHCP(Dynamic Host Configuration Protocal,动态主机配置协议)
2、专门用于TCP/IP网络中的计算机自动分配TCP/IP参数的协议
3、使用DHCP的好处
减少管理员的工作量
避免输入错误的可能
当更改IP地址段时,不需要重新配置每个用户的IP地址
提高了IP地址的利用率
方便客户端的配置
4、DHCP的分配方式
自动分配:分配到一个IP地址后永久使用
手动分配:由DHCP服务器管理员专门指定IP地址
动态分配:使用完后释放该IP,供其他客户机使用

2. DHCP lease process

Insert picture description here

1. The client requests an IP address.
When a DHCP client starts, the client does not yet have an IP address, so the client needs to obtain a legal address through DHCP.
At this time, the DHCP client sends a DHCP Discover message to find DHCP by broadcasting. server

Insert picture description here

2. When the server responds to the
DHCP server receiving the information requesting the IP address from the client, it searches its own IP address pool to find out whether there is a legal IP address provided to the client.
If so, the DHCP server marks the IP address and adds it To the DHCP Offer message, and then broadcast a DHCP Offer message
Insert picture description here

3. The client selects the IP address. The
DHCP client extracts the IP address from the first DHCP Offer message it receives, and the DHCP server that sends out the IP reserves the address so that the address cannot be assigned to another DHCP client.

Insert picture description here

4. After the server confirms the lease
DHCP server receives the DHCP Request message, it broadcasts a successful confirmation to the client in the form of a DHCP ACK message, which contains the valid lease of the IP address and other configurable information.
When the client receives the DHCP ACK When message, configure the IP address, complete the initialization of TCP/IP
Insert picture description here

5. Re-login to the
DHCP client every time you re-login to the network, you do not need to send DHCP Discover information, but directly send the DHCP Request request information containing the IP address assigned the previous time. The IP address is
not assigned
Insert picture description here

The IP address is assigned
Insert picture description here

6. Renew the lease.
When the lease of the IP address leased by the DHCP server to the client reaches 50%, the lease needs to be renewed. The
client directly sends a DHCP Request packet to the server that provides the lease, requesting to renew the existing address lease.

Three, use DHCP to dynamically configure the IP address

1、DHCP服务
为大量客户机自动分配地址,提供集中管理
减轻管理和维护成本,提高网络配置效率
2、可分配的地址信息主要包括
网卡的IP地址、子网掩码
对应的网络地址、广播地址
默认网关地址
DNS服务器地址
租期

Four, Linux service setup steps

1、安装服务
2、修改配置文件
3、服务启动/重启
4、通过netstat –anpt/-anpu/-anput | grep 服务名称/端口号
5、客户机测试

Five, learning methods

1、使用场合
2、工作原理
3、使用方法(包含要修改哪些参数对应哪些功能)
4、如果实验过程中出现一些问题,发现并解决问题,把这个故障点及对应的解决方法写进文档里

Six, install DHCP service

1、安装DHCP服务
rpm –ivh /mnt/Packages/dhcp-4.2.5-58.el7.centos.x86_64.rpm
2、复制样例为dhcp配置文件
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
3、配置dhcp的配置文件
vi /etc/dhcp/dhcpd.conf;
ddns-updata-style none;   //
default-lease-time 21600;
max-lease-time 43200;
option domain-name “bdgn.com”;
option domain-name-servers 202.106.0.20,202.106.148.1;
***************下发地址段的配置选项****************
subnet 192.168.4.0 netmask 255.255.255.0 {
range 192.168.4.128 192.168.4.254;
option routers 192.168.4.1;
}
********************设置保留地址********************
host prtsvr {
hardware Ethernet 00:c0:c3:22:46:81;
fixed-address 192.168.4.100;
}
4、启动DHCP服务
systemctl start dhcpd
netstat –anpu | grep dhcpd
5、客户端设置为dhcp启动
Vi /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
ONBOOT=yes
BOOTPROTO=dhcp
6、客户机设置ens33网卡dhcp获取地址
dhclient –d ens33
7、服务器查看客户机获取地址的情况
less /var/lib/dhcpd/dhcpd.leases
8、客户机设置ens33网卡释放获取到的地址
dhclient –r ens33 

Guess you like

Origin blog.csdn.net/yuiLan0/article/details/108509255