Linux系统中DHCP服务设置

一.什么是DHCP

动态主机配置协议是一个局域网的网络协议。指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。担任DHCP服务器的计算机需要安装TCP/IP协议,并为其设置静态IP地址、子网掩码、默认网关等内容。

二.实验操作流程

1. 搜索自己使用的计算机中是否有dhcp服务的安装程序

dnf serach dhcp

dnf install dhcp-server.x86_64##找到dhcp服务对应的程序进行安装

 2. 编辑配置文件

cd /etc/dhcp/ ##切换到配置文件的环境

 ll ##查看这个环境下的文件

cat /etc/dhcp/dhcpd.conf  ##查看配置文件内容,发现里面没有内容但发现有一个模板/usr/share/doc/dhcp-server/dhcpd.conf.example

cp  /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf ##复制模板到/etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf ##编辑配置文件

配置文件的内容:

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

# option definitions common to all supported networks...
option domain-name "xyf.org"; ##设置域名
option domain-name-servers 114.114.114.114;##设置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.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

subnet 172.25.254.0 netmask 255.255.255.0  {  ##设置ip网络和子网掩码
  range 172.25.254.37 172.25.254.137 ;##ip池,可以分配ip的范围
  option routers 172.25.254.250 ;##网关设置
}

3.开启dhcp服务

systemctl status dhcp.service ##查看dhcp服务的状态,此时发现是关闭的。

systemctl start dhcpd.service ##开启dhcp服务

 这个时候dhcp服务就已经开启了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值