I. Basic knowledge:
1.DHCP简介:DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。2.DHCP服务器简介:DHCP服务器指的是由服务器控制一段IP地址范围,客户端登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。
Two. Configuration of the DHCP server:
Today we're going to do a DHCP server:
I use the virtual machine server as a DHCP server to test with Destop
For convenience, rename the server hostname to dhcp.server.com and rename the desktop host name to Dhcp.test.com
Down, we are configured on the dhcp.server.com host:
1. View the IP of the server
2. Review the DHCP service's dependency package:
3. Install the DHCP service:
4. Configure:
(1) Turn on DHCP service
start dhcpd
(2) Changing the configuration file
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
Vim/etc/dhcp/dhcpd.conf
Change the following sections:
7Option Domain-name"Server.com";# #域名: See/etc/resolv.conf8Option Domain-name-servers172.25.10.254;# #指定dns服务器, multiple sets are separated by commas.Subnet172.25.10.0 netmask 255.255.255.0 { # #指定子网络及子网掩码 31 range 172.25< Span class= "Hljs-number" >.10.10 172.25 .10.20; # #指定IP范围 32 option routers Span class= "Hljs-number" >172.25.10.254; # #指定默认网关 33} 34 #### Delete 27, 28 rows, 34 rows and later
Here are the configurations that are made on dns.test.com:
(1) Network parameter settings:
Edit/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0BOOTPROTO=dhcp###关键部位为dhcpONBOOT=yes
(2) Restart the network:
systemctl restart network###在本次试验,我遇到了如下问题:执行该命令报错,无法通过DHCP服务器获得ip,解决思路为:DHCP通常是用于局域网内的一个通信协议,它主要通过客户端发送广播数据包给整个物理网段内的所有主机,若局域网内有DHCP服务器时,才会响应客户端的ip参数要求。所以DHCP服务器与客户端应该在同一个物理网段内。整个DHCP数据包在服务器与客户端间的交互情况如(1):###所以我猜测是防火墙阻止了数据包的传送###我采取的解决方法是:两台虚拟机均执行命令:firewall-cmd --permanent --add-service=dhcpfirewall-cmd --reload 查看dhcp是否通行:firewall-cmd --list-all重启虚拟机后问题解决。
(Figure (1) The interaction of the DHCP packet between the server and the client)
The test machine obtains the IP from the DHCP server:
(3) After the entire network is restarted, the following files may be modified if the results of the execution are found for the correct DHCP host.
#1.查看/etc/resolv.conf
#2.查看路由
#3.查看服务器记录的DHCP信息cat /var/lib/dhcpd/dhcpd.leases
Three. Example of a configuration
[Email protected] ~]# cat/etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# See/usr/share/doc/dhcp*/dhcpd.conf.example
# See dhcpd.conf (5) Mans page
#
# The Ddns-updates-style parameter controls whether or not the server would
# attempt to does a DNS update when a lease is confirmed. We default to the
# Behavior of the version 2 packages (' None ', since DHCP v2 didn ' t
# has support for DDNS.)
Ddns-update-style none;
Option Domain-name-servers 192.168.19.254;
Default-lease-time 600;
Max-lease-time 7200;
# IF This DHCP server is the official DHCP server for the local
# Network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send DHCP log messages to a different log file (you also
# has to hack syslog.conf to complete the redirection).
Log-facility Local7;
# No Service would be given on this subnet, but declaring it helps the
# DHCP Server to understand the network topology.
Subnet 192.168.18.0 netmask 255.255.254.0 {
Range 192.168.18.20 192.168.19.200;
Option routers 192.168.19.254;
Option Domain-name-servers 192.168.19.254;
}
Linux Common Server--DHCP server build-up