🖧 Setting up an Isolated DHCP Server on Fedora 40 with KVM


This guide explains how to configure an isolated DHCP server in Fedora 40 to provide IP addresses for a KVM isolated virtual network.

1. Create an Isolated Network in KVM

Open Virtual Machine Manager → Edit → Connection Details → Virtual Networks and create a new network:

  • Name: Testing
  • Device: virbr1
  • Network: 192.168.100.0/24
  • DHCP Range: Disabled (we’ll use our own DHCP server)
  • Forwarding: Isolated network



2. Install DHCP Server

sudo dnf install dhcp-server -y

3. Configure dhcpd.conf

Edit /etc/dhcp/dhcpd.conf and add:

authoritative;
default-lease-time 600;
max-lease-time 7200;

subnet 192.168.100.0 netmask 255.255.255.0 {
    range 192.168.100.100 192.168.100.200;
    option routers 192.168.100.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.100.255;
    option domain-name "isolated.local";
    option domain-name-servers 8.8.8.8, 8.8.4.4;
}

4. Assign Gateway IP to the NIC

Identify your NIC with:

nmcli connection show

Bind the IP to enp7s0 (network interface):

nmcli con mod "Wired connection 2" ipv4.addresses 192.168.100.1/24 ipv4.method manual
nmcli con up "Wired connection 2"

5. Configure DHCP Systemd Service

Copy and edit the service unit (note: enp7s0 is a network interface):

sudo cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
sudo vi /etc/systemd/system/dhcpd.service

Replace content with:

[Unit]
Description=DHCPv4 Server Daemon
Documentation=man:dhcpd(8) man:dhcpd.conf(5)
Wants=network-online.target
After=network-online.target
After=time-sync.target

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/dhcpd
ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid enp7s0
StandardError=null

[Install]
WantedBy=multi-user.target

6. Allow DHCP Through Firewall

sudo firewall-cmd --permanent --add-service=dhcp
sudo firewall-cmd --reload

7. Start and Enable DHCP Server

sudo systemctl --system daemon-reload
sudo systemctl enable --now dhcpd.service
sudo systemctl status dhcpd.service

8. Configure Client Machines

Ensure the client VM network interface is mapped to the same Testing isolated network (virbr1). The DHCP server will assign IPs automatically.

✅ Result

  • virbr1 provides isolated connectivity for KVM guests.
  • The DHCP server on enp7s0 assigns IPs from 192.168.100.100–200.
  • Guests can communicate inside the isolated network with automatic IP assignment.

No comments:

Post a Comment