×


Dnsmasq DHCP Server in Proxmox – How to use for VMs IP ?

The DHCP server in Dnsmasq integrates with the DNS server seamlessly.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related DHCP queries.

In this context, we shall look into how to use Dnsmasq DHCP Server in Proxmox for VMs IP.


Dnsmasq DHCP Server in Proxmox

The machines with IP addresses allocated by the DHCP server appear in the DNS with names configured either in each host or in a central configuration file.

Dnsmasq supports dynamic and static DHCP leases.

We can use Dnsmasq in the Proxmox virtualization platform to assign IP addresses dynamically or statically and also to manage DNS.


1. Install dnsmasq on Proxmox VE 6.x

We install dnsmasq from the default upstream repositories:

$ sudo apt update
$ sudo apt install dnsmasq

Then we proceed to install dnsmasq on Proxmox VE 6.x:

Reading state information… Done

The following additional packages will be installed:

dns-root-data dnsmasq-base

Suggested packages:

resolvconf

The following NEW packages will be installed:

dns-root-data dnsmasq dnsmasq-base
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 463 kB of archives.
After this operation, 1,027 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
$ sudo apt install dnsutils -y

Eventually, we test and ensure the installation:

$ dig ibmimedia.com @localhost
nslookup ibmimedia.com localhost

The DNS function in Dnsmasq forwards all requests to the system's default DNS settings in /etc/resolv.conf file.


2. Configure DHCP Server using Dnsmasq

Next, we proceed to configure the DHCP service:

$ sudo vim /etc/dnsmasq.conf

We set the domain for dnsmasq:

domain=example.com

Then we let dnsmasq know the ethernet interface it will use to listen for DHCP requests:

#Around line 106
interface=vmbr1
# Or which to listen on by address (remember to include 127.0.0.1 if you use this.)
#listen-address=

We set DHCP server range of IP addresses to hand out:

#around line 159
dhcp-range=192.168.50.50,192.168.50.200,12h

Also, we set the default route supplied by dnsmasq:

#around line 337
dhcp-option=vmbr1,3,192.168.50.1
#dhcp-option=eth0,3,192.168.50.1

We can provide upstream DNS servers via:

#line 66
# You can use Google’s open DNS servers
server=8.8.8.8
server=8.8.4.4

Set path to a file for the DHCP lease database:

dhcp-leasefile=/var/lib/misc/dnsmasq.leases

Later, we test the configurations:

$ sudo dnsmasq –test
dnsmasq: syntax check OK.

Finally, we restart dnsmasq service:

$ sudo systemctl restart dnsmasq
$ sudo systemctl enable dnsmasq


3. Create a VM on the network with DHCP service

To create a new VM, under Nodes, we right-click on the node name and click on Create VM.

We can name it and choose the node where it will run.

Then we select the OS installation disc. 

The options we have are as below:

Use CD/DVD disc image file (iso).
Use physical CD/DVD Drive.
Do not use any media.

We ensure to pick a network, same as the one we use in dnsmasq DHCP configurations.

Install the OS and then reboot and check the IP address from DHCP.

If the interface does not get an IP address assigned by the DHCP server automatically, we can do a manual request:

$ sudo dhclient interface


[Need help with the procedures? We are here for you. ]


How to resolve Common error encountered while installing dnsmasq ?

While installing dnsmasq, we may come across the following error:

dnsmasq: failed to create listening socket for port 53: Address already in use

If some other service uses port 53, it can cause this error.

So, we check what is listening on port 53 (domain) with:

$ sudo ss -lp “sport = :domain”

In order to solve this, our we suggests a few methods.

1. Initially, we disable any service that is running on port 53.

Or we can mask it, so it does not auto-start on reboot.

$ sudo systemctl disable systemd-resolved
$ sudo systemctl mask systemd-resolved

Also, we ensure that we stop the systemd-resolved service:

$ sudo systemctl stop systemd-resolved

If in case we want to undo what we did, we run:

$ sudo systemctl unmask systemd-resolved
$ sudo systemctl enable systemd-resolved

We can use defaults instead of Disable to undo the command.

Sometimes, dnsmasq-base will listen on port 53 preventing dnsmasq to start.

To use it, we need to use another config directory: the one placed in the Network Manager folder:

/etc/NetworkManager/dnsmasq.d/

Or we can change what port dnsmasq listens on:

$ sudo nano /etc/dnsmasq.conf

Search for listen-address=.

Uncomment the line and add 127.0.0.1 with a different port than 53 like:

listen-address=127.0.0.1#5300


2. Edit /etc/NetworkManager/NetworkManager.conf file with any text editor.

Comment the line dns=dnsmasq.

Then we restart the network manager:

$ sudo service network-manager restart

However, in dnsmasq configuration, we have to listen to the localhost DNS queries with the line listen-address=127.0.0.1.

If we change the configuration of dnsmasq, we make sure to run:

$ sudo /etc/init.d/dnsmasq restart


3. In case we don't want to mess the resolver, we do it with rc.local.

We stop dnsmasq from auto-starting via:

$ servicectl disable dnsmasq

Create file /etc/rc.local or /etc/rc.d/rc.local depending on distro.

Then we set permissions:

$ chmod +x /etc/rc.local

Finally, edit the file:

#!/bin/bash
service systemd-resolved stop
service dnsmasq start


[Need help with fixing DHCP errors? We'd be happy to assist. ]


Conclusion

This article covers methods to install, configure and resolve matters relating to Dnsmasq DHCP Server in Proxmox. When creating the VM we just need to specify the MAC address for specific IP and than just use DHCP to get the assigned IP.


To Install the DHCP server, run the command:

$ apt install isc-dhcp-server