在Centos中搭建DHCP服务器

Posted by FanHao on 2020-10-10

系统平台

系统为Centos7.7 x86_64,已安装rpm和yum等工具

安装

查询是否已安装软件包,已安装可以跳过此步骤

1
rpm -q dhcp

如果未安装则通过yum安装

1
yum install -y dhcp

也可以搜索安装其他dhcp服务器软件包

1
yum search all dhcp

配置

配置网卡接口为静态ip

1
ifconfig eth1 192.168.11.1

或者编辑网卡配置文件,设置静态ip

1
vi /etc/sysconfig/network-scripts/ifcfg-eth1

配置dhcp服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
vi /etc/dhcp/dhcpd.conf
# 写入如下配置
subnet 192.168.11.0 netmask 255.255.255.0 {
authoritative;
range 192.168.11.10 192.168.11.254;
option routers 192.168.11.1;
option broadcast-address 192.168.11.255;
option domain-name-servers 192.168.11.1;
option domain-name "test.cn";
default-lease-time 60;
max-lease-time 60;
}

# 静态IP绑定
host hostname {
hardware ethernet 00:90:4c:53:30:50;
fixed-address 192.168.11.100;
}

控制

开启dhcp服务

1
systemctl start dhcpd

关闭dhcp服务

1
systemctl stop dhcpd

开机自启动设置

1
2
3
systemctl enable dhcpd
# 禁用自启动
systemctl disable dhcpd