实验目的
1、熟悉DHCP协议、掌握DHCP工作过程
2、掌握DHCP的安装和配置
3、掌握DHCP服务的测试方法
4、掌握selinux的配置
1、DHCP服务器的简单配置
测试用了两台电脑,都是CentOS7系统,连接 vnet2 虚拟网络。
选择其中的一台主机作为DHCP服务机,另一台作为测试机子。
需要达到的目的:
DHCP主机的IP为: 192.168.10.10/24
DHCP动态分配的IP范围为: 192.168.10.100/24 – 192.168.10.200/24
DHCP客户端的网关设置为: 192.168.10.1
DNS 192.168.10.10 , 221.7.136.68
2、安装DHCP
方法一: 先挂载
(mkdir /mnt/cdrom
mount -t auto /dev/cdrom /mnt/cdrom
cd Packages
ls
rpm…)
rpm 包 ( dhcp-4.2.5-68.el7.centos.x86_64.rpm )
rpm –ivh dhcp-4.2.5-68.el7.centos.x86_64.rpm
建议使用此方法,安装DHCP
方法二: yum –y install dhcp
3、DHCP 服务器软件配置 ( /etc/dhcp/dhcpd.conf )
3.1、首先对/etc/dhcp/dhcpd.conf 进行备份
cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.confbak
3.2、编辑 vi /etc/dhcp/dhcpd.conf
DHCP Server Configuration file.
see /usr/share/doc/dhcp*/dhcpd.conf.example
see dhcpd.conf(5) man page
1. 整体的环境设定
#不要更新 DDNS 的设定
ddns-update-style none;
#忽略客户端的 DNS更新功能
ignore client-updates;
预设租期为 3 天
default-lease-time 259200;
最大租期为 6 天
max-lease-time 518400;
动态分配的 IP
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200 ;
# DHCP客户端的默认的转发地址
option routers 192.168.10.1 ;
# DHCP客户端的子网掩码
option subnet-mask 255.255.255.0 ;
域名服务器地址,
option domain-name-servers 192.168.10.10,221.7.136.68;
}
4、关闭防火墙 selinux ( /etc/selinux/config ),并重启 reboot
4.1、首先对/etc/selinux/config 进行备份
cp /etc/selinux/config /etc/selinux/config.bak
4.2、编辑 /etc/selinux/config
This file controls the state of SELinux on the system.
SELINUX= can take one of these three values:
enforcing - SELinux security policy is enforced.
permissive - SELinux prints warnings instead of enforcing.
disabled - No SELinux policy is loaded.
SELINUX=enforcing
关闭selinux的强制模式
SELINUXTYPE= can take one of three two values:
targeted - Targeted processes are protected,
minimum - Modification of targeted policy. Only selected processes are protected.
mls - Multi Level Security protection.
SELINUXTYPE=targeted
selinux=disabled
在末尾添加一行 ,禁止selinux
5、给dhcp主机设定IP地址
ip addr add 192.168.10.10/24 dev ens33
ifconfig ; ip addr show
6、开启DHCP服务,并测试
开启dhcp服务,如果没有报错,则说明配置正确
[root@localhost ~]# systemctl start dhcpd.service
查看服务状态
[root@localhost ~]# systemctl status dhcpd.service
7、dhcp客户端配置与测试
只要配置客户端ip为自动获取即可
同时保证,两台centos 7 虚拟机 连接虚拟网络 vnet2 即可
Ifconfig ; ip addr show