Creating manageable virtual machines: Configuring DHCP server

III/ CONFIGURING DHCP SERVER

Once you have a successful name server, everything will be easy.

We modify the dhcpd.conf configuration file, deleting unused lines in the new schema:

sudo sed -e '/^on commit/,$d' -e '/authoritative\|netbios/d' \
         -i /etc/dhcp/dhcpd.conf

Next, select Dynamic DNS Update style:

sudo sed '/ddns-update-style/s,none,standard,' -i /etc/dhcp/dhcpd.conf

Modify the domain name:

sudo sed 's,mardom\.,,' -i /etc/dhcp/dhcpd.conf

We now add the DNS key we created earlier when setting up the name server:

sudo tee -a /etc/dhcp/dhcpd.conf << EOF
key dhcp-key {
        algorithm hmac-sha256;
        secret "Tc/p6puZnnIFb4uRV/u7JoH+M1khwdMDj+gdSm4+Who=";
};
EOF

Specify the zones that the DHCP server will require to update. That is the zone “omarine.org” and the reverse zone “0.168.192.in-addr.arpa”:

sudo tee -a /etc/dhcp/dhcpd.conf << EOF

zone OMARINE.ORG. {
        primary 127.0.0.1;
        key dhcp-key;
}

zone 0.168.192.in-addr.arpa. {
        primary 127.0.0.1;
        key dhcp-key;
}
EOF

Normal clients and guest virtual machines are dynamically assigned IP addresses in the range 192.168.0.10 – 192.168.0.62 (see original dhcpd.conf).

Because customers using virtual machines typically prefer static IP addresses instead of dynamic IP addresses, we prepare in advance a group of hosts that are assigned fixed IP addresses:

sudo tee -a /etc/dhcp/dhcpd.conf << EOF

group {
        use-host-decl-names on;
        option time-offset 0;
        option routers 192.168.0.1;

        host guest-2 {
                hardware ethernet 12:34:56:78:9a:02;
                fixed-address 192.168.0.12;
        }
        host guest-3 {
                hardware ethernet 12:34:56:78:9a:03;
                fixed-address 192.168.0.13;
        }
}
EOF

The above MAC addresses are determined by us when creating virtual machines. So called manageable virtual machines.

Since the configuration file contains the secret, we allow only root to read and modify the file:

sudo chmod 600 /etc/dhcp/dhcpd.conf

Enable and start the service:

sudo systemctl enable dhcpd &&
sudo systemctl start dhcpd

Check the status

Bình luận về bài viết này