DNSmasq dns caching

Moderator: Forum moderators

Post Reply
williams2
Posts: 1059
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 302 times

DNSmasq dns caching

Post by williams2 »

In the Murga forum, there is a DNSmasq thread in Software, Network.
http://www.murga-linux.com/puppy/viewtopic.php?t=111057

It refers to this webpage:
http://www.techrepublic.com/article/how ... h-dnsmasq/

See the dnsmasq webpage:
http://www.thekelleys.org.uk/dnsmasq/doc.html

Someone asked:
What are the simple step to install Dnsmasq?
I have been running DNSmasq since June 20, for about 2 months.
I have had no trouble with it, it seems to run well.

This is what I did to install and configure in BionicPup64 8.0.

I ran the Puppy Package Manager (from the menu, or from QuickPet or type ppm)
You can update the database by clicking the config icon, top left.

I typed dnsmasq in the search bar and pressed the Enter key.
I clicked on the dnsmasq_2.79-1 package, then clicked DoIt to Auto Install
which installed:
netbase_5.4_all.deb
dnsmasq-base_2.79-1_amd64.deb
dnsmasq_2.79-1_all.deb

This was for BionicPup64, your packages may have different names or version numbers.

If you type dnsmasq in a text terminal, it should run in the background, with no error messages.

To configure dnsmasq, all I had to do was edit the file resolv.conf.head in /etc
and put this line as the first line at the top of the file:

Code: Select all

nameserver 127.0.0.1
Create the file if it does not exist.

Also edit the file resolv.conf and put the line nameserver 127.0.0.1 as the first line of the file.
Or reconnect to the internet, or reboot.

What happens, is an app will try using the first dns nameserver listed in resolv.conf.
Which will be 127.0.0.1
If dnsmasq is not running, 127.0.0.1 won't work and the app will try the next nameserver in resolv.conf
So the internet dns server should work whether or not dnsmasq is running.

If dnsmasq is running, the nameserver 127.0.0.1 line at the top of resolv.conf will cause dnsmasq to be asked for the address. If it is in the cache (the cache is always in ram, not in a file) dnsmasq will return the address almost instantaneously.
If the address is not in the cache, it will look in the /etc/hosts file (which it has copied to ram)
If the address is not in the hosts file, it will try the other nameservers in resolv.conf
(not one after the other, from top to bottom, unless you configure it that way.)
When it finds the address from one of the other nameservers, it keeps it in it's cache in ram

It should work if dsnmasq is running and the first line in resolv.conf is nameserver 127.0.0.1
You can test it like this:

Code: Select all

# nslookup -debug easyos.org
Server:		127.0.0.1
Address:	127.0.0.1:53

Query #0 completed in 123ms:
Non-authoritative answer:
Name:	easyos.org
Address: 216.239.136.174

Query #1 completed in 223ms:
Non-authoritative answer:

# nslookup -debug easyos.org
Server:		127.0.0.1
Address:	127.0.0.1:53

Query #0 completed in 1ms:
Non-authoritative answer:
Name:	easyos.org
Address: 216.239.136.174

Query #1 completed in 1ms:
Non-authoritative answer:
The first time, it takes 223ms.
The second time, it is cached in ram and takes 1ms.

You can see what happens if you kill dnsmasq so that it is not running.
DNS is still working, even if dnsmasq is not running.

Code: Select all

# killall dnsmasq
# nslookup -debug easyos.org
nslookup: write to '127.0.0.1': Connection refused
Server:		1.1.1.1
Address:	1.1.1.1:53

Query #1 completed in 40ms:
Non-authoritative answer:

Query #0 completed in 41ms:
Non-authoritative answer:
Name:	easyos.org
Address: 216.239.136.174
If you have Firefox or Waterfox etc etc configured to use the moziila encrypted DNS server,
that should still work because it bypasses resolv.conf.
Firefox using encrypted DNS is probably not using dnsmasq at all.

To start dsnmasq every time Puppy boots, I put this in /root/Startup/youtube-dl-update

Code: Select all

#!/bin/sh
sleep 10
killall -q dnsmasq
dnsmasq
exit
sleep 50
exec youtube-dl --update
This starts dnsmasq every time Xwindows starts or restarts. And also disables the youtube-dl update every time X starts/restarts, which I always disable.

It would probably work to put the line
dnsmasq
in /etc/rc.d/rc.local
but I have not tried it that way.
Post Reply

Return to “Network”