Avahi-Daemon Service

知更鸟

Avahi是一种免费的零配置网络(zeroconf)实现,包括用于 mDNS/DNS-SDservice 发现的系统。

背景

Avahi是一个使程序能够发布和发现在本地网络上运行的服务和主机的系统。 例如,用户可以将其计算机插入网络,并让Avahi自动发布在计算机上运行的网络服务,从而可以访问文件和打印机。

配置文件

/etc/avahi/avahi-daemon.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

# See avahi-daemon.conf(5) for more information on this configuration
# file!

[server]
#host-name=foo
#domain-name=local
#browse-domains=0pointer.de, zeroconf.org
use-ipv4=yes
#use-ipv6=yes
allow-interfaces=eth0
deny-interfaces=wlan0
check-response-ttl=yes
#use-iff-running=no
#enable-dbus=yes
#disallow-other-stacks=no
#allow-point-to-point=no
#cache-entries-max=4096
#clients-max=4096
#objects-per-client-max=1024
#entries-per-entry-group-max=32
ratelimit-interval-usec=1000000
ratelimit-burst=1000

[wide-area]
enable-wide-area=yes

[publish]
#disable-publishing=no
#disable-user-service-publishing=no
#add-service-cookie=no
#publish-addresses=yes
publish-hinfo=no
publish-workstation=no
#publish-domain=yes
#publish-dns-servers=192.168.50.1, 192.168.50.2
#publish-resolv-conf-dns-servers=yes
#publish-aaaa-on-ipv4=yes
#publish-a-on-ipv6=no

[reflector]
#enable-reflector=no
#reflect-ipv=no

[rlimits]
#rlimit-as=
#rlimit-core=0
#rlimit-data=8388608
#rlimit-fsize=0
#rlimit-nofile=768
#rlimit-stack=8388608
#rlimit-nproc=3

配置主机名称

1
sed -i 's/^#host-name=.*/host-name=pi/' /etc/avahi/avahi-daemon.conf

添加服务广播

将需要广播的服务配置文件在/etc/avahi/services下。

ssh服务

ssh.service

ssh.service
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h ssh</name>
<service protocol="ipv4">
<type>_ssh._tcp</type>
<port>22</port>
<host-name>pi.net</host-name>
</service>
</service-group>

webdav服务

webdav.service
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h webdav</name>
<service protocol="ipv4">
<type>_webdav._tcp</type>
<port>80</port>
<host-name>pi.net</host-name>
</service>
</service-group>

ftp服务

webdav.service
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h ftp</name>
<service protocol="ipv4">
<type>_ftp._tcp</type>
<port>21</port>
<host-name>pi.net</host-name>
</service>
</service-group>

type 类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Devices

_workstation._tcp:Workstation
_workstation._tcp[de]:Arbeitsplatzrechner
_workstation._tcp[it]:Macchine

# Web

_http._tcp:Web Site
_http._tcp[de]:Web-Angebot
_http._tcp[it]:Sito Web

_https._tcp:Secure Web Site
_https._tcp[de]:Sicheres Web-Angebot
_https._tcp[it]:Sito Web sicuro

_rss._tcp:Web Syndication RSS

# Network

_domain._udp:DNS Server
_domain._udp[de]: DNS-Dienst

_ntp._udp:NTP Time Server

_smb._tcp:Microsoft Windows Network
_smb._tcp[it]:Rete Microsoft Windows

_airport._tcp:Apple AirPort

# File and data access

_ftp._tcp:FTP File Transfer
_ftp._tcp[de]:FTP-Dateifreigabe

_tftp._udp:TFTP Trivial File Transfer

_webdav._tcp:WebDAV File Share
_webdav._tcp[it]:WebDAV Condivisione File

_webdavs._tcp:Secure WebDAV File Share
_webdavs._tcp[it]:WebDAV Condivisione File Sicuro

_afpovertcp._tcp:Apple File Sharing

_nfs._tcp:Network File System

_sftp-ssh._tcp:SFTP File Transfer

_apt._tcp:APT Package Repository
_apt._tcp[it]:APT - Repository dei Pacchetti

_odisk._tcp:DVD or CD Sharing

_adisk._tcp:Apple TimeMachine

# Remote machine access

_ssh._tcp:SSH Remote Terminal
_ssh._tcp[de]:SSH-Fernzugriff
_ssh._tcp[it]:SSH Terminale remoto

_rfb._tcp:VNC Remote Access
_rfb._tcp[it]:Controllo remoto VNC

_telnet._tcp:Telnet Remote Terminal
_telnet._tcp[it]:Telnet Terminale Remoto

_timbuktu._tcp:Timbuktu Remote Desktop Control

_net-assistant._udp:Apple Net Assistant

_udisks-ssh._tcp:Remote Disk Management

# Mail

_imap._tcp:IMAP Mail Access
_imap._tcp[it]:Posta - IMAP

_pop3._tcp:POP3 Mail Access
_pop3._tcp[it]:Posta - POP3

# Printing

_printer._tcp:UNIX Printer
_printer._tcp[it]:Stampante UNIX

_pdl-datastream._tcp:PDL Printer
_pdl-datastream._tcp[it]:Stampante PDL

_ipp._tcp:Internet Printer
_ipps._tcp:Secure Internet Printer

# Multimedia

_daap._tcp:iTunes Audio Access
_daap._tcp[de]:iTunes Audio-Zugriff
_daap._tcp[it]:Accesso Audio iTunes

_dacp._tcp:iTunes Remote Control

_realplayfavs._tcp:RealPlayer Shared Favorites
_realplayfavs._tcp[it]:RealPlayer - Preferiti Condivisi

_raop._tcp:AirTunes Remote Audio
_airplay._tcp:AirPlay Remote Video

_rtsp._tcp:RTSP Realtime Streaming Server
_rtp._udp:RTP Realtime Streaming Server

_dpap._tcp:Digital Photo Sharing
_dpap._tcp[it]:Condivisione Foto

_pulse-server._tcp:PulseAudio Sound Server
_pulse-sink._tcp:PulseAudio Sound Sink
_pulse-source._tcp:PulseAudio Sound Source

_mpd._tcp:Music Player Daemon

_remote-jukebox._tcp:Remote Jukebox

# DAAP share provided by iTunes on behalf of an iPod Touch
_touch-able._tcp:iPod Touch Music Library

_vlc-http._tcp:VLC Streaming

# Communication, presence, working together

_presence._tcp:iChat Presence

_sip._udp:SIP Telephony
_sip._udp[de]:SIP-Telefonie
_sip._udp[it]:Telefonia-SIP

_h323._tcp:H.323 Telephony
_h323._tcp[de]:H.323-Telefonie
_h323._tcp[it]:Telefonia-H.323

_presence_olpc._tcp:OLPC Presence

_iax._udp:Asterisk Exchange

_skype._tcp:Skype VoIP

_see._tcp:SubEthaEdit Collaborative Text Editor

_lobby._tcp:Gobby Collaborative Editor Session

_mumble._tcp:Mumble Server

# Databases

_postgresql._tcp:PostgreSQL Server

# Development

_svn._tcp:Subversion Revision Control
_svn._tcp[it]:Subversion - Versionatore

_distcc._tcp:Distributed Compiler
_distcc._tcp[de]:Verteilter Compiler
_distcc._tcp[it]:Compilatore Distribuito

_bzr._tcp:Bazaar

# Vendor specific

_MacOSXDupSuppress._tcp:MacOS X Duplicate Machine Suppression
_ksysguard._tcp:KDE System Guard
_omni-bookmark._tcp:OmniWeb Bookmark Sharing
_acrobatSRV._tcp:Adobe Acrobat
_adobe-vc._tcp:Adobe Version Cue
_home-sharing._tcp:Apple Home Sharing
_amzn-wplay._tcp:Amazon Fire TV
_qdiscover._tcp:QNAP NAS

# Other
_pgpkey-hkp._tcp:GnuPG/PGP HKP Key Server
_ldap._tcp:LDAP Directory Server
_tp._tcp:Thousand Parsec Server
_tps._tcp:Thousand Parsec Server (Secure)
_tp-http._tcp:Thousand Parsec Server (HTTP Tunnel)
_tp-https._tcp:Thousand Parsec Server (Secure HTTP Tunnel)
_shifter._tcp:Window Shifter
_xpra._tcp:Xpra Session Server
_libvirt._tcp:Virtual Machine Manager
_device-info._tcp:Device Info

静态主机名称

man avahi.hosts

/etc/avahi/hosts

1
2
3
4
5
6
7
8
9
10
11
12
# This file is part of avahi.
#
# This file contains static ip address <-> host name mappings. These
# can be useful to publish services on behalf of a non-avahi enabled
# device. Please bear in mind that host names are expected to be
# fully qualified domain names, i.e. ending in .local!

# See avahi.hosts(5) for more information on this configuration file!

# Examples:
192.168.0.1 router.local
2001::81:1 test.local

Avahi-Tools

avahi-utils

1
2
:~$ sudo apt-get update
:~$ sudo apt-get install avahi-utils

1. avahi-browse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
:~$ avahi-browse -all
+ eth0 IPv4 transmission Web Site local
+ eth0 IPv4 pi Web Site local
+ eth0 IPv4 pi SSH Remote Terminal local
+ eth0 IPv4 R7800 SSH Remote Terminal local
+ eth0 IPv4 pi Secure Web Site local
:~$ avahi-browse -r _https._tcp
+ eth0 IPv4 pi Secure Web Site local
= eth0 IPv4 pi Secure Web Site local
hostname = [pi.net]
address = [192.168.100.100]
port = [50443]
txt = ["org.freedesktop.Avahi.cookie=1839282170"]
:~$

2. other tools

  • avahi-publish
  • avahi-publish-address
  • avahi-publish-service
  • avahi-resolve
  • avahi-resolve-address
  • avahi-resolve-host-name
  • avahi-set-host-name

图形工具 avahi-discover

1
2
3
4
5
6
7
8
:~$ sudo apt-get install avahi-discover
:~$ avahi-discover
Browsing domain 'local' on -1.-1 ...
...
Found service 'pi' of type '_https._tcp' in domain 'local' on 2.0.
Found service 'transmission' of type '_http._tcp' in domain 'local' on 2.0.
Found service 'pi' of type '_http._tcp' in domain 'local' on 2.0.
Found service 'pi' of type '_ssh._tcp' in domain 'local' on 2.0.

ZeroConf与UPnPs

为什么要写成UPnPs?*因为UPnP是一个组织,而并非专指某个协议。就如同说:我们正在实现RFC XXXX,而不是说:我们正在实现IETF。

ZeroConf是一个被精确定义的,三为一体的协议,即:Address Selection(地址选择)Name Resolution(域名解析)Service Discovery(服务发现),用于降低网络配置的难度。

例如,Apple的Bonjour服务即为ZeroConf的一个实现,如果在Windows上安装了Bonjour for Windows service,可以很容易的找到并使用网络上支持ZeroConf的打印机。

ZeroConf的目的就在于提高产品的可用性与可靠性,而不需要提供复杂的文档,及降低支持成本,提高客户满意度。

相比来说,ZeroConf是一个开放的设备相关的协议集。每一个新设备,UPnP Forum都成立一个新的工作组讨论此类设备该如何工作。问题在于,虽然有许多设备声称支持ZeroConf,但这些只是在名义上的声明。例如,Windows并未使用ZeroConf去发现、配置与使用一些网络上存在的打印机。

为什么不用ZeroConf替换UPnP呢?

这里存在误解:

  1. 这里不存在选择的问题:没有道理在支持ZeroConf时,不支持ZeroConf,这在技术上完全可行。在本地地址选择这个层次上,ZeroConfZeroConf完全相同。
  2. ZeroConfZeroConf不是能够比较的概念。如前面提到的,ZeroConf是协议,ZeroConf是组织。
  3. 如果有人说:我们正在适配ZeroConf,估计有俩个意思:我们正在适配某个特定的ZeroConf协议,或这人根本就不懂他在说什么,他的意思是那些倒霉的网络配置问题已经交给底层的工程师去解决了。

结论

  • 在地址选择问题上,ZeroConfZeroConf没有本质区别;
  • ZeroConf提供了域名解析服务,而ZeroConf没有(明显的区别);
  • 在服务发现的层次上,俩者各有实现,但不冲突。ZeroConfmDNS-SD,而ZeroConfSSDP
  • 如果你是新建一个产品,而不是在一个已经存在了的ZeroConf协议模型上工作的话,使用ZeroConf是没有意义的,ZeroConf只是在很窄的方向上针对一些问题的特定实现罢了。

References:

  • AVAHI
  • Zeroconf
  • UPnP