Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to advertise a service using Bonjour across subnets?

I am familiar with the usage of Bonjour for advertising services on the "local" domain. I have worked through several examples, and I know the corresponding Cocoa classes I use for that.

I am curious about how I advertise a simple Bonjour service to a different subnet. Specifically, I am trying to write a network service that runs on my desktop which is connected via ethernet. The client runs on a mobile device (iPhone/iPad) that is connected via Wifi. In my network setup, the Wifi is on a different subnet than the ethernet. However, both are behind the firewall. I have no need to advertise outside the firewall, I simply want wifi clients to be able to see services advertised by a ethernet connected server.

Is this possible? I know Bonjour is supposed to support communication across subnets, but anytime I try to read about this feature it dives deep into DNS records and whatnot. I am an application developer...I have no idea about that stuff, nor do I want users to have to worry about it. Am I missing something simple?

like image 203
pj4533 Avatar asked Sep 20 '10 15:09

pj4533


1 Answers

This is not a typical programming question, but I see it's a huge obstacle in testing your Bonjour based code.

Bonjour supports two mechanisms for servers to inform clients about their existence, multicasts on local network first, DNS second.

Multicasts are easy to use because there is no setup, unfortunately it can only be used on the same network.

DNS have the luxury of working across routers (Internet), but it requires properly configured nameserver and clients using that nameserver.

I think you are having only two options.

  1. advertise your bonjour service on WiFi network
  2. configure your own DNS

In the first case it is important to realize that the service doesn't necessarily have to be advertised by your own application running on a Mac. You can use utility dns-sd to register any IP address/port as a Bonjour service on the network. For this to work you need a machine (Mac, Linux) which is connected to your WiFi, and run dns-sd there in a similar way to this:

dns-sd -P "Stack Overflow" _http._tcp . 80 stackoverflow.com 69.59.196.211

This would register an "http" service with name "Stack Overflow" as a Bonjour service. Check it out - run it in terminal and check it in Safari's Bookmarks under Bonjour. The same way you can register your application.

Unfortunately you need to run this on a machine connected to WiFi network. That means your Mac application will advertise on its own ethernet network, dns-sd advertises on WiFi.

Second option is a bit frightening, but it's not a big deal if you're willing to get hands dirty with some administration.

Again, you don't need to have services dynamically registered in DNS. You can simply hard code your Mac's name and your app's port in the DNS configuration. Those are just 4 lines that need to be added to the zone file (DNS configuration file).

b._dns-sd._udp  IN PTR @   ;  b = browse domain
lb._dns-sd._udp IN PTR @   ; lb = legacy browse domain
_icool._tcp  PTR iCool\ App\ Service._http._tcp
iCool\ App\ Service._http._tcp     SRV 0 0 8888 macpro.domain.com.

First two lines tells clients (iOS devices in your case) that Bonjour is enabled for this domain. Third line tells clients that there is a service "iCool App Service" of type icool available. Fourth line tells clients current address and port of the service.

Clients will look for DNS entries for their configured (or gotten via DHCP) "Search Domains". Check your network settings.

You can run nameserver on your Mac, some Linux box, or you can use services like dyndns.com.

Hope this helps.

like image 160
Michal Avatar answered Oct 02 '22 06:10

Michal