You can use the dns-sd command interactively as a network diagnosis tool to browse and discover services, similarly to the ping or traceroute command.
Because the dns-sd command-line arguments and its output format can change over time, invoking it from a shell script is unpredictable and risky. Additionally, the asynchronous nature of DNS-SD does not easily lend itself to script-oriented programming.
For more information, see the dns-sd(8) man page. To incorporate the DNS service in applications, see the libdns_sd(3LIB) man page.
The following examples show how to advertise services by using DNS service discovery.
Example 1 Advertising a Printing ServiceThis example advertises the existence of the LPR printing service on port 515 on a system called My Test so that it will be available to DNS-SD compatible printing clients.
# dns-sd -R "My Test" _printer._tcp. . 515 pdl=application/postscript
For this registration to be useful, the LPR service must be available on port 515.
Example 2 Advertising a Web PageThis example advertises a web page being served by an HTTP server on port 80 on the My Test system. The web page will appear on the Bonjour list in Safari and other DNS-SD compatible web clients.
# dns-sd -R "My Test" _http._tcp . 80 path=/path-to-page.html