Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:guide-developer:mdns [2019/03/10 16:39] – updated ubus commands exploidedocs:guide-developer:mdns [2024/10/17 00:59] (current) – [Config File] bartprokop
Line 5: Line 5:
 //This is early stage documentation, but at least attempts to cover some basic usage, and bring umdns usage out of the dark.// //This is early stage documentation, but at least attempts to cover some basic usage, and bring umdns usage out of the dark.//
  
-mDNS, also known as Bonjour or zero-configuration networking, enables automatic discovery of computers, devices, and services on IP networks. It is an internet standard documented in [[https://tools.ietf.org/html/rfc6762|RFC6762]].+mDNS, also known as Bonjour or zero-configuration networking (ZeroConf) or DNS Service Discovery (DNS-SD), enables automatic discovery of computers, devices, and services on IP networks. It is an internet standard documented in [[https://tools.ietf.org/html/rfc6762|RFC6762]].
  
-The umdns package provides a compact implementation of this standard, well integrated with the OpenWrt system environment. In particular, almost all interaction with the daemon is via [[docs:guide-developer:ubus]].+The [[packages:pkgdata:umdns]] package provides a compact implementation of this standard, well integrated with the OpenWrt system environment. In particular, almost all interaction with the daemon is via [[docs:guide-developer:ubus]].
  
 ==== Alternatives ==== ==== Alternatives ====
 +See [[docs:guide-user:network:zeroconfig:zeroconf|Zero configuration networking in OpenWrt]]
 +==== Config File ====
  
-  * mdnsd provided by Apple's mDNSResponder package +<code /etc/config/umdns> 
-  * avahi-A fairly full, but quite large implementation+config umdns 
 + option jail 1 # enables jail - see procd 
 + list network lan 
 + list network dmz # Provides visibility into both networks, but does not act as a repeater 
 +</code> 
 + 
 +Note that it may be unsafe to enable umdns on ''wan'' interface. 
 + 
 +Note that ''%%network list%%'' argument refers to interface name under ''%%/etc/config/network%%'' not the device name shown by ''%%ifconfig%%''. Test if you using the right name with ''%%ifstatus%%''. So if you have something like ''%%config interface 'vlan1'%%'' in your ''%%/etc/config/network%%'', use ''%%vlan1%%''. 
 + 
 +==== Install ==== 
 +umdns is available starting from OpenWRT 17 and to install it execute ''opkg install umdns'' 
 + 
 +==== Firewall ==== 
 +If you need to advertise on WAN or other networks then UDP port 5353 should be opened in firewall: 
 +<code - /etc/config/firewall> 
 +config rule 
 +        option src_port '5353' 
 +        option src '*
 +        option name 'Allow-mDNS' 
 +        option target 'ACCEPT' 
 +        option dest_ip '224.0.0.251' 
 +        option dest_port '5353' 
 +        option proto 'udp' 
 +</code> 
 +To configure from GUI see "Firewall rules" section of [[https://blog.christophersmart.com/2020/03/30/resolving-mdns-across-vlans-with-avahi-on-openwrt/|Resolving mDNS across VLANs with Avahi on OpenWRT]]
  
 ==== Browsing announced services ==== ==== Browsing announced services ====
Line 50: Line 77:
       },       },
    ....    ....
 +$ ubus call umdns hosts 
 +#Show hosts discovered via mDns
 +        "SteakPrinter.local": {
 +                "ipv4": "192.168.1.159"
 +        },
 +        "Upstairs.local": {
 +                "ipv4": "192.168.1.151"
 +        },
 </code> </code>
  
Line 57: Line 92:
   * TXT records aren't valid json in the dump, so jsonfilter can't be used.   * TXT records aren't valid json in the dump, so jsonfilter can't be used.
   * How long is data cached? What causes it to update? No idea.   * How long is data cached? What causes it to update? No idea.
 +  * You may not see locally advertised services with ''ubus call umdns browse''. See the [[https://forum.openwrt.org/t/how-to-announce-service-with-umdns/5029/7|discussion]]
  
 ==== Announcing local services ==== ==== Announcing local services ====
-'umdnsscans all the services listed in 'ubus(''ubus call service list'') and looks for 'mdns' objects in their data object.  You can view this more selectively for example with:+The umdns scans all the services listed in ubus (''ubus call service list'') and looks for ''mdns'' objects in their data object. You can view this more selectively for example with:
 <code> <code>
-# ubus call service list | jsonfilter -e '@[*].instances[*].data.mdns'+# ubus call service list | jsonfilter -e "$[*]['instances'][*]['data']['mdns']"
 { "ssh_22": { "service": "_ssh._tcp.local", "port": 22, "txt": [ "daemon=dropbear" ] } } { "ssh_22": { "service": "_ssh._tcp.local", "port": 22, "txt": [ "daemon=dropbear" ] } }
 </code> </code>
Line 67: Line 103:
 Here we can see that ssh is being advertised locally. Here we can see that ssh is being advertised locally.
  
-If you want to advertise your own service, your service needs to (*AT THE TIME OF WRITING* 2017-07-11) be a [[docs:guide-developer:procd]] managed service. You can use the ''procd_add_mdns'' call to provide a basic definition.+If you want to advertise your own service, your service needs to be a [[docs:guide-developer:procd]] managed service. You can use the ''procd_add_mdns'' call to provide a basic definition.
 <code> <code>
 procd_open_instance procd_open_instance
Line 78: Line 114:
 As an example, the following call As an example, the following call
 <code> <code>
-procd_add_mdns "hoho" "tcp" "99" "daemon=special" "colour=fuschia"+procd_add_mdns "webdav" "tcp" "80" "path=/nextcloud/remote.php/dav/files/YOUR_USER/" "u=YOUR_USER"
 </code> </code>
-will result in advertising ''_hoho._tcp.local'' with two text records.+will result in advertising ''_webdav._tcp.local'' with two text records
 +In the example we published a WebDAV folder from Nextcloud and now it can be seen in Network folder of a file manager in GNOME and KDE and can be [[https://kodi.wiki/view/Avahi_Zeroconf|discovered from a Kodi media player]]. 
 +The service names may be taken from the [[https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml|IANA register]] and the txt-records may be taken from the official DNS-SD keys (see [[http://www.dns-sd.org/ServiceTypes.html|ServiceTypes]] under "Defined TXT keys".
  
 If you wish to create a more complicated mdns information block, see ''procd_add_mdns_service'' in ''/lib/functions/procd.sh'' but be warned that umdns probably can't automatically support everything you can represent in json. If you wish to create a more complicated mdns information block, see ''procd_add_mdns_service'' in ''/lib/functions/procd.sh'' but be warned that umdns probably can't automatically support everything you can represent in json.
 +
 +===== Service description files in /etc/umdns =====
 +umdns advertises the services whose ''*.json'' files are found in ''/etc/umdns''. This is similar to how Avahi advertises ''*.service'' files in ''/etc/avahi/services/''.
 +
 +For example the same WebDAV service description:
 +<code - /etc/umdns/nextcloud_webdav.json>
 +{
 +  "nextcloud_webdav": {
 +    "service": "_webdav._tcp.local",
 +    "port": 80,
 +    "txt": [
 +      "path=/nextcloud/remote.php/dav/files/YOUR_USER/",
 +      "u=YOUR_USER"
 +    ]
 +  }
 +}
 +</code>
 +Or you can advertise SFTP and SSH:
 +<code - /etc/umdns/ssh.json>
 +{
 +  "ssh_login": {
 +    "service": "_ssh._tcp.local",
 +    "port": 22,
 +    "txt": [
 +      "u=root"
 +    ]
 +  },
 +  "sftp_share": {
 +    "service": "_sftp-ssh._tcp.local",
 +    "port": 22,
 +    "txt": [
 +      "path=/",
 +      "u=root"
 +    ]
 +  }
 +}
 +</code>
 +See more examples in [[commit>?p=project/mdnsd.git;a=tree;f=json;hb=HEAD|umdns sources]]
 +
 +The reload the umdns service with: ''ubus call umdns reload'' or ''service umdns reload''
 +
 +==== Testing ===
 +To see that service was advertised you may use ''avahi-discover'' GUI application.
 +To see from a command line use ''avahi-browse --all''.
 +To find a specific service use: ''avahi-browse -d local _webdav._tcp''.
 +
 +
  • Last modified: 2019/03/10 16:39
  • by exploide