我正在尝试从在 Windows 上运行的 Bash 脚本通过 mDNS 连接到 PC。虽然我能够.local
在 CMD 中通过其 mDNS 地址 ping PC,但由于主机名解析问题,在 Ubuntu/Bash 窗口中执行相同操作失败。
当我尝试安装时avahi-daemon
,似乎无法启动服务,因此我无法解析 mDNS 名称。
$ sudo apt-get install avahi-daemon
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libfreetype6 os-prober
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libavahi-common-data libavahi-common3 libavahi-core7 libdaemon0 libnss-mdns
Suggested packages:
avahi-autoipd
The following NEW packages will be installed:
avahi-daemon libavahi-common-data libavahi-common3 libavahi-core7 libdaemon0
libnss-mdns
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 220 kB of archives.
After this operation, 1,094 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libavahi-common-data amd64 0.6.31-4ubuntu1 [21.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/main libavahi-common3 amd64 0.6.31-4ubuntu1 [21.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty/main libavahi-core7 amd64 0.6.31-4ubuntu1 [80.9 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty/main libdaemon0 amd64 0.14-2ubuntu1 [16.4 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ trusty/main avahi-daemon amd64 0.6.31-4ubuntu1 [58.7 kB]
Get:6 http://archive.ubuntu.com/ubuntu/ trusty/main libnss-mdns amd64 0.10-6 [21.4 kB]
Fetched 220 kB in 1s (159 kB/s)
Selecting previously unselected package libavahi-common-data:amd64.
(Reading database ... 24998 files and directories currently installed.)
Preparing to unpack .../libavahi-common-data_0.6.31-4ubuntu1_amd64.deb ...
Unpacking libavahi-common-data:amd64 (0.6.31-4ubuntu1) ...
Selecting previously unselected package libavahi-common3:amd64.
Preparing to unpack .../libavahi-common3_0.6.31-4ubuntu1_amd64.deb ...
Unpacking libavahi-common3:amd64 (0.6.31-4ubuntu1) ...
Selecting previously unselected package libavahi-core7:amd64.
Preparing to unpack .../libavahi-core7_0.6.31-4ubuntu1_amd64.deb ...
Unpacking libavahi-core7:amd64 (0.6.31-4ubuntu1) ...
Selecting previously unselected package libdaemon0.
Preparing to unpack .../libdaemon0_0.14-2ubuntu1_amd64.deb ...
Unpacking libdaemon0 (0.14-2ubuntu1) ...
Selecting previously unselected package avahi-daemon.
Preparing to unpack .../avahi-daemon_0.6.31-4ubuntu1_amd64.deb ...
Unpacking avahi-daemon (0.6.31-4ubuntu1) ...
Selecting previously unselected package libnss-mdns:amd64.
Preparing to unpack .../libnss-mdns_0.10-6_amd64.deb ...
Unpacking libnss-mdns:amd64 (0.10-6) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up libavahi-common-data:amd64 (0.6.31-4ubuntu1) ...
Setting up libavahi-common3:amd64 (0.6.31-4ubuntu1) ...
Setting up libavahi-core7:amd64 (0.6.31-4ubuntu1) ...
Setting up libdaemon0 (0.14-2ubuntu1) ...
Setting up avahi-daemon (0.6.31-4ubuntu1) ...
runlevel:/var/run/utmp: No such file or directory
invoke-rc.d: policy-rc.d denied execution of force-reload.
runlevel:/var/run/utmp: No such file or directory
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for ureadahead (0.100.0-16) ...
Setting up libnss-mdns:amd64 (0.10-6) ...
First installation detected...
Checking NSS setup...
Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
$ ping my-other-pc.local
ping: unknown host my-other-pc.local
我需要做什么才能解析 mDNS 名称?除了安装 Avahi 之外,还有其他方法吗?或者我需要做其他什么才能使此包正常运行?
答案1
您有两个选择:
安装此
libnss-mdns
软件包将更改您系统的解析器以.local.
通过 mDNS 查询域。请注意,此软件包的大多数版本都不遵守local
解析器搜索路径(请参阅这个答案) 因此您需要查找MacbookPro.local
而不仅仅是MacbookPro
。安装
avahi-utils
软件包并使用该avahi-resolve
程序进行查找。您可能还会发现此软件包中的其他工具是查找服务等的更简便的方法。