Photo by Koen Swiers

Setting Up Multi-Tenancy and Multi-Subdomain Systems with Dnsmasq

Linux Aug 12, 2023

Multi-tenancy and multi-subdomain systems require a robust DNS management solution. Dnsmasq is a lightweight, easy-to-use DNS forwarder and DHCP server that can be used to manage these types of systems. In this article, we will walk through the process of installing and configuring dnsmasq for and its subdomains.

Step 1: Install Dnsmasq

To begin, you'll need to install dnsmasq on your system. You can do this using your system's package manager. For example, on Ubuntu or Debian-based systems, run:

sudo apt-get install dnsmasq

Step 2: Configure Dnsmasq

Create a new configuration file for dnsmasq:

sudo nano /etc/dnsmasq.d/anuragdeep.conf

Add the following lines to the configuration file:


These lines configure dnsmasq to listen on the loopback interface, specify the domain name as, and set up DNS records for the domain and any subdomains to resolve to, which is the IP address of the local machine.

Restart dnsmasq:

sudo systemctl restart dnsmasq

Step 3: Configure Network Settings

To use dnsmasq for DNS resolution, you need to configure your network settings to use as the DNS server. You can do this by editing the /etc/resolv.conf file:

sudo nano /etc/resolv.conf

Add the following line to the file:


This tells your system to use dnsmasq as the DNS server.

Note: If you are using Ubuntu 20.04 or later, the /etc/resolv.conf file is now a symbolic link to /run/systemd/resolve/stub-resolv.conf. In this case, you should edit the file /etc/systemd/resolved.conf instead:

sudo nano /etc/systemd/resolved.conf

Uncomment the line that starts with DNS= and add as the first DNS server:


Then restart systemd-resolved:

sudo systemctl restart systemd-resolved

This will ensure that your system uses dnsmasq as the DNS server.

Step 4: Test DNS Resolution

You can test if DNS resolution is working by running the following command:

dig @

This should return, which is the IP address that we set up in the dnsmasq configuration file.


You should now be able to use dnsmasq to resolve DNS requests for the domain and any subdomains on your local machine. This will allow you to manage a multi-tenant and multi-subdomain system effectively, providing a robust and easy-to-maintain DNS solution.


Anurag Deep

Logical by Mind, Creative by Heart