avahi-publish-service
Publish network services using Avahi
SYNOPSIS
avahi-publish-service [options] <name> <type> <port> [TXT record ...]
PARAMETERS
-s <SUBTYPE>, --subtype=<SUBTYPE>
Specifies a subtype for the service, allowing more granular discovery by clients looking for specific variants of a service.
-d <DOMAIN>, --domain=<DOMAIN>
Sets the domain for the service; defaults to .local for typical mDNS operations.
-H <HOST>, --host=<HOST>
Specifies the hostname under which the service is published. If not provided, the local machine's hostname is used.
-f, --no-fail
Prevents the command from exiting immediately if publishing initially fails; it will instead retry indefinitely.
-V, --version
Prints the Avahi version information and then exits.
-h, --help
Displays a help message with available options and then exits.
-v, --verbose
Enables verbose output, showing more details about the publishing process and Avahi daemon communication.
-c, --cache
Enables caching of host name lookups related to the published service, potentially improving resolution performance.
-a, --auto-rename
Automatically renames the service if a conflict is detected on the network, typically by appending a number (e.g., 'My Service (2)').
-p, --publish-address
Instructs Avahi to also publish the host's IP address along with the service record, which can be useful for direct connection.
-t, --no-terminate
Prevents the command from terminating on a SIGINT signal (e.g., Ctrl+C). This can be useful for specific scripting scenarios, but requires manual termination.
-k <KEY>, --service-key=<KEY>
Specifies a service key for authenticated service publishing, if supported and configured by the Avahi daemon.
-e, --no-echo
Suppresses the echoing of TXT record contents to standard output during the publishing process.
DESCRIPTION
avahi-publish-service is a command-line utility from the Avahi project, designed to easily publish a network service using Multicast DNS (mDNS) and DNS Service Discovery (DNS-SD), commonly known as Zeroconf or Bonjour. This allows clients on the local network to discover the service without requiring manual configuration or a central DNS server. It's particularly useful for ad-hoc service announcements, testing, or integrating Avahi-based service discovery into scripts.
The command requires you to specify the service name, type, and port, and optionally allows adding TXT records for additional information. It runs in the foreground by default, continuously publishing the service until terminated. This facilitates plug-and-play networking by enabling automatic discovery of resources like printers, file shares, or custom applications, thereby simplifying network management in dynamic environments.
CAVEATS
The avahi-daemon service must be running for avahi-publish-service to function correctly, as it acts as a client to the daemon.
The command runs in the foreground; terminating it (e.g., with Ctrl+C, unless --no-terminate is used) will stop the service announcement. For continuous availability, it should be run in a persistent manner (e.g., within a service manager like systemd, or a screen/tmux session).
mDNS/DNS-SD typically operates only within the local network segment (subnet) and does not traverse routers without specialized gateways or configurations.
Service name conflicts can occur if the chosen service name is already in use on the network and the --auto-rename option is not utilized, potentially leading to service discovery issues for clients.
SERVICE DEFINITION
The command requires three mandatory positional arguments to define the service:
name: A human-readable name for the service (e.g., My Web Server, Shared Printer). This name will be displayed to clients.
type: The service type, which typically follows a standardized format like _service._protocol. (e.g., _ssh._tcp for SSH, _http._tcp for HTTP, _ipp._tcp for IPP printers, _sftp-ssh._tcp for SFTP).
port: The TCP or UDP port number on which the service is listening.
For example, to publish an SSH service on port 22 named 'My Dev Server SSH':
avahi-publish-service "My Dev Server SSH" _ssh._tcp 22
TXT RECORDS
Optional TXT record arguments can be appended after the port number. These allow you to include arbitrary key-value pairs that provide additional information about the service to discovering clients. TXT records are vital for passing configuration details or metadata that clients might need. Examples include path=/index.html, version=1.0, location=LivingRoom, or admin_email=admin@example.com. Multiple TXT records can be provided as separate arguments.
Example with TXT records:
avahi-publish-service "Home Media Server" _http._tcp 8080 "path=/media" "user=guest"
HISTORY
Avahi emerged as a free software implementation of Apple's Bonjour (formerly Rendezvous) Zeroconf networking architecture. It was developed to provide automatic service discovery for Linux and other Unix-like systems, addressing the need for plug-and-play network capabilities. avahi-publish-service is a core command-line utility within the Avahi suite, introduced early in its development to simplify the process of service announcement from the terminal or within shell scripts. Its continuous development reflects the ongoing importance of automatic network configuration in modern computing environments.
SEE ALSO
avahi-browse(1), avahi-resolve(1), avahi-daemon(8), avahi-publish(1), nss-mdns(5)