DHCP
1. Understand DHCP
1.1 What is DHCP
DHCP: Dynamic Host Configuration Protocol, designed and developed by the intern work task group, is a protocol specially used to assign tcp/ip parameters to the winning computer of the tcp/ip network department. DHCP is
a LAN network protocol, which refers to a segment of ip addresses controlled by the server Scope, the client can automatically obtain the ip address and subnet mask assigned by the server after logging in to the server. By default, DHCP, as a service component of windows serve, will not be automatically installed by the system, and the administrator needs to manually install and configure it.
DHCP adopts c/s architecture, c-client (client), s-server (server), client/server architecture
The DHCP service uses the transport layer udp protocol, the client uses port 68 of the udp protocol, and the server uses port 67 of the udp protocol.
1.2DHCP benefits
1. Reduce the workload of the administrator
2. Avoid the possibility of input errors
3. Avoid ip address conflicts
4. When changing the ip address segment, there is no need to reconfigure the ip address of each
user
.Convenient client configuration
1.3DHCP allocation method
- Automatic allocation: permanent use after allocation to an ip address
- Manual allocation: the ip address is specially assigned by the DHCP server administrator
- Dynamic allocation; release the ip address after use for other clients to use
1.4DHCP a complete process
1. When the client joins the LAN without an address, it will send a discover message to find the dhcp server.
2. The dhcp server that receives the message will reply an offer message and put the configuration information in the offer message (ip , subnet, gateway, dns and other information)
3. After the client receives the offer message, it will drop the address and other information configuration, and will reply a request message
4. The server will send an ack message again after receiving the request message confirm
1.5 DHCP messages
DHPC DISCOVER | The first message sent by the client when it logs in to the network for the first time is used to find the dhcp server |
---|---|
DHCPoffer | The DHCP server is used to respond to the DHCP DISCOVER message, which carries various configuration information |
DHCP REQUEST | Client requests configuration confirmation, or lease renewal |
DHCP ACK | The server's confirmation response to the REQUEST message |
DHCP WANT | The server's rejection response to the REQUEST message |
2. DHCP in Linux system
2.1 Install DHCP service
dhcp is used to run a DHCP server on a Linux system
1.yum install -y dhcp
2.rpm -qi dhcp 查看dhcp的安装状态
3.systemctl start dhcpd 开启dhcp
ss -nap | grep dhcp 查看dhcp的端口和协议
2.2 Configuration file
1.rpm -qc dhcp 查询配置文件的位置
2.cp /usr/share/doc/dhcp*/shcpd。conf。example /etc/dhcp/dhcpd.
conf
3.vim /etc/dhcp/dhcpd.conf 编辑配置文件
#设置全局配置参数
defau7t-lease-time 21600; #默认租约为6小时,单位为秒I
max-lease-time 43200; #最大租约为12小时,单位为秒
option domain-name "benet.com"; #指定默认域名
option domain-name-servers 202.106.0.20,202.106.148.1; #指定DNS服务器地址
ddns-update-style none; #禁用DNS动态更新
#subnet网段声明(作用于整个子网段,部分配置参数优先级高于全局配置参数)
subnet 192.168.100.0 netmask 255.255.255.o {
#声明要分配的网段地址
range 192.168.100.128 192.168.100.200; #设置地址池
option routers 192.168.100.1; #指定默认网关地址
#host主机声明(给单机分配固定的IP地址)
host hgstname{
#指定需要分配固定IP地址的客户机名称
hardware ethernet 00:c0:c3:22:46:81; #指定该主机的MAC地址
fixed-address 192.168.4.100; #指定保留给该主机的IP地址
3. Simulate the realization of DHCP service
1. Use virtual machine A as a DHCP server to assign an address to another virtual machine B so that virtual machine B can network
模拟过程
1. Turn off the DHCP
virtual machine B of the virtual machine and there is no network state
2. Turn off the firewall
1.systemctl stop firewalld.service #关闭防火墙
2.setenforce 0 #临时禁用selinux,selinux是安全子系统
3. Install the dhcp service and find the configuration file
yum -y install dhcp # 安装
rpm -qc dhcp 查看配置文件
4. Edit the configuration file
5.systemctl start dhcpd to start the dhcpd service
5. Assign address to virtual machine B
In virtual machine B, win+r to bring up the running window, enter cmd to enter the command line mode
and reacquire the ip address -----ifconfig/new
to check the network connection of virtual machine B
4. Realize time synchronization in the virtual intranet environment
Synchronize one host with the external network, and other hosts in the internal network environment only need to synchronize the host to achieve time synchronization
1. Use virtual machine A as a time synchronization server to synchronize with the Alibaba Cloud server
yum -y install chrony 安装
rpm -qc chrony 寻找chrony软件的配置文件
systemctl start chrod 启动chrony服务
systemctl status chrond 查看服务状态
2. Edit the configuration file
3. Check whether the time synchronization of virtual machine A takes effect