Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

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

by | May 11, 2021

Let us discuss Dnsmasq DHCP Server in Proxmox.

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

As part of our Server Management Services, we assist our customers with several DHCP queries.

Today, let us see 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.

Step 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

In addition, w need dnsutils package which provides the dig command:

$ sudo apt install dnsutils -y

Eventually, we test and ensure the installation:

$ dig bobcares.com @localhost
nslookup bobcares.com localhost

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

Step 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

Step 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]

 

Common error

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 Support Techs 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 the solution? We’d be happy to assist]

 

Conclusion

In short, we saw effective methods to install, configure and resolve matters relating to Dnsmasq DHCP Server in Proxmox.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF