raspberry pi
If you’re tired of looking up the IP addresses of devices you frequently access via remote login, SSH, and other means on your home network, you can save yourself a lot of time by assigning an easy to remember .local address to the device. Read on as we demonstrate by assigning an easy to remember name to our Raspberry Pi.
如果您厌倦了在家庭网络上查找经常通过远程登录,SSH和其他方式访问的设备的IP地址,则可以通过为设备分配一个易于记忆的.local地址来节省很多时间。 。 通过为Raspberry Pi分配一个易于记忆的名称来继续阅读,以示示范。
我为什么要这样做? (Why Do I Want to Do This?)
Most likely your home network uses DHCP IP assignments, which means that each time a device leaves the network and returns a new IP address is assigned to it. Even if you set a static IP for a frequently used device (e.g. you set your Raspberry Pi box to always be assigned to number 192.168.1.99), you still have to commit that entirely unintuitive number to memory. Further, if you ever need to change the number for any reason you would have to remember a brand new one in its place.
您的家庭网络很可能使用DHCP IP分配,这意味着每次设备离开网络并返回新IP地址时,都会为其分配一个IP。 即使为经常使用的设备设置了静态IP(例如,将Raspberry Pi盒子设置为始终分配为192.168.1.99 ),您仍然必须将该完全不直观的数字提交给内存。 此外,如果出于任何原因需要更改号码,则必须记住一个全新的号码。
Doing so isn’t the end of the world, but it is inconvenient. Why bother with memorizing IP strings when you can give you local devices easy to remember names like raspberrypi.local or mediaserver.local?
这样做不是世界末日,但不便。 为什么要与记忆的IP字符串时,你可以很容易记住的名字一样给你本地设备打扰raspberrypi.local或mediaserver.local ?
Now, some of you (especially those of you with a more intimate knowledge of DNS, domain naming, and other network address structures) might be wondering what the catch is. Isn’t there an inherent risk or problem in just slapping a domain name onto your existing network? It’s important here to make note of the big distinction between Fully Qualified Domain Names (FQDNs), which are officialy recognized suffixes for top-level domains (e.g. the .com portion of www.howtogeek.com that signifies How-To Geek is a commercial web site) and domain names that are either not recognized by the global naming/DNS system or are outright reserved for private network usage.
现在,您中的某些人(尤其是对DNS,域命名和其他网络地址结构有更深入了解的人)可能想知道这是什么。 仅将域名拍打到现有网络上是否存在固有的风险或问题? 在此重要的是要注意完全限定域名(FQDN)之间的巨大区别,完全限定域名(FQDN)是顶级域的官方认可后缀(例如, www.howtogeek.com的.com部分表示How-To Geek是商业广告)网站)和域名,这些域名或者是全球命名/ DNS系统无法识别的,或者是完全保留给专用网络使用的域名。
For example, .internal is, as of this writing, not a FQDN; there are no registered domains anywhere in the world that end with .internal and thus if you were to configure your private network to use .internal for local addresses, there would be no chance of a DNS conflict. That could, however, change (though the chance is remote) in the future if .internal became an official FQDN and addresses ending in .internal were externally resolvable through public DNS servers.
例如,在撰写本文时, .internal不是FQDN; 在世界任何地方都没有以.internal结尾的注册域,因此,如果您要配置专用网络以将.internal用作本地地址,则DNS冲突的可能性就很小。 但是,如果.internal成为正式的FQDN,并且以.internal结尾的地址可以通过公共DNS服务器从外部解析,则将来可能会更改(尽管机会.internal )。
Conversely, the .local domain, has been officially reserved as a Special-Use Domain Name (SUDN) specifically for the purpose of internal network usage. It will never be configured as a FQDN and as such your custom local names will never conflict with existing external addresses (e.g. howtogeek.local).
相反, .local域已被正式保留为特殊用途域名(SUDN),专门用于内部网络使用。 它将永远不会配置为FQDN,因此您的自定义本地名称将永远不会与现有的外部地址(例如howtogeek.local )冲突。
我需要什么? (What Do I Need?)
The secret sauce that makes the entire local DNS resolution system work is known as Multicast Domain Name Service (mDNS). Confusingly, there are actually two implementations of mDNS floating around, one by Apple and one by Microsoft. The mDNS implementation created by Apple is what undergirds their popular Bonjour local network discovery service. The implementation by Microsoft is known as Link-local Multicast Name Resolution (LLMNR). The Microsoft implementation was never widely adopted thanks to its failure to adhere to various standards and a security risk related to which domains could be captured for local use.
使整个本地DNS解析系统正常工作的秘诀被称为多播域名服务(mDNS)。 令人困惑的是,实际上存在两种mDNS实现,一种是Apple的,另一种是Microsoft的。 苹果公司创建的mDNS实现是其受欢迎的Bonjour本地网络发现服务的基础。 Microsoft的实现称为链接本地多播名称解析(LLMNR)。 微软的实现从未得到广泛采用,这归因于其未能遵守各种标准以及与可能捕获供本地使用的域有关的安全风险。
Because Apple’s mDNS implementation Bonjour enjoys a much wider adoption rate, has better support, and a huge number of applications for platforms big and small, we’ve opted to use it for this tutorial.
由于Apple的mDNS实施Bonjour享有更高的采用率,更好的支持以及各种大小平台的大量应用程序,因此我们选择在本教程中使用它。
If you have computers running Apple’s OS X on your network, there’s nothing you need to do beyond following along with the tutorial to set things up on the Raspberry Pi (or other Linux device) side of things. You’re set to go as your computers already support it.
如果您的网络上有运行Apple OS X的计算机,则除了遵循本教程以在Raspberry Pi(或其他Linux设备)方面进行设置外,您无需执行任何其他操作。 您已准备好,因为您的计算机已支持它。
If you’re running a Windows machine that does not have iTunes installed (which would have installed a companion Bonjour client for mDNS resolution), you can resolve the lack of native mDNS support by downloading Apple’s Bonjour Printer Service helper app here. Although the download page makes it sound like it’s a printer-only tool, it effectively adds mDNS/Bonjour support across the board to Windows.
如果您运行的Windows计算机未安装iTunes(本来已安装了随附的Bonjour客户端以进行mDNS解析),则可以通过在此处下载Apple的Bonjour打印机服务助手应用程序来解决缺少本机mDNS支持的问题 。 尽管下载页面听起来像是一个仅用于打印机的工具,但它实际上将mDNS / Bonjour支持全面添加到Windows。
在Raspberry Pi上安装Bonjour支持 (Installing Bonjour Support on Your Raspberry Pi)
The first order of business is to either pull up the terminal on your Pi or connect into the remote terminal (if you have a headless machine) via SSH. Once at the terminal, take a moment to update and upgrade apt-get. (Note: if you’ve just recently done this as part of another one of our Raspberry Pi tutorials, feel free to skip this step.)
首先要做的是拔起Pi上的终端或通过SSH连接到远程终端(如果您有无头机器)。 到达终端后,请花一点时间更新和升级apt-get。 (注意:如果您刚在Raspberry Pi教程的另一部分中完成此操作,请随时跳过此步骤。)
sudo apt-get update
sudo apt-get update
sudo apt-get upgrade
sudo apt-get upgrade
After the update/upgrade process is complete, it’s time to install Avahi–a fantastic little open source mDNS implementation. Enter the following command at the prompt:
更新/升级过程完成后,该安装Avahi了 -一种极好的开源mDNS实现。 在提示符下输入以下命令:
sudo apt-get install avahi-daemon
sudo apt-get install avahi-daemon
Once the installation process is complete, you don’t even have to reboot the device. Your Raspberry Pi will begin immediately recognizing local network queries for its hostname (by default “raspberrypi“) at raspberrypi.local.
安装过程完成后,您甚至不必重启设备。 您的树莓派将立即开始认识到本地网络查询的主机名(默认为“ raspberrypi的“) raspberrypi.local 。
The particular machine we used for this test is the same Raspberry Pi we turned into an ambient weather indicator, and then later changed the local hostname, so when we go to look for the newly minted .local address, we’ll be looking for weatherstation.local instead of raspberrypi.local.
我们用于该测试的特定机器是Raspberry Pi,它变成了一个环境天气指示器,然后又更改了本地主机名 ,因此当我们寻找新创建的.local地址时,我们将在寻找weatherstation.local而不是raspberrypi.local 。
Again, for emphasis, the portion that precedes the .local suffix is always the hostname of the device. If you want your Raspberry Pi music streamer to have the local name jukebox.local, for example, you’ll need to follow these instructions to change the Pi’s hostname.
再次强调一下,.local后缀之前的部分始终是设备的主机名。 例如,如果您希望Raspberry Pi音乐流jukebox.local的本地名称为jukebox.local ,则需要按照以下说明更改Pi的主机名 。
Go ahead and ping the new .local address on the machine you wish to access the device from now:
继续并从现在开始在要访问设备的计算机上ping新的.local地址:
Success! weatherstation.local resolves to 192.168.1.100, which is the actual IP address of the device on the local network. From now on, any application or service which previously required the IP address of the Raspberry Pi can now use the .local address instead.
成功! weatherstation.local解析为192.168.1.100,这是本地网络上设备的实际IP地址。 从现在开始,以前需要Raspberry Pi IP地址的任何应用程序或服务现在都可以使用.local地址。
翻译自: https://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/
raspberry pi