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.
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.
Note
Changing DNS addresses while using cellular data and keeping the Meshnet connection active is not possible. If you are using a mobile device with a cellular connection, you will need to use dnsmasq with a VPN connection.
macOS
Linux
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 :53
If 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.
To install dnsmasq, you can use the Homebrew package manager. Install Homebrew by taking these steps:
- 1.Open Terminal.
- 2.Enter the following command:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 3.Follow the on-screen instructions to finish the installation.
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:
- 2.Open Terminal.
- 3.Run the following command:ifconfig
- 4.Locate the interface with your Meshnet IP and note its name. For example,
utun3
.
To start configuring your DNS server, you will need to install dnsmasq on your machine.
- 1.Open Terminal.
- 2.Install dnsmasq by running the following command:brew install dnsmasq
The dnsmasq application will be installed.
Dnsmasq settings are controlled via its configuration file called
dnsmasq.conf
.- 1.Open the
dnsmasq.conf
file using the Nano text editor by running this command in Terminal: For Intel Macs:nano /usr/local/etc/dnsmasq.confnano /opt/homebrew/etc/dnsmasq.conf - 2.Using the Control ⌃ + W keyboard shortcut, locate and uncomment the following lines by removing the hash (#) symbol at the start: •
domain-needed
•bogus-priv
•no-resolv
- 3.Find the
cache-size
line, uncomment it, and change the value to 1000. - 4.Locate the
interface
line, uncomment it, and append the name of the network interface from the Find the Meshnet network interface section after the equals (=) sign. - 5.Find the
#server=/localnet/192.168.0.1
line and replace it with the following two lines:server=1.1.1.1server=8.8.8.8Instead of the1.1.1.1
and8.8.8.8
DNS addresses, you can use your preferred DNS provider for the upstream DNS. - 6.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 dnsmasq
Note
Detailed information about the altered parameters can be found in the Options section of the dnsmasq manual page.
You can enable query logging in the
dnsmasq.conf
file to monitor for any failed DNS resolutions or inconsistencies in website loading.- 1.Open Terminal and run the following command: For Intel Macs:nano /usr/local/etc/dnsmasq.confnano /opt/homebrew/etc/dnsmasq.conf
- 2.Locate the
log-queries
line and uncomment it by removing the hash (#) symbol at the start. - 3.Append a new
log-facility=/usr/local/var/log/dnsmasq.log
line belowlog-queries
. - 4.Press Control + X, Y, and Return to save changes and exit.
- 5.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.To test if dnsmasq was configured properly and is working, do the following:
- 1.Open Terminal.
- 2.Check the status of the dnsmasq service via this command:sudo brew services list
- 3.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.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 :53
Note
The
net-tools
package is required to use the netstat
command.It can be installed by running the following:
sudo apt install net-tools
If port 53 is being used, in the output, you will see the name of the process that is using it.
For example, in the screenshot below, you can see that the
systemd-resolve
is listening on port 53.
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.
Many Linux distributions use systemd-resolve for DNS query resolution. To disable the systemd-resolved service from binding to port 53:
- 1.Open Terminal.
- 2.Open the
resolved.conf
file using the Nano text editor by running this command:sudo nano /etc/systemd/resolved.conf - 3.At the end of the file, append this line:DNSStubListener=no
- 4.Press Ctrl + X, Y, and Enter to save changes and exit.
- 5.Run the following command to restart the systemd-resolved process:sudo systemctl restart systemd-resolved
To start configuring your DNS server, you will need to install dnsmasq on your machine.
- 1.Open Terminal.
- 2.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.
Dnsmasq settings are controlled via its configuration file called
dnsmasq.conf
.- 1.Open the
dnsmasq.conf
file using the Nano text editor by running this command in Terminal:sudo nano /etc/dnsmasq.conf - 2.Using the Ctrl + W keyboard shortcut, locate and uncomment the following lines by removing the hash (#) symbol at the start: •
domain-needed
•bogus-priv
•no-resolv
- 3.Find the
cache-size
line, uncomment it, and change the value to 1000. - 4.Locate the
interface
line, uncomment it, and appendnordlynx
after the equals (=) sign. - 5.Find the
#server=/localnet/192.168.0.1
line and replace it with the following two lines:server=1.1.1.1server=8.8.8.8Instead of the1.1.1.1
and8.8.8.8
DNS addresses, you can use your preferred DNS provider for the upstream DNS. - 6.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 dnsmasq
You can enable query logging in the
dnsmasq.conf
file to monitor for any failed DNS resolutions or inconsistencies in website loading.- 1.Open Terminal and run the following command:sudo nano /etc/dnsmasq.conf
- 2.Locate the
log-queries
line and uncomment it by removing the hash (#) symbol at the start. - 3.Append a new
log-facility=/var/log/dnsmasq.log
line belowlog-queries
. - 4.Press Ctrl + X, Y, and Enter to save changes and exit.
- 5.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.To test if dnsmasq was configured properly and is working, do the following:
- 1.Open Terminal.
- 2.Run the following command to check the syntax in the
dnsmasq.conf
file:dnsmasq --test - 3.Install the
dnsutils
tool by running this command:sudo apt install dnsutils - 4.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.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.
Windows
Android
iOS
macOS
Linux
Android TV
- 1.Right-click Startand select Network connections.
- 2.Choose the network type your device is using (Wi-Fi or Ethernet).
- 3.Find the DNS server assignment option and click Edit.
- 4.Choose Manual from the dropdown menu and enable IPv4.
- 5.Fill in the DNS fields.
- Under Preferred DNS, enter the Meshnet IP of the dnsmasq device.
- Under Alternate DNS, enter the DNS address of another provider.
- 6.Click Save.
- 1.Right-click Startand select Network connections.
- 2.Select Change adapter options.
- 3.Right-click your current network adapter (Wi-Fi or Ethernet) and choose Properties.
- 4.In the new window, select Internet Protocol Version 4 (TCP/IPv4) and click Properties.
- 5.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.
- 6.Click OK twice to apply the changes.
- 1.Open the Settings menu.
- 2.Go to Connections and select Wi-Fi.
- 3.Find your current Wi-Fi network and tap the gear button.
- 4.Go to Advanced/View more.
- 5.Change the IP settings value to Static.
- 6.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.
- 7.Tap Save (if such a button is present).
- 1.Open Settings.
- 2.Tap Wi-Fi, find your current network, and tap the Infobutton.
- 3.Tap Configure DNS and choose Manual.
- 4.Select Add server and enter the Meshnet IP of the dnsmasq device.
- 5.Ensure that the added IP address is at the top.
- 6.Tap Save.
- 1.Go to System settings and click Network.
- 2.Select the network interface you use (Wi-Fi or Ethernet) and click Details.
- 3.Open the DNS tab and click the plus (+) button at the bottom to add the Meshnet IP address of the dnsmasq device.
- 4.Ensure that the added IP address is at the top.
- 5.Click OK to save the changes.
- 1.Go to System preferences and click Network.
- 2.Select the network interface you use (Wi-Fi or Ethernet) and click Advanced.
- 3.Open the DNS tab and add the Meshnet IP address of the dnsmasq device by clicking the plus (+) icon.
- 4.Ensure that the added IP address is at the top.
- 5.Click OK and then click Apply.
- 1.Open Settings, and then select either Network or Wi-Fi based on your network type.
- 2.Click the gear button and go to the IPv4 tab.
- 3.Next to DNS, disable the Automatic toggle.
- 4.In the DNS field, enter the Meshnet IP of the dnsmasq device and the DNS of another provider, separated by a comma.
- 5.Click Apply.
- 6.Open Terminal and run the following command to restart the Network Manager daemon:sudo systemctl restart NetworkManager
- 7.Enter your sudo password.
- 1.Open Terminal and run the following command:sudo nano /etc/systemd/resolved.conf
- 2.Locate the
DNS
andFallbackDNS
lines. - 3.Uncomment the lines by removing the hash (#) symbols.
- 4.Enter the appropriate DNS addresses after the equals (=) sign, as shown:
DNS=<Meshnet IP of the dnsmasq device>
FallbackDNS=<DNS of another provider>
- 5.Press Ctrl + X, Y, and Enter to exit and save the changes.
- 6.Run the following command to ensure that the network changes are applied:sudo systemctl restart systemd-resolved
- 7.Enter your sudo password.
Note
Changes in the
/etc/systemd/resolved.conf
file take priority over settings in the Network Manager. Therefore, if you apply the DNS change directly via the Network Manager settings, ensure that there are no custom configurations in the previously mentioned resolved.conf
file. Otherwise, the specified DNS addresses will not be used.- 1.Open the Android TV Settings menu.
- 2.Select Network & internet.
- 3.Choose your network and change the IP settings value to Static.
- 4.Enter your device's local IP address, network gateway, and network prefix length.
- 5.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.
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:
Windows
Android
iOS
macOS
Linux
Android TV
- 1.Open the NordVPN app.
- 2.Navigate to Meshnetand copy the Meshnet IP address of your dnsmasq device.
- 3.In the lower-left corner, click Settings.
- 4.Select the Connection section.
- 5.Enable the Use custom DNS toggle and click the dropdown arrow.
- 6.In the first field, paste the copied Meshnet IP address.
- 7.On the right, click the Savecheckmark.
Now, when you establish a VPN connection to a NordVPN server, the DNS address that you specified will be used for the connection.
Note
On the Threat protection
page, make sure that the Threat protection lite toggle is disabled. Otherwise, the custom DNS change will be overwritten by the Threat Protection feature.
- 1.Open the NordVPN app.
- 2.Navigate to the Meshnettab and copy the Meshnet IP address of your dnsmasq device.
- 3.In the lower-right corner, tap Profile, and then select Settings.
- 4.Under VPN and security, tap DNS.
- 5.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.
Note
In the Settings menu, make sure that the Threat protection lite toggle is disabled. Otherwise, the custom DNS change will be overwritten by the Threat Protection feature.
- 1.Open the NordVPN app.
- 2.Navigate to Meshnetand copy the Meshnet IP address of your dnsmasq device by tapping it.
- 3.In the lower-right corner, tap Profile.
- 4.In the upper-right corner, select Settings.
- 5.Under VPN connection, tap Protocol.
- 6.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.
Note
In the Profile
menu, make sure that the Threat protection lite toggle is disabled. Otherwise, the custom DNS change will be overwritten by the Threat Protection feature.
Note
- 1.Open the NordVPN app.
- 2.Navigate to Meshnetand copy the Meshnet IP address of your dnsmasq device.
- 3.In the lower-left corner, click Settings.
- 4.On the left, select the DNS section.
- 5.Click Add new DNS.
- 6.In the new entry, paste the copied Meshnet IP address.
- 7.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.
Note
On the Threat protection
tab, make sure that the Use lite version toggle is disabled. Otherwise, the custom DNS change will be overwritten by the Threat Protection feature.
- 1.Open Terminal.
- 2.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.
Note
Make sure that Threat protection lite is disabled. Otherwise, the custom DNS change will be overwritten by NordVPN’s Threat Protection feature.
To disable Threat Protection lite, use the
nordvpn set tplite off
command.- 1.Open the NordVPN app.
- 2.Scroll down to the Settings section and select the Settings card.
- 3.Choose DNS and select Custom.
- 4.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.
Note
In the Settings menu, make sure that the Threat protection lite option is turned off. Otherwise, the custom DNS change will be overwritten by NordVPN’s Threat Protection feature.
Tip
If you're looking for alternate DNS addresses, here are some of the most popular free DNS providers:
- Google — 8.8.8.8 and 8.8.4.4
- Cloudflare — 1.1.1.1 and 1.0.0.1
- AdGuard — 176.103.130.130 and 176.103.130.131
- Quad9 — 9.9.9.9 and 149.112.112.112
- OpenDNS — 208.67.222.222 and 208.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.