Multicast DNS (mDNS) & DNS Service Discovery (DNS-SD) Test Tool

dns-sd commad arga

Intended for interactive use as many commands wait for changes until interrupted.

-E list domains recommended for registering(advertising) services.
dns-sd -E
Looking for recommended registration domains:
DATE: ---Thu 29 Oct 2020---
16:41:56.469  ...STARTING...
Timestamp     Recommended Registration domain
16:41:56.470  Added                          local
-F Find domains recommended for browsing services.
Normally, on a LAN the only domain expected is "local". If there are Domain Enumeration records, recommended domains for registering and browsing.
 dns-sd -F
Looking for recommended browsing domains:
DATE: ---Thu 29 Oct 2020---
16:40:31.648  ...STARTING...
Timestamp     Recommended Browsing domain
16:40:31.649  Added                          local
-B _service [domain] _tcp Browse for instances
valid services include:ftp,ssh,telnet,smtp,domain, tftp, http, pop3, …. See /etc/services and IANA.org. As of 10/29/20 services are defined through 49150 (although many are not)

Omitting the domain or using "." means "pick a sensible default."

dns-sd -B _http._tcp
Browsing for _http._tcp
DATE: ---Thu 29 Oct 2020---
12:39:29.999  ...STARTING...
Timestamp     A/R    Flags  if Domain   Service Type Instance Name
12:39:29.999  Add        3   4 local.   _http._tcp.  Photosmart 7520 series [C658CA]
12:39:30.000  Add        3   4 local.   _http._tcp.  D-Link DAP-1320 Configuration Utility
12:39:30.000  Add        2   4 local.   _http._tcp.  Omega-CFDC
13:28:17.127  Add        2   4 local.   _http._tcp.  QcJSPiNEd/jK6iOhRDTk7g==
13:39:09.521  Rmv        0   4 local.   _http._tcp.  QcJSPiNEd/jK6iOhRDTk7g==

dns-sd -B _ssh._tcp
Browsing for _ssh._tcp
DATE: ---Thu 29 Oct 2020---
15:47:18.087  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
15:47:18.088  Add        3   4 local.               _ssh._tcp.           smackerpro
15:47:18.088  Add        3   4 local.               _ssh._tcp.           Omega-CFDC
15:47:18.088  Add        2   4 local.               _ssh._tcp.           smacpro
15:47:18.220  Add        2   1 local.               _ssh._tcp.           smacpro
-L name type domain Look up information necessary to contact and use the service: the hostname of the machine where that service is available, the port number on which the service is listening, and TXT record attributes describing properties of the service.

in a typical application, browsing may only happen rarely, while lookup (or "resolving") happens every time the service is used.
For example, a user browses the network to pick a default printer fairly rarely, but once a default printer has been picked, that named service is resolved to its current IP address and port number every time the user presses Cmd-P to print.

-q name [rrtype [rrclass]] query any DNS name, resource record type, and resource record class, not necessarily names and record types.
rrtype defaults to A
rrclass defaults to IN .
If name is not a fully qualified domain name, search domains may be appended.
This information can also be retrieved with dig
 dns-sd -q dalogger.cccu.us
DATE: ---Thu 29 Oct 2020---
16:20:21.948  ...STARTING...
Timestamp     A/R    Flags if Name         Type  Class   Rdata
16:20:22.044  Add        2  0 logr.cccu.us. Addr   IN
dns-sd -q CCCU.US mx
DATE: ---Thu 29 Oct 2020---
16:02:10.650  ...STARTING...
Timestamp     A/R    Flags if Name     Type  Class   Rdata
16:02:10.758  Add        2  0 cccu.us. MX     IN     11 bytes: 00 00 04 63 63 63 75 02 75 73 00  
                                                            sic  i.e. cccc us
 dns-sd -q cccu.us soa
DATE: ---Thu 29 Oct 2020---
16:05:20.852  ...STARTING...
Timestamp     A/R    Flags if Name     Type   Class Rdata reformatted
16:05:20.853  Add 40000002  0 cccu.us. SOA     IN  dns1.midphase.com. cpanel-admin.midphase.com. 
                                           Ser 2014061600 Ref 86400 Ret 7200 Exp 3600000 Min 86400
dns-sd -q cccu.us ns 
DATE: ---Thu 29 Oct 2020---
16:06:30.974  ...STARTING...
Timestamp     A/R    Flags if Name       Type  Class   Rdata
16:06:30.975  Add 40000003  0 cccu.us.   NS     IN     dns1.midphase.com.
16:06:30.975  Add 40000002  0 cccu.us.   NS     IN     dns2.midphase.com.
From dig cccu.us
cccu.us.  14400   TXT "v=spf1 +a +mx +ip4: +ip4: ~all"
cccu.us.        14400   MX  0 cccu.us.
cccu.us.        86400   SOA dns1.midphase.com. hostmaster.midphase.com. 
                                               2020091201 86400 7200 604800 600
cccu.us.        3600    NS  dns2.midphase.com.
cccu.us.        3600    NS  dns1.midphase.com.
cccu.us.        14400   A
-Z type domain browse for service instances and display output in zone file format.
-G v4/v6/v4v6 name Get the IP address of name.
If the name is not a fully qualified domain name, then search domains may be appended
 dns-sd -G v4v6 cccu.us
DATE: ---Thu 29 Oct 2020---
16:23:03.859  ...STARTING...
Timestamp     A/R    Flags if Hostname Address                                      TTL
16:23:03.859  Add 40000003  0 cccu.us. 0000:0000:0000:0000:0000:0000:0000:0000%<0> 4289 No Such Record
16:23:03.860  Add 40000002  0 cccu.us.                               4502
-R name type domain port [key=value … ] Register (advertise) a service in the specified domain with the name and type as listening (on the current machine) on port.
name can be arbitrary unicode text, containing any legal unicode characters (including dots, spaces, slashes, colons, etc. without restriction), up to 63 UTF-8 bytes long.
type must be of the form _app-proto._tcp or _app-proto._udp, where "app-proto" is an application protocol name registered at http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml.
domain is the domain in which to register the service. only the local multicast domain "local" is supported. "." is a synonym for "local".
port is a number from 0 to 65535.
Additional attributes of the service may be described by key/value pairs, which are stored in the advertised service's DNS TXT record. Allowable keys and values are listed with the service registration at IANA.org
-P name type domain port host IP [key=value …] create a Proxy advertisement for a service running on another machine. The options are Host, a name for the device and IP, the address of it.
The service need not be on the local network. It may be a local proxy for a website on the Internet.
-X udp/tcp/udptcp IntPort ExtPort TTL NAT Port Mapping
-V version running daemon/system service.
Currently running daemon (system service) is version 1097.0.3
sudo dns-sd -O
XPC service returns error, description: State dump is only enabled in internal builds


DNSService call failed -65540 (x'10004')
with exit code =255

No Such Record DNS server could not be contacted, exit code 130.


To advertise the existence of LPR printing service on port 515 on this machine, such that it will be discovered by the Mac OS X printing software and other compatible printing clients, use:
dns-sd -R "My Test" _printer._tcp. . 515 pdl=application/postscript
advertise a web page being served by an HTTP server on port 80 on this machine, such that it will show up in the Bonjour list in Safari and other compatible Web clients, use:
dns-sd -R "My Test" _http._tcp . 80 path=/path-to-page.html
To find the advertised web pages on the local network (the same list that Safari shows), use:
dns-sd -B _http._tcp
In another window, use the dns-sd -R example given above to advertise a web page. You should see the "Add" event reported to the -B window.
Press Ctrl-C in the dns-sd -R window and you should see the "Remove" event reported to the -B window.

In the example below, the www.apple.com web page is advertised as a service called "apple", running on a target host called apple.local, which resolves to

dns-sd -P apple _http._tcp "" 80 apple.local
The Bonjour menu in the Safari web browser will now show "apple". The same IP address can be reached by entering apple.local in the web browser. In either case, the request will be resolved to the IP address and browser will show contents associated with www.apple.com. If a client wants to be notified of changes in server state, it can initiate a query for the service's particular record and leave it running. For example, to monitor the status of an iChat user you can use: dns-sd -q someone@ex1._presence._tcp.local txt Everytime status of that user(someone) changes, you will see a new TXT record result reported. query for a unicast name like www.apple.com and monitor its status. dns-sd -q www.apple.com


For us inscripts use is documented in /usr/include/dns_sd.h. The dns-sd command replaces the older mDNS command. mDNSResponder(8)

For example, if you are programming in Ruby, then you can directly call DNS-SD APIs using the dnssd package documented at RubyForge.org.