Install isc-dhcp-server
apt install isc-dhcp-server
Use the ens38 network card as the service interface of the dhcp server, first configure an IP address 192.168.1.1
Modify /etc/dhcp/dhcpd.conf to configure the subnet
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 114.114.114.114, 8.8.8.8;
option domain-name "isc.org";
}
Modify interface variables in /etc/default/isc-dhcp-server
INTERFACESv4="ens38"
Start isc-dhcp-server at this time
systemctl restart isc-dhcp-server
I failed to start this, because the startup command of /lib/systemd/system/isc-dhcp-server.service has an error, and the modification is as follows
[Unit]
Description=ISC DHCP IPv4 server
Documentation=man:dhcpd(8)
Wants=network-online.target
After=network-online.target
After=time-sync.target
ConditionPathExists=/etc/default/isc-dhcp-server
ConditionPathExists=|/etc/ltsp/dhcpd.conf
ConditionPathExists=|/etc/dhcp/dhcpd.conf
[Service]
EnvironmentFile=/etc/default/isc-dhcp-server
RuntimeDirectory=dhcp-server
# The leases files need to be root:dhcpd even when dropping privileges
ExecStart=/bin/sh -ec '\
CONFIG_FILE=/etc/dhcp/dhcpd.conf; \
rm /var/lib/dhcp/dhcpd.leases && touch /var/lib/dhcp/dhcpd.leases; \
chown root:dhcpd /var/lib/dhcp /var/lib/dhcp/dhcpd.leases; \
chmod 775 /var/lib/dhcp ; chmod 664 /var/lib/dhcp/dhcpd.leases; \
if test -n "$INTERFACES" -a -z "$INTERFACESv4"; then INTERFACESv4="$INTERFACES"; fi; \
exec dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf $CONFIG_FILE $INTERFACESv4'
[Install]
WantedBy=multi-user.target
After modification, execute systemctl daemon-reload to reload the file, and execute systemctl restart isc-dhcp-server
Get ip address in windows virtual machine