Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dns-sd: how to manually register a remote service

I have a service on another remote system which is on another physical network and its multicast packages don't get to my local system, thus I don't see its DNS-SD published services.

I there a way I can manually register it on my local machine so that applications which only show DNS-SD discovered services show it?

like image 276
Albert Avatar asked Nov 16 '11 15:11

Albert


2 Answers

With Avahi temporary registrations can be created using avahi-publish and persistent ones can be created by writing a static service file. See man 1 avahi-publish for more on the former and man 5 avahi.service for more on the later.

With Bonjour the dns-sd tool can be used to proxy register a service:

dns-sd -P <Name> <Type> <Domain> <Port> <Host> <IP> [<TXT>...]

If the service you're proxy registering already has a unicast DNS hostname something like this will work:

$ dns-sd -P Google _http._tcp local 80 google.com google.com path=/
Registering Service Google._http._tcp.local host google.com port 80 TXT path=/
 4:23:00.928  Got a reply for service Google._http._tcp.local.: Name now registered and active
^C

If it doesn't have a hostname a unique name should be used for the host:

$ dns-sd -P Google _http._tcp local 80 google.local 74.125.237.144 path=/
Registering Service Google._http._tcp.local host google.local port 80 TXT path=/
 4:16:48.208  Got a reply for record google.local: Name now registered and active
 4:16:48.208  Got a reply for service Google._http._tcp.local.: Name now registered and active
^C
like image 88
andrewtj Avatar answered Dec 20 '22 20:12

andrewtj


This is just what I was looking for. I wanted to make a service housed on a non-OS X system visible from outside the home network. Elsewhere on here, I found out how to use scutil to find out my Back to My Mac network:

echo show Setup:/Network/BackToMyMac | scutil | sed -n 's/.* : *\(.*\).$/\1/p' 

So I can take that and use it to populate this:

BTMM=`echo show Setup:/Network/BackToMyMac | scutil | sed -n 's/.* : *\(.*\).$/\1/p'`

dns-sd -P <advertised host name> _ssh._tcp ${BTMM} 22 <real host name> <real IP address—could be a hostname if it resolves> path=/

The beauty of this is that I don't have to remember to do anything before I leave the house, as long as some variant of ZeroConf is running. I can advertise the remote service from wherever I am, use it, then take down the advertisement. So I run the commands and then look in my Shell -> New Remote Command dialog and there it is. I can then copy files to and fro, run commands, access the home network, all as if I was there.

like image 28
paulbeard Avatar answered Dec 20 '22 22:12

paulbeard