DHCP 架設設定 - c8

  1. 安裝 dhcp 套件
    [root@msi ~]# dnf install dhcp-server
    
  2. /etc/dhcp/dhcpd.conf 設定如下:。
    [root@msi ~]# vim /etc/dhcp/dhcpd.conf
    [root@msi ~]# cat /etc/dhcp/dhcpd.conf
    #
    # DHCP Server Configuration file.
    #   see /usr/share/doc/dhcp-server/dhcpd.conf.example
    #   see dhcpd.conf(5) man page
    #
    ddns-update-style none;
    option space PXE;
    
    subnet 192.168.1.0 netmask 255.255.255.0 {
    
    class "PXE" {
    	match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
    		option vendor-encapsulated-options 01:04:00:00:00:00:ff;
    		option boot-size 0x11;
    		filename "pxelinux.0";
    #		option tftp-server-name "deyu.wang";
    		option vendor-class-identifier "PXEClient";
    		vendor-option-space PXE;
    	}
    
    
    #	   The following lines are standard all of the time.
    		option routers 192.168.1.254;
    		option subnet-mask 255.255.255.0;
    		option domain-name "deyu.wang";
    		option domain-name-servers 192.168.1.254,8.8.8.8,168.95.1.1,139.175.10.20;
    		default-lease-time 21600;
    		max-lease-time 43200;
    
    		# Assign IPs 101-100 to PXE clients
    		pool {
    			allow members of "PXE";
    			default-lease-time 12;
    			max-lease-time 18;
    			range 192.168.1.250 192.168.1.253;
    		}
    		pool {
    			deny members of "PXE";
    			range 192.168.1.100 192.168.1.199;
    		}
    #   The following lines are examples of kickstart directives.
    	next-server 192.168.1.254;
    }
    
  3. dhcp 的網卡,依照 /etc/sysconfig/dhcpd 有服務啟動的範例設定。
    [root@msi ~]# grep example -A5 /etc/sysconfig/dhcpd
    # example:
    # $ cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
    # $ vi /etc/systemd/system/dhcpd.service
    # $ ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid <your_interface_name(s)>
    # $ systemctl --system daemon-reload
    # $ systemctl restart dhcpd.service
    
  4. 依範例實作,dhcp.service 中的網卡還是用變數 DHCPDARGS,並在 /etc/sysconfig/dhcpd 中設定此變數。
    [root@msi ~]# cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
    [root@msi ~]# grep Exec /etc/systemd/system/dhcpd.service
    ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid $DHCPDARGS
    [root@msi ~]# tail -1 /etc/sysconfig/dhcpd
    DHCPDARGS=wlo1
    
  5. 啟動服務
    [root@msi ~]# systemctl --system daemon-reload
    [root@msi ~]# systemctl restart dhcpd.service
    
  6. 查看服務狀態 active
    [root@msi ~]# systemctl status dhcpd.service
    ● dhcpd.service - DHCPv4 Server Daemon
       Loaded: loaded (/etc/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-07-15 07:11:44 CST; 1min 1s ago
         Docs: man:dhcpd(8)
               man:dhcpd.conf(5)
     Main PID: 4587 (dhcpd)
       Status: "Dispatching packets..."
        Tasks: 1 (limit: 48313)
       Memory: 4.9M
       CGroup: /system.slice/dhcpd.service
               └─4587 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid wlo1