mDNS multicast DNS, using port 5353, multicast address 188.8.131.52. In a small network without a regular DNS server, mDNS can be used to implement DNS-like programming interfaces, packet formats, and operational semantics. The MDNS protocol packet has the same message structure as the DNS packet, but some fields have new meanings for MDNS.
Each host that enters the LAN will multicast a message to all hosts on the LAN if the mDNS service is enabled. Who am I, and what is my IP address? Then other hosts that have the service will respond and will tell you who it is and what its IP address is. The domain name of the mDNS is distinguished from the domain name of the normal DNS by the suffix .local. If a terminal needs to access an mDNS domain name, it will send a multicast to the LAN and ask what the IP of the domain name is.
A device accesses the network, first queries whether the name conflicts, and notifies the current server information.
After the conflict detection ends, send an MDNS advertisement to notify other devices to update the DNS cache.
When other devices access the domain name, an MDNS query will be initiated.
1. Relay configuration (gateway application)
In the traditional TCP/IP-based communication mode, if communication between devices is required, the IP address of the peer device must be known. Because the IP address is not well remembered, in order to facilitate memory and improve usability, the network administrator can configure the DNS service to facilitate access by other devices through the domain name. In this way, when a device accesses other devices through a domain name, you need to configure a DNS server on the device to resolve the IP address corresponding to the domain name. In order to reduce the manual configuration cost of network equipment, Apple proposed Zero-configuration networking (Zero-configuration networking).
A zero-configuration network refers to network devices that implement automatic address configuration, domain name resolution, and service discovery without requiring administrators to participate in configuration. They are widely used in home wireless networks and enterprise office networks. Bonjour technology is a solution proposed by Apple based on the multicast domain name system mDNS (Multicast Domain Name System) and the DNS-based service discovery protocol DNS-SD (DNS-Based Service Discovery) protocol. The technology applied to the Layer 2 broadcast domain enables the network devices in the Layer 2 broadcast domain to automatically obtain addresses and discover services. Most Apple products (such as iPhone, iPad, Apple TV, etc.) support Bonjour technology.
The Bonjour technology can only implement service discovery in the same VLAN. In order to realize service discovery across VLANs and across network segments, Huawei has proposed a solution for mDNS gateway and mDNS relay. The mDNS relay is responsible for forwarding mDNS messages between the Bonjour device (the user terminal or service providing device supporting Bonjour technology) and the mDNS gateway. In this way, user terminals supporting Bonjour technology can implement printer and Airplay service discovery across network segments.
A service-providing device (such as Apple TV) using Bonjour technology announces the services it can provide through the multicast address (the IPv4 address is 184.108.40.206). The user terminal device (for example, a client such as an iPhone or an iPad) requests an available service in the local network by sending an mDNS request message whose destination multicast address is 220.127.116.11. On the one hand, the service sharing in the network is realized, and on the other hand, the client can access the service resources in the network.
However, the destination multicast address (18.104.22.168) used for the mDNS protocol to exchange information is valid only in the Layer 2 broadcast domain. That is, it can only be forwarded in the same VLAN. It cannot be forwarded across VLANs or across Layer 3 devices. As shown in [Figure 6-1] (http://support.huawei.com/enterprise/docinforeader!loadDocument1.action?contentId=DOC1000049740&partNo=10062#dc_fd_mdns_000101), the enterprise network usually plans multiple VLANs or multiple network segments. Apple TV_1, Apple TV_2, and Printer are on different network segments. The iPhone in VLAN 10 can only discover the services of Apple TV_1 in this VLAN; the Apple TV_2 service in VLAN 20 and the Printer service connected to the AC cannot be found.
Figure 6-1 Network diagram for mDNS gateway application
2. google IoT framework weave
Google Weave Framework (Reference: http://www.uml.org.cn/xjs/201611012.asp)
The Weave Local API uses the mDNS protocol to solve the first problem. We know that the DNS protocol is used to resolve between computer names and IP addresses. When accessing the Internet, the user generally enters the domain name of the website to be accessed in the browser, which is essentially the name of a server. The browser will query the DNS server, translate the server’s name into the corresponding IP address, and then establish a connection with the server through the TCP/IP protocol and download the web page. This process requires an important role – DNS server support. DNS servers typically exist in large networks with hundreds or thousands of computers and require complex management and configuration by network administrators. In a small network such as a home network, there is generally no DNS server, so the traditional DNS protocol cannot be used to resolve the IP address of the Weave device. The mDNS protocol is specifically designed for small networks such as home networks. In the mDNS architecture, there is no need for a centralized DNS server. As long as the terminal devices are all in a LAN (strictly speaking, it should be in a broadcast domain) and support the mDNS protocol, the IP addresses can be mutually resolved and peer-to-peer communication can be completed.
Because there is no centralized DNS server, the terminals running the mDNS protocol communicate with each other through multicast (which can be understood as broadcast). The smartphone client knows the name of the Weave device (completed through the registration mechanism and recorded in the smartphone client), which sends an mDNS request broadcast containing the name of the target device. This broadcast request is received by all devices on the same LAN, but only the device whose requested name matches its own name will respond to the smartphone client with a response. This response contains its own IP address. So the smartphone client knows the IP address of the Weave device, and then it can communicate based on the normal TCP/IP protocol.
3.Smart Home (HomeKit)
4. Airplay Protocol Basics
to sum up
mDNS is a protocol supplement in the LAN without a central DNS server, and the application scenario is still very extensive. Moreover, basically the current smart phones, pcs, etc. have their own protocols, and the client code can be developed based on the protocol without introducing a third-party sdk package.