Recently, I covered how to install and configure dnsmasq on Linux systems (see "How to speed up DNS caching on Linux machines with dnsmasq"). However, that particular setup doesn't work for the likes of Fedora (both desktop and server editions). So I thought it time to walk through the process of getting the same system setup on Fedora 26. With this in place, you will enjoy faster dns lookups, for faster networking.
So, without further ado, let's get to the setup.
SEE: 20 quick tips to make Linux networking easier (TechRepublic)
The first thing you must do is install the necessary software. To do this, open up a terminal window and issue the command:
sudo dnf install dnsmasq
Once the installation completes, you're almost ready to configure. Before we do that, we must create a new unprivileged user and group that will handle the functions of dnsmasq. Issue the following two commands to take care of that:
sudo groupadd -r dnsmasq sudo useradd -r -g dnsmasq dnsmasq
Now it's time to configure.
This is where things vary significantly to the Ubuntu installation. The first thing you want to do is copy the original configuration file with the command:
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
Next we're going to delete the original configuration file and create a new one with the commands:
sudo rm /etc/dnsmasq.conf sudo touch /etc/dnsmasq.conf
Open that new file in your editor of choice and add the following:
listen-address=127.0.0.1 port=53 bind-interfaces user=dnsmasq group=dnsmasq pid-file=/var/run/dnsmasq.pid domain-needed bogus-priv no-hosts dns-forward-max=150 cache-size=1000 no-negcache neg-ttl=3600 resolv-file=/etc/resolv.dnsmasq no-poll
Save and close that file.
Next we must create a specific dns resolve file that the system will use. Issue the command sudo touch /etc/resolv.dnsmasq and then open that new file with your editor of choice. The setup of this file is exactly like that of /etc/resolve.conf. So if you use the Google DNS nameservers, the contents of the /etc/resolv.dnsmasq will be:
nameserver 220.127.116.11 nameserver 18.104.22.168
Save and close that file.
Finally, in the /etc/resolv.conf file, make sure the only line is:
Testing and starting the setup
Before we start dnsmasq, let's test out configuration with the command:
sudo dnsmasq --test
You should see no errors. That being the case, start up dnsmasq with the command:
sudo systemctl start dnsmasq
Finally, we'll enable dnsmasq at boot with the command:
sudo systemctl enable dnsmasq
Faster DNS means faster networking
Issue a dig command on a domain and you'll see a fairly standard response time. Issue the dig command a second time and you'll see that response time drop to near zero. Congratulations, dnsmasq is working and your networking (to or from your Fedora machine) should now be significantly improved.
- How to configure gzip compression with NGINX (TechRepublic)
- How to speed up page load times with Google's PageSpeed Insights (TechRepublic)
- Linux Essentials Bundle (TechRepublic Academy)
- Need to install Linux bash on Windows? Here's how. (TechRepublic Video)
- Fedora 26 is coming: Here's what you need to know (ZDNet)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.