1. 安装相关依赖

  1. sudo yum install dhcp-server dnsmasq

2. dhcp 相关配置

  1. 配置静态 IP 和 网关

https://www.yuque.com/marchawake/elgunl/gxg5r7

  1. /etc/dhcp/dhcpd.conf 相关配置 ```bash

    DHCP Server Configuration file.

    see /usr/share/doc/dhcp-server/dhcpd.conf.example

    see dhcpd.conf(5) man page

subnet 192.168.138.0 netmask 255.255.255.0 {

路由分配地址范围

range 192.168.138.100 192.168.138.250;

域名服务

option domain-name-servers 192.168.138.1, 223.5.5.5; option domain-name “rubbish.internal.com”; option routers 192.168.138.1; option broadcast-address 192.168.138.255; default-lease-time 600; max-lease-time 7200; }

  1. 3. 配置 dhcp 服务
  2. ```bash
  3. # 拷贝服务文件
  4. cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/dhcpd.service
  5. # 修改服务内容
  6. [Unit]
  7. Description=DHCPv4 Server Daemon
  8. Documentation=man:dhcpd(8) man:dhcpd.conf(5)
  9. Wants=network-online.target
  10. After=network-online.target
  11. After=time-sync.target
  12. [Service]
  13. Type=notify
  14. EnvironmentFile=-/etc/sysconfig/dhcpd
  15. # 指定dhcp服务调用的网卡设备
  16. ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid eth1
  17. StandardError=null
  18. SuccessExitStatus=143
  19. TimeoutSec=10
  20. Restart=on-failure
  21. RestartSec=5
  22. [Install]
  23. WantedBy=multi-user.target