[Dnsmasq-discuss] Finding actual DNS server used

Albert ARIBAUD albert.aribaud at free.fr
Sun Jan 15 21:44:55 GMT 2017


Hi Chris,

Le Sun, 15 Jan 2017 20:31:28 +0000
Chris Green <cl at isbd.net> a écrit:

> On Sun, Jan 15, 2017 at 04:54:11PM +0100, Albert ARIBAUD wrote:
> > Bonjour,
> > 
> > Le Sun, 15 Jan 2017 12:36:47 +0000
> > Chris Green <cl at isbd.net> a écrit:
> >   
> > > On Sun, Jan 15, 2017 at 12:14:42PM +0100, Albert ARIBAUD wrote:  
> > > > > > - read the configuration file(s) dnsmasq uses and find
> > > > > > "server=" lines in it, and read the /etc/resolv* tree, if
> > > > > > dnsmasq uses them, and that will give the list of servers
> > > > > > dnmasq uses at any point in time.
> > > > > >       
> > > > > There aren't any! These are systems where dnsmasq is run by
> > > > > Network Manager rather than directly, thus there is no spcific
> > > > > dnsmasq configuration file.    
> > > > 
> > > > ... and then the configuration is known from the dnsmasq process
> > > > command line. So let me amend my statement above: "... read the
> > > > configuration options, from the dnsmasq process command line if
> > > > it contains any, and from the configuration file or files if
> > > > applicable".   
> > >     chris at t430$ ps -ef | grep dnsmasq
> > >     nobody    1579  1031  0 Jan14 ?
> > > 00:00:01 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground
> > > --no-hosts --bind-interfaces
> > > --pid-file=/var/run/NetworkManager/dnsmasq.pid
> > > --listen-address=127.0.1.1 --cache-size=0 --conf-file=/dev/null
> > > --proxy-dnssec
> > > --enable-dbus=org.freedesktop.NetworkManager.dnsmasq
> > > --conf-dir=/etc/NetworkManager/dnsmasq.d chris at t430$ 
> > > 
> > > 
> > > ... and there's nothing in /etc/NetworkManager/dnsmasq.d  
> > 
> > Then Network Manager sets the DNS via DBus, as the configuration
> > (on command line) allows it. You can most probably find which DNS
> > servers are set by spying on DBus, using dbus-monitor. You can even
> > set up a bash script which shows a list of them in real time.
> >   
> Is there any description anywhere of how to do this?

A ready-made solution with zero effort? Non, there is none.

A solution with some effort? In my case, 10 minutes of searching how to
filter dbus-monitor by interface, starting with near-zero knowledge of
DBus, and strictly zero knowledge of dbus-monitor, and ending up with
the following proof-of-concept running on my machine:

1. Run this command in a shell:

	sudo dbus-monitor --system \
	"interface=org.freedesktop.NetworkManager.dnsmasq"

	(your interface may not be the same. Run

		dbus-send --system --dest=org.freedesktop.DBus
		--type=method_call --print-reply /org/freedesktop/DBus
		org.freedesktop.DBus.ListNames | grep dnsmasq

	and you'll know the interface to use.

2. Force a connection renewal through Network Manager (or by unplugging
   and replugging the client's RJ45 if that's how it gets network
   access).

3. See the dbus-monitor running in the shell display dumps of the
   SetServersEx method calls, complete with server IPs as arguments.

If you want to automate that, you'll need to do some parsing. Or maybe
use Python, which provides a dbus module; this should make extracting
the method arguments easier.

Amicalement,
-- 
Albert.



More information about the Dnsmasq-discuss mailing list