Linux的DHCP服务的搭建

1、首先要在服务机配置好yum源
2、用yum安装dhcp软件

yum install dhcp -y

在这里插入图片描述
3、更改dhcp的配置文件

vim /etc/dhcp/dhcpd.conf
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf

首先找出DHCP服务的配置文件路径
在这里插入图片描述
找一个有示例的配置文件
在这里插入图片描述
覆盖,然后修改它
在这里插入图片描述
dhcp文件内容

dhcpd.conf文件的内容:

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "dhcp.com";		##域名
option domain-name-servers 7.7.7.7;		##网络DNS

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# 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
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

# This is a very basic subnet declaration.

subnet 172.25.254.0 netmask 255.255.255.0 {		##IP前三位和掩码
  range 172.25.254.1 172.25.254.253;			##分配的IP从哪里到哪里
  option routers 172.25.254.120;				##默认的网关
}

4、启动dhcpd服务,关掉防火墙

systemctl start dhcpd
systemctl stop firewalld

5、测试

用一台可以ping通服务机的主机,把网络设置为DHCP。查看网络设置,是否和我们服务机的DHCP服务设定的相同。
在这里插入图片描述
将网络改为DHCP模式
在这里插入图片描述
DHCP服务器未开启服务,客户机无法获得IP
在这里插入图片描述
DHCP服务器开启DHCP服务
在这里插入图片描述
客户机获得了IP,可以看到DNS为7.7.7.7
在这里插入图片描述
说明DHCP服务搭建成功

猜你喜欢

转载自blog.csdn.net/qq_43570369/article/details/86571538