The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Net::MDNS::Server - Perl extension for a multicast DNS server


        use Net::MDNS::Server ':all';
        service("myhost", "", 444, "perl", "tcp");
        while (1) {process_network_events}


  Advertises network services using the multicast DNS protocol, allows clients to find servers.
  May work with Apple's Rendevous software.


Multicast DNS is a lightweight protocol designed to allow easy configuration of computers on a network. You can advertise services (like http, or ftp, or anything you make up). It also allows for dynamic port numbers since part of the response to a query is the port number the service is running on.

Multicast DNS is a UDP service that runs on port 5353.

This module monitors the network for queries and responds if it has an answer. If it doesn't, it keeps quiet. In this way multiple computers can form a sort of 'DNS cluster' without even knowing about each other.

In addition, multiple servers can run on the same machine, and they will keep out of each others way, thanks to the magic of UDP.

The upshot of this is that each application can advertise its own services to the network, reusing this module, without having to worry about colliding with other servers on the same machine.

The module Net::MDNS::Client can be used to query these services.



Initialises the MDNS system. This is called automatically for you when you load the module. You don't need to call this unless you stop MDNS first.


Stops the MDNS system. Right now it's the only way of removing services.


claim_hostname(hostname, ip)

Claim the hostname. The server will start answering requests for this hostname. Any other server that tries to get this hostname will fail. Naturally, if you get in second, you will fail to get the hostname.

The IP is in dotted decimal format.

e.g. claim_hostname("my_computer", "");

service(hostname, ip, port number, service name, protocol)

Start advertising a service. The service name should be a commonly recognised one like "http" or "ssh", but you are free to make up your own. The protocol should be "tcp" or "udp".

You can use any hostname, ip address and port number that you feel like, but there aren't many good reasons to advertise services for another machine.

You may advertise as many services as you like.

e.g. service("myhostname", "", "25", "smtp", "tcp")


You have to call this as often as possible. If you don't call it enough, you'll start missing requests.


Some aspects of mDNS, like adding data to the service records, are not yet supported, but are planned.

The biggie is that service() and claim_hostname() do not return pointers to the records created, so the created services cannot be deleted. I tried returning the pointers as integers but that didn't work. Any patches would be very much appreciated.

Also, the service call should probably be spilt into multiple calls that create individual records.


The multicast DNS system is still in RFC draft stage, so search the web for "multicast DNS" for more details.


Jepri, <<gt>

Jer, <<gt>


Copyright 2003 by Jepri (Perl and C wrappers)

Copyright 2003 by Jer (C library)

This library is free software; you can redistribute it and/or modify it under the same terms as the GPL.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 154:

You forgot a '=back' before '=head1'