Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How avahi works?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Tue Apr 04, 2017 5:55 pm    Post subject: How avahi works? Reply with quote

Can't figure out how avahi resolves IP addresses, net search gives lots of documents but none I have found so far covers the process of resolving external IP addresses. Is it using DNS given by DHCP?
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Tue Apr 04, 2017 7:30 pm    Post subject: Re: How avahi works? Reply with quote

Jaglover wrote:
Can't figure out how avahi resolves IP addresses, net search gives lots of documents but none I have found so far covers the process of resolving external IP addresses. Is it using DNS given by DHCP?

Jaglover ... it's using multicastDNS (mDNS) ... you might be better off searching for zeroconf rather than avahi.

HTH & best ... khay
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3134

PostPosted: Tue Apr 04, 2017 8:23 pm    Post subject: Reply with quote

Basically all hosts with avahi subscribe to the same multicast group (predefined - no specific configuration required) and then periodically announce themselves (their names and services provided) to that group setting some arbitrary timeout value (used to be 2 minutes or something close to that), and also announce themselves with timeout of 0 when the host is about to leave that network.
In addition, if you want to resolve a name your local avahi deamon is not familiar with, it will simply send query packet to that multicast group and wait for some host claiming that identity to reply.

Fun fact: on Linux you can open multiple sockets on a single UDP port. All open sockets can send data with the same local port number. Unicast traffic will be delivered to the most recently opened socket. Multicast traffic will be delivered to all sockets subscribed to the multicast group (so multiple applications can receive the same multicast packet).
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Tue Apr 04, 2017 8:42 pm    Post subject: Reply with quote

Thanks for replies. :)

Still in dark what happens when, say, a web browser wants www.google.com resolved. It queries avahi, how avahi gets the public address of google? Will it pass the query to another DNS resolver or will it query root servers? If first, where can avahi be configured to use a specific DNS?
I'm asking this because I have a Mint machine here and dig command clearly uses 127.0.1.1 by default which is avahi. 8O
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3134

PostPosted: Tue Apr 04, 2017 8:58 pm    Post subject: Reply with quote

Avahi will not resolve google's IP.
However, when you configure your box to use avahi for IP resolution, you typically end up with this line in /etc/nsswitch.conf
Code:
hosts:       files mdns dns

So, it will check /etc/hosts first ("files" is the first option listed), then query multicast dns with avahi, and then go for regular dns service.
Of course, as soon as you get a reply, the query is dropped. In the above example, neither dns nor mdns will be referred if you can resolve the name with local configs.
You may consider swapping dns and mdns around to prevent malicious neighbour from impersonating a global service. The downside is, you will always query DNS on every call to your neighbour in that case. Not a big deal with a DNS server running on your router, but it might impact LAN's performance if the DNS is slow.

By the way, dnsmasq also points your resolver to 127.0.0.1 by default.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Tue Apr 04, 2017 9:19 pm    Post subject: Reply with quote

127.0.0.1 is not the same as 127.0.1.1.
Anyhow, it is querying dns. Where is it configured? Where can I tell avahi to use particular DNS? I went thru avahi configuration files in /etc/avahi and found nothing.

What a devilish piece of software, no proper documentation, even no man page. How can one troubleshoot it without knowing how it is configured?
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Apr 04, 2017 11:12 pm    Post subject: Reply with quote

Jaglover wrote:
Where is it configured? Where can I tell avahi to use particular DNS? I went thru avahi configuration files in /etc/avahi and found nothing.

This question doesn't make any sense. Avahi does not send any traffic to port 53. The "DNS servers" avahi queries are your other computers/devices running avahi or zeroconf; if you want it to only see a subset of them, you need to do that at layer 2.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Tue Apr 04, 2017 11:26 pm    Post subject: Reply with quote

I agree I do not understand how it works. But all DNS queries are sent to avahi in this Mint machine.
Code:

dig www.google.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3460
;; flags: qr rd ra; QUERY: 1, ANSWER: 16, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.google.com.                        IN      A

;; ANSWER SECTION:
www.google.com.         300     IN      A       206.124.214.35
www.google.com.         300     IN      A       206.124.214.31
www.google.com.         300     IN      A       206.124.214.20
www.google.com.         300     IN      A       206.124.214.53
www.google.com.         300     IN      A       206.124.214.37
www.google.com.         300     IN      A       206.124.214.27
www.google.com.         300     IN      A       206.124.214.57
www.google.com.         300     IN      A       206.124.214.46
www.google.com.         300     IN      A       206.124.214.24
www.google.com.         300     IN      A       206.124.214.16
www.google.com.         300     IN      A       206.124.214.42
www.google.com.         300     IN      A       206.124.214.48
www.google.com.         300     IN      A       206.124.214.38
www.google.com.         300     IN      A       206.124.214.26
www.google.com.         300     IN      A       206.124.214.49
www.google.com.         300     IN      A       206.124.214.59

;; Query time: 65 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Tue Apr 04 18:26:00 CDT 2017
;; MSG SIZE  rcvd: 288

See, it comes from 127.0.1.1, which is avahi.

Makes me think avahi is a middleman between application and real DNS resolver.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Apr 04, 2017 11:47 pm    Post subject: Reply with quote

That's port 53. Are you running avahi on port 53? Post the output of ss -nlp 'sport = 53'
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Wed Apr 05, 2017 12:09 am    Post subject: Reply with quote

Code:
ss -nlp 'sport = 53'
Netid  State      Recv-Q Send-Q       Local Address:Port                      Peer Address:Port             
udp    UNCONN     0      0                127.0.1.1:53                                   *:*                   users:(("dnsmasq",pid=893,fd=4))
tcp    LISTEN     0      5                127.0.1.1:53                                   *:*                   users:(("dnsmasq",pid=893,fd=5))

I'm not running anything, this is Linux Mint, unmodified.
Code:
 cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1

_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21624

PostPosted: Wed Apr 05, 2017 1:12 am    Post subject: Reply with quote

That ss output says your queries are going to dnsmasq, not avahi. dnsmasq can act as a forwarding resolver for domains it does not resolve locally, so you are correct that a middleman is involved, just not about which program acted as the middleman. You need to look at the dnsmasq configuration to find how it is resolving names.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Wed Apr 05, 2017 1:48 am    Post subject: Reply with quote

OK, thanks. :) They really complicate things in Ubuntu. Where did I read this is avahi listening on 127.0.1.1 ... ? I think it was some Poettering article about avahi superior name resolving.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum