How to set up your own DNS server
Learn how to set up your personal DNS server on Linux and macOS and use it remotely over Meshnet.
Introduction
Once the internet connection is set up in your home, it is usually configured to use the internet service provider’s DNS addresses. Using such DNS can lead to a number of inconveniences: longer website loading times, unwanted URL blocking, and query logging. All of these factors can make the browsing experience feel like a chore. Thankfully, there are various ways to overcome these hindrances, such as configuring a personal DNS server. A tool that allows you to do exactly this is dnsmasq.
By using the free dnsmasq software, your device can function as a DNS forwarder and DHCP server. It has an integrated DNS caching feature. This means that any website that is saved in the cache will open nearly instantly. Such behavior leads to a much smoother and more enjoyable browsing experience. Additionally, you are in control of your DNS records, as you can monitor them directly on your device or disable logging altogether.
The drawback of dnsmasq is that it is designed to work only on the local network. However, with the addition of Meshnet, you can use your dnsmasq configuration no matter how far away from home you are.
In this article, you will find instructions on how to set up a personal DNS server using dnsmasq on macOS and Linux.
Before you begin
Because dnsmasq uses port 53 for its functionality, it is important to ensure that this port is available on your system before configuring dnsmasq. To do so, open Terminal and execute the following command:
sudo lsof -i -n -P | grep :53If port 53 is being used, in the output, you will see the name of the process that is using it.
In case the port is occupied, you will need to free it up by killing the other process which is using port 53 or changing its port to a different one.
Install Homebrew
To install dnsmasq, you can use the Homebrew package manager. Install Homebrew by taking these steps:
Open Terminal.
Enter the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"For additional information about the installation process, refer to Homebrew documentation.
Follow the on-screen instructions to finish the installation.
Find the Meshnet network interface
Communication between devices in Meshnet is done via the Meshnet network interface. The name of the interface can differ for each device. To find the correct name on your device:
Open Terminal.
Run the following command:
ifconfigLocate the interface with your Meshnet IP and note its name. For example,
utun4.

Install dnsmasq
To start configuring your DNS server, you will need to install dnsmasq on your machine.
Open Terminal.
Install dnsmasq by running the following command:
brew install dnsmasq
The dnsmasq application will be installed.
Configure dnsmasq
Dnsmasq settings are controlled via its configuration file called dnsmasq.conf.
Open the
dnsmasq.conffile using the Nano text editor by running this command in Terminal: For Intel Macs:nano /usr/local/etc/dnsmasq.confFor Apple silicon Macs:
nano /opt/homebrew/etc/dnsmasq.confUsing the Control ⌃ + W keyboard shortcut, locate and uncomment the following lines by removing the hash (#) symbol at the start:
domain-neededbogus-priv

no-resolv

Find the
cache-sizeline, uncomment it, and change the value to 1000.

Locate the
interfaceline, uncomment it, and append the name of the network interface from the Find the Meshnet network interface section after the equals (=) sign.

Find the
#server=/localnet/192.168.0.1line and replace it with the following two lines:server=1.1.1.1 server=8.8.8.8

Instead of the
1.1.1.1and8.8.8.8DNS addresses, you can use your preferred DNS provider for the upstream DNS.Press Control ⌃ + X, Y, and Return to save changes and exit.
Start the dnsmasq process as the root user via the following command:
sudo brew services start dnsmasqEnable query logging (optional)
You can enable query logging in the dnsmasq.conf file to monitor for any failed DNS resolutions or inconsistencies in website loading.
Open Terminal and run the following command: For Intel Macs:
nano /usr/local/etc/dnsmasq.confFor Apple silicon Macs:
nano /opt/homebrew/etc/dnsmasq.confLocate the
log-queriesline and uncomment it by removing the hash (#) symbol at the start.Append a new
log-facility=/usr/local/var/log/dnsmasq.logline belowlog-queries.

Press Control + X, Y, and Return to save changes and exit.
Restart the dnsmasq process by running:
sudo brew services restart dnsmasq
All of the DNS queries will now be logged in the /usr/local/var/log/dnsmasq.log file.
Test dnsmasq
To test if dnsmasq was configured properly and is working, do the following:
Open Terminal.
Check the status of the dnsmasq service via this command:
sudo brew services list

Check if the domain name resolution is working properly by using
dig:dig nordvpn.com @localhost

If you receive an answer to the dig command, it indicates that your DNS server is working properly and ready for use.
Before you begin
Because dnsmasq uses port 53 for its functionality, it is important to ensure that this port is available on your system before configuring dnsmasq. To do so, open Terminal and execute the following command:
sudo netstat -tulpn | grep :53If port 53 is being used, in the output, you will see the number and the name of the process that is using it.

In case the port is occupied, you will need to free it up by killing the other process which is using port 53 or changing its port to a different one.
Free up port 53 used by systemd-resolve
Many Linux distributions use systemd-resolve for DNS query resolution. To disable the systemd-resolved service from binding to port 53:
Open Terminal.
Open the
resolved.conffile using the Nano text editor by running this commandsudo nano /etc/systemd/resolved.confAt the end of the file, append this line:
DNSStubListener=no
Press Ctrl + X, Y, and Enter to save changes and exit.
Run the following command to restart the systemd-resolved process:
sudo systemctl restart systemd-resolved
Install dnsmasq
To start configuring your DNS server, you will need to install dnsmasq on your machine.
Open Terminal.
Update all of your repositories and install dnsmasq by running the following command:
sudo apt update && sudo apt install dnsmasq
The dnsmasq application will be installed and started automatically.
Configure dnsmasq
Dnsmasq settings are controlled via its configuration file called dnsmasq.conf.
Open the
dnsmasq.conffile using the Nano text editor by running this command in Terminal:sudo nano /etc/dnsmasq.confUsing the Ctrl + W keyboard shortcut, locate and uncomment the following lines by removing the hash (#) symbol at the start:
domain-neededbogus-priv
no-resolv
Find the
cache-sizeline, uncomment it, and change the value to 1000.
Locate the
interfaceline, uncomment it, and appendnordlynxafter the equals (=) sign.
Find the
#server=/localnet/192.168.0.1line and replace it with the following two lines:server=1.1.1.1 server=8.8.8.8
Instead of the
1.1.1.1and8.8.8.8DNS addresses, you can use your preferred DNS provider for the upstream DNS.Press Ctrl + X, Y, and Enter to save changes and exit.
To ensure that the changes are applied, restart the dnsmasq process via the following command:
sudo systemctl restart dnsmasqEnable query logging (optional)
You can enable query logging in the dnsmasq.conf file to monitor for any failed DNS resolutions or inconsistencies in website loading.
Open Terminal and run the following command:
sudo nano /etc/dnsmasq.confLocate the
log-queriesline and uncomment it by removing the hash (#) symbol at the start.Append a new
log-facility=/var/log/dnsmasq.logline belowlog-queries.
Press Ctrl + X, Y, and Enter to save changes and exit.
Restart the dnsmasq process by running:
sudo systemctl restart dnsmasq
All of the DNS queries will now be logged in the /var/log/dnsmasq.log file.
Test dnsmasq
To test if dnsmasq was configured properly and is working, do the following:
Open Terminal.
Run the following command to check the syntax in the
dnsmasq.conffile:dnsmasq --test
Install the
dnsutilstool by running this command:sudo apt install dnsutilsCheck if the domain name resolution is working properly by using
dig:dig nordvpn.com @localhost
If you receive an answer to the dig command, it indicates that your DNS server is working properly and ready for use.
Use your dnsmasq DNS over Meshnet
With dnsmasq fully set up, you can start using it on your devices. For usage via Meshnet, you must set the server device’s Meshnet IP address as the DNS server on each client device.
Without a VPN connection
Windows 11
Right-click Start
and select Network connections.
Choose the network type your device is using (Wi-Fi or Ethernet).
Find the DNS server assignment option and click Edit.
Choose Manual from the dropdown menu and enable IPv4.
Fill in the DNS fields.
Preferred DNS server: the Meshnet IP of the dnsmasq device
Alternate DNS server: the DNS address of another provider


Click Save
Windows 10
Right-click Start
and select Network connections.
Select Change adapter options.
Right-click your current network adapter (Wi-Fi or Ethernet) and choose Properties.
In the new window, select Internet Protocol Version 4 (TCP/IPv4) and click Properties.
Select Use the following DNS server addresses and fill in the fields underneath.
Preferred DNS server: the Meshnet IP of the dnsmasq device.
Alternate DNS server: the DNS address of another provider.

Click OK twice to apply the changes.
Open the Settings menu.
Go to Network & internet > Internet, find your current Wi-Fi network, and tap the gear button.
In the upper-right corner, select Modify.
Expand the Advanced settings dropdown, and change the IP settings value to Static.
Enter your device's local IP address, network gateway, and network prefix length.
Fill in the required DNS addresses.
Under DNS 1, enter the Meshnet IP of the dnsmasq device.
Under DNS 2, enter the DNS address of another provider.


Tap Save.
Open Settings.
Tap Wi-Fi, find your current network, and tap the Info
button.
Tap Configure DNS and choose Manual.
Select Add server and enter the Meshnet IP of the dnsmasq device.


Ensure that the added IP address is at the top.
Tap Save.
macOS Ventura 13 and newer
Go to System settings and click Network.
Select the network interface you use (Wi-Fi or Ethernet) and click Details.
Open the DNS tab and click the plus (+) button at the bottom to add the Meshnet IP address of the dnsmasq device.
Ensure that the added IP address is at the top.


Click OK to save the changes.
macOS Monterey 12 and older
Go to System preferences and click Network.
Select the network interface you use (Wi-Fi or Ethernet) and click Advanced.
Open the DNS tab and add the Meshnet IP address of the dnsmasq device by clicking the plus (+) icon.
Ensure that the added IP address is at the top.

Click OK and then click Apply.
Method 1: Using Network Manager
Open Settings, and then select either Network or Wi-Fi based on your network type.
Click the gear button and go to the IPv4 tab.
Next to DNS, turn off the Automatic toggle.
In the DNS field, enter the Meshnet IP of the dnsmasq device and the DNS of another provider, separated by a comma.


Click Apply.
Open Terminal and run the following command to restart the Network Manager daemon:
sudo systemctl restart NetworkManagerEnter your sudo password.
Method 2: Using Terminal
Open Terminal and run the following command:
sudo nano /etc/systemd/resolved.confLocate the
DNSandFallbackDNSlines.Uncomment the lines by removing the hash (#) symbols.
Enter the appropriate DNS addresses after the equals (=) sign, as shown:
DNS=<Meshnet IP of the dnsmasq device>FallbackDNS=<DNS of another provider>
Press Ctrl + X, Y, and Enter to exit and save the changes.
Run the following command to ensure that the network changes are applied:
sudo systemctl restart systemd-resolvedEnter your sudo password.
Open the Android TV Settings menu.
Select Network & internet.
Choose your network and change the IP settings value to Static.
Enter your device's local IP address, network gateway, and network prefix length.
Type in the DNS addresses:
In the DNS 1 field, enter the Meshnet IP address of your dnsmasq device.

In the DNS 2 field, enter the DNS address of another provider
With a VPN connection
Meshnet allows you to use your custom, self-hosted DNS server alongside a VPN connection via the NordVPN app. Follow these steps to use your dnsmasq DNS when connected to a VPN server:
Open the NordVPN app.
Navigate to Devices in Meshnet
and copy the Meshnet IP address of your dnsmasq device.
In the lower-left corner, click Settings
.
Select the Connection and security section.
Turn on the Use custom DNS toggle and click the dropdown arrow.
In the first field, paste the copied Meshnet IP address.


Click the Save checkmark.
Now, when you establish a VPN connection to a NordVPN server, the DNS address that you specified will be used for the connection.
Open the NordVPN app.
Navigate to Profile
> Meshnet
> Manage devices and copy the Meshnet IP address of your dnsmasq device.
Go back to the Profile
menu, and then select Settings
.
Under VPN and security, tap DNS.
Select Custom, paste the copied Meshnet IP address, and tap Add.


Now, when you establish a VPN connection to a NordVPN server, the DNS addresses that you specified will be used for the connection.
Open the NordVPN app.
Navigate to Profile
> Meshnet
> Manage devices and copy the Meshnet IP address of your Pi-hole device by tapping it.
Go back to the Profile
menu and select Settings
.
Under VPN connection, tap Protocol.
In the Enter custom DNS address field, paste the copied Meshnet IP address.


Now, when you establish a VPN connection to a NordVPN server, the DNS address that you specified will be used for the connection.
Open the NordVPN app.
Navigate to the Meshnet
tab and copy the Meshnet IP address of your dnsmasq device.
In the lower-left corner, click Settings
and go to Custom DNS.
Click Add new DNS.
In the new entry, paste the copied Meshnet IP address.
Turn on the Enable custom DNS servers toggle.


Now, when you establish a VPN connection to a NordVPN server, the DNS address that you specified will be used for the connection.
Open Terminal.
Run the following command, replacing
<MeshnetIP>with your dnsmasq device's Meshnet IP address:nordvpn set dns <MeshnetIP>Example

Now, when you establish a VPN connection to a NordVPN server, the DNS address that you specified will be used for the connection.
Open the NordVPN app.
Navigate to Settings
> DNS server.
Choose Custom and select Add server.

Enter the Meshnet IP address of your dnsmasq device.

Now, when you establish a VPN connection to a NordVPN server, the DNS address that you specified will be used for the connection.
Tip
If you're looking for alternate DNS addresses, here are some of the most popular free DNS providers:
Google —
8.8.8.8and8.8.4.4Cloudflare —
1.1.1.1and1.0.0.1AdGuard —
94.140.14.14and94.140.15.15Quad9 —
9.9.9.9and149.112.112.112OpenDNS —
208.67.222.222and208.67.220.220
You can also use the same upstream DNS addresses from the dnsmasq.conf file.
With the DNS changes applied, you have finished the setup process. Your personal DNS server can now be used remotely, with the help of Meshnet.
Last updated
Was this helpful?