DHCP服务器的配置

一、准备两台虚拟机来进行实验

    一台vm1 ip:172.25.5.11

    一台vm2 ip:配置为dhcp

    使用vm1来配置dhcp服务器,用vm2来测试

二、下载dhcp服务器

    yum install -y dhcp

三、配置dhcp服务器

    1)打开dhcp的配置文件

        DHCP服务器的配置_第1张图片

        此图片中说要看/usr/share/doc/dhcp*/dhcpd.conf.example该文件,此为dhcp的配置文件

    2)拷贝该文件到dhcp的配置文件

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

    3)配置我们所需要的dhcp服务器

            我们需要配置的地方:

                option domain-name                                                            ##设置名称

                option domain-name-servers                                               ##设置ip为提供dns服务的ip

                subnet 10.152.187.0 netmask 255.255.255.0 {                ##删除这两行
}

                subnet 10.254.239.0 netmask 255.255.255.224 {            ##保留这三行,并删除之后的所有行
  range 10.254.239.10 10.254.239.20;                                               ##第一行为dhcp所在的网段和子网掩码

  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; ##第二行为dhcp分配ip的范围

}                                                                                                                ##第三行为网关

四、开启服务

        systemctl start dhcpd

        如果出现如下情况则应该是配置文件中有错误

        [root@vm1 ~]# systemctl start dhcpd
      Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and         "journalctl -xe" for details.

五、测试

        设置vm2的ip地址为dhcp自动获取

        vim /etc/sysconfig/network-scripts/ifcfg-eth0        ##可能设置ip会用到

        设置完成后重启网络

        systemctl restart network

        查看ip是否是dhcp设置的范围中

        ip addr / ifconfig

六、附我实验时配置文件的内容

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

# option definitions common to all supported networks...
option domain-name "wwb.org";
option domain-name-servers 172.25.5.11;

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.5.0 netmask 255.255.255.0 {
  range 172.25.5.100 172.25.5.110;
  option routers 172.25.5.11;
}


你可能感兴趣的:(运维学习)