mDNS
mDNS
1
组播地址 224.0.0.251:5353
mDNS-client : 客户端(组播请求), 带缓存(过期时间)
mDNS-server : 服务器(组播/单播响应)
mDNS 的工作原理
mDNS 的工作原理
首先,在 IP 协议里规定了一些保留地址,其中有一个是 224.0.0.251,对应的 IPv6 地址是 [FF02::FB]。
mDNS 协议规定了端口为 5353,而 DNS 的端口是 53。
mDNS 基于 UDP 协议。DNS 一般也是基于 UDP 协议的,但是也可以使用 TCP 协议。
如果理解了 DNS 协议,再去理解 mDNS 协议就很简单了,区别只是 mDNS 一般作用在一个局域网内的,有特定的 IP 地址,也就是 224.0.0.251,有特定的端口 5353,mDNS 的作用是实现局域网内的服务发现,查询,注册,DNS 作用是实现域名的解析,作用大概是一样的。
每个进入局域网的主机,如果开启了 mDNS 服务的话,都会向局域网内的所有主机组播一个消息,我是谁,和我的IP地址是多少。然后其他也有该服务的主机就会响应,也会告诉你,它是谁,它的 IP 地址是多少。当然,具体实现要比这个复杂点。
比如,A 主机进入局域网,开启了 mDNS 服务,并向 mDNS 服务注册以下信息:我提供 FTP 服务,我的 IP 是 192.168.1.101,端口是 21。当 B 主机进入局域网,并向 B 主机的 mDNS 服务请求,我要找局域网内 FTP 服务器,B主机的 mDNS 就会去局域网内向其他的 mDNS 询问,并且最终告诉你,有一个IP地址为 192.168.1.101,端口号是 21 的主机,也就是 A 主机提供 FTP 服务,所以 B 主机就知道了 A 主机的 IP 地址和端口号了。
大概的原理就是这样子,mDNS 提供的服务要远远多于这个,当然服务多但并不复杂。
在 Apple 的设备上(电脑,笔记本,iphone,ipad等设备)都提供了这个服务。很多 Linux 设备也提供这个服务。Windows 的设备可能没有提供,但是如果安装了 iTunes 之类的软件的话,也提供了这个服务。
这样就可以利用这个服务开发一些局域网内的自动发现,然后提供一些局域网内交互的应用了。
UDP单播、广播、组播
主机之间一对所有”的通讯模式,广播者可以向网络中所有主机发送信息。广播禁止在Internet宽带网上传输(广播风暴)。
广播UDP与单播UDP的区别就是IP地址不同,广播使用广播地址255.255.255.255,将消息发送到在同一广播网络上的每个主机。值得强调的是:本地广播信息是不会被路由器转发。当然这是十分容易理解的,因为如果路由器转发了广播信息,那么势必会引起网络瘫痪。这也是为什么IP协议的设计者故意没有定义互联网范围的广播机制。
广播地址通常用于在网络游戏中处于同一本地网络的玩家之间交流状态信息等。
其实广播顾名思义,就是想局域网内所有的人说话,但是广播还是要指明接收者的端口号的,因为不可能接受者的所有端口都来收听广播。
多播/组播
多播使用的是D类IP地址, 被划分为局部链接多播地址、预留多播地址和管理权限多播地址三类。
多播的程序设计使用setsockopt()函数和getsockopt()函数来实现,组播的选项是IP层的,其选项值和含义如图所示。
单播流程:主机A向主机B发送UDP数据报,发送的目的IP为192.168.1.151,端口为 80,目的MAC地址为00:00:00:00:00:02。此数据经过UDP层、IP层,到达数据链路层,数据在整个以太网上传播,在此层中其他主机会 判断目的MAC地址。主机C的MAC地址为00:00:00:00:00:03,与目的MAC地址00:00:00:00:00:02不匹配,数据链路层 不会进行处理,直接丢弃此数据。
主机B的MAC地址为00:00:00:00:00:02,与目的MAC地址00:00:00:00:00:02一致,此数据会经过IP层、UDP层,到达接收数据的应用程序。
广播的流程:主机A向整个网络发送广播数据,发送的目的IP为192.168.1.255,端口为 80,目的MAC地址为FF:FF:FF:FF:FF:FF。此数据经过UDP层、IP层,到达数据链路层,数据在整个以太网上传播,在此层中其他主机会 判断目的MAC地址。由于目的MAC地址为FF:FF:FF:FF:FF:FF,主机C和主机B会忽略MAC地址的比较(当然,如果协议栈不支持广播,则 仍然比较MAC地址),处理接收到的数据
Multicast DNS (mDNS) on Beaglebone AI
.29181/
Multi-cast Domain Name Service (mDNS) is used to provide name resolution on a local network. The use of the service allows a network to use host-names instead of IP addresses. The zero-configuration allows a network to not need a DNS Server.
When a system needs to resolve a host-name to an IP address it sends out a special packet that queries the systems on the network to respond if the host-name matches. The system which has the host-name will respond to the inquiring system. The packet contains the IP address of the responding system.
How it works
For instance, there could be a system on the network named ‘Desktop1’ which is trying to open a web page on a server named ‘WebServer’. In the browser, you may want to type in the address of 'http://WebServer’. If there is no name resolution or a static IP address in the ARP cache then this will not work.
With mDNS, the ‘Desktop1’ system sends out a packet to the network. The packet is sent as broadcast and contains the name of the other host, ‘WebServer’, and the IP Address of ‘Desktop1’. All the systems on the local network receive the packet and check the host-name listed in the packet. If the name matches the local host-name then the system will respond to the sending system. A packet is created including the necessary response details so the initial system will know it is a response to the mDNS packet it sent out. The packet includes the IP address of the responding system, ‘WebServer’, and is sent to the system that broadcast the original packet, ‘Desktop1’. Once the originating system, ‘Desktop1’, receives the response then the Address Resolution Protocol (ARP) cache will hold the name resolution information.
How to Implement mDNS
Each system must be enabled to use mDNS on the network. The process is not a hard one to implement, but it does make the network easy to use when host-names are preferred.
A few things are needed to know before we start on a system:
network adapter name
system host-names
To find these is quite simple. The network adapter name is found by running the command ‘ifconfig’ in a Terminal. Find the active adapter and note its name. To find the host-name of a system you execute the command ‘hostname’ or ‘hostnamectl’ from a Terminal on a system.
Once you have the network apter name you are ready to enable mDNS. You need to start up the BeagleBone AI so that it can be accessed using mDNS.
Beaglebone AI
The Beaglebone AI Single Board Computer (SBC) is shown in Figure 1 and has the following hardware:
Dual Arm® Cortex®-A15 microprocessor subsystem
2 C66x floating-point VLIW DSPs
2.5MB of on-chip L3 RAM
2x dual Arm® Cortex®-M4 co-processors
4x Embedded Vision Engines (EVEs)
2x dual-core Programmable Real-Time Unit and Industrial Communication SubSystem (PRU-ICSS)
2D-graphics accelerator (BB2D) subsystem
Dual-core PowerVR® SGX544™ 3D GPU
IVA-HD subsystem (4K @ 15fps encode and decode support for H.264, 1080p60 for others)
FIGURE 1
The software image is found at and can be burned to an SD card with Balena Etcher. To install and use Balena Etcher check out the article at .23269/#post-68982.
After you download the image you do not need to extract it. Balena Etcher will manage the file just as it is after the download. Once the image is on the SD card can place it into the BeagleBone AI and plug the SBC into a USB-C cable for power. The SBC will power on and after a minute should be ready to start being used.
Enable mDNS
On a system, you can access the BeagleBone AI with a Secure SHell (SSH) program such as Remina. The SBC will need to be given the information to connect to your Wi-Fi network so other systems can find it (you could also connect it to the network via an Ethernet cable).
In your Wi-Fi connections, you need to look for a network called ‘BeagleBone-xxxx’ and connect to it.
NOTE: The value of ‘xxxx’ will vary board by board.
When you are prompted for a password, use ‘BeagleBone’. Once connected you can open a Web Browser and go to ‘http://192.168.8.1’. It may take a minute for the page to completely load. Once connected you should see a screen similar to Figure 2.
FIGURE 2
Put your mouse cursor over the picture on the screen and scroll down to show the instructions as shown in Figure 3.
Figure 03.jpg
FIGURE 3
In the lower window which is a Terminal, you can type the commands shown and enable the Wi-Fi.
NOTE: The ‘MySecretPassphrase’ is the password for the Wi-Fi connection to the Router. After the first command, you will be prompted for the ‘[sudo] password for debian’ which is ‘temppwd’.
After some commands are entered you need to wait to get the response as shown in Figure 3.
Once the BeagleBone AI is connected to the Wi-Fi then you can reconnect to the normal Wi-Fi as well from the system you are using.
NOTE: You could use SSH to connect to the BeagleBone AI with the username ‘debian’ and a password of ‘temppwd’.
You can open a Terminal and type the command ‘ping beaglebone.local’ and you should not receive a response. Now we need to enable mDNS on your system so you can use the hostname of the BeagleBone AI to access it.
Enable mDNS
At this point, you do need to know the port name that you are using for your network interface. As I stated above you need to run ‘ifconfig’ and find the name. The name for my Wi-Fi adapter on my system is ‘wlo1’. Yours may be different.
You need to edit a file to enable the ability for mDNS. For example, I used ‘leafpad’ so the command to edit the necessary file is ‘sudo leafpad /etc/systemd/resolved.conf’.
Within the file is the line ‘#MulticastDNS=no’. The line should be changed to ‘MulticastDNS=yes’. Simply delete the hashtag (#) and change ‘no’ to ‘yes’. Save the files and exit your text editor.
At a command line in a Terminal execute the command ‘sudo systemctl restart systemd-networkd’. The command will restart the networking service.
You should now be able to ‘ping beaglebone.local’ and get a response. You can also open a browser and access the board with the address of ‘beaglebone.local’ as well.
The name resolution should work on all Linux systems on the network. Make sure you add ‘.local’ to the end of each hostname.
Troubleshooting
If there are issues with the name resolution then you need to check that ‘avahi-daemon’ is running. Use the command ‘sudo systemctl status avahi-daemon.service’ from a Terminal. It should show that the service is running. You should also see the hostname of the system you are executing the command as shown in Figure 4.
If the service is not started the try the command ‘sudo systemctl start avahi-daemon.service’. The service should start and all should be working.
I hope this article will aid you in some way. The Beaglebone AI board comes with mDNS already enabled.
2
局部多播地址:在224.0.0.0~224.0.0.255之间,这是为路由协议和其他用途保留的地址,路由器并不转发属于此范围的IP包。
预留多播地址:在224.0.1.0~238.255.255.255之间,可用于全球范围(如Internet)或网络协议。
管理权限多播地址:在239.0.0.0~239.255.255.255之间,可供组织内部使用,类似于私有IP地址,不能用于Internet,可限制多播范围。
属于永久组的地址:
224.0.0.1 所有组播主机
224.0.0.2 所有组播路由器
224.0.0.4 DRMRP路由器
224.0.0.5 所有OSPF的路由器
224.0.0.6 OSPF指派路由器
224.0.0.9 RPIv2路由器
224.0.0.10 EIGRP路由器
224.0.0.13 PIM路由器
224.0.0.22 IGMPv3
224.0.0.25 RGMP
224.0.1.1 NTP网络时间协议
IP到以太网地址映射
因为以太网支持多种协议,所以要采取措施分配多播地址,避免冲突。IEEE管理以太网多播地址分配。IEEE把一块以太网多播地址分给IANA以支持IP多播。块的地址都以01:00:5e开头。 第25位为0,低23位为IPv4组播地址的低23位。IPv4组播地址与MAC地址的映射关系如图所示:
发布者:admin,转转请注明出处:http://www.yc00.com/news/1692322573a585125.html
评论列表(0条)