Monday, July 02, 2007

Bonjour/Zeroconf fun on Linux

I have a headless Fedora linux box that plugs in to my home network and gets an IP address from DHCP.

To find it I've been pinging the broadcast address, in my case 172.16.1.255, and then trying to ssh to each of the IPs that answer until I find it. Very agricultural. Seems like a great reason to use Zeroconf.

To advertise the sshd service, put this in /etc/avahi/services/ssh.service:

<?xml version=\"1.0\" standalone=\'no\'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">
<!-- See avahi.service(5) for more information about this configuration file -->

<service-group>

<name replace-wildcards=\"yes\">ssh on %h</name>

<service>
<type>_ssh._tcp</type>
<port>22</port>
</service>

</service-group>

Here's another example showing how to include the path in the http url:

<?xml version=\"1.0\" standalone=\'no\'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">
<!-- See avahi.service(5) for more information about this configuration file -->
<service-group>
<name replace-wildcards=\"yes\">myservice on %h</name>
<service>
<type>_http._tcp</type>
<port>80</port>
<txt-record>path=/0/1/</txt-record>
</service>
</service-group>

It's a good idea to set the hostname to something reasonable in /etc/sysconfig/network and reboot.

As root:

# chkconfig --level 35 avahi-daemon on
# service avahi-daemon start

Now you can Command-Shift-K in the MacOS Terminal to browse for the sshd service.

Even better, you can use Chicken of the VNC client to browse for a VNC desktop by putting this in /etc/rc.local

# start vnc for my username at boot
su -l username -c "/usr/bin/vncserver -geometry 1200x900"

(Replace username with YOUR username).

As you, run vncpasswd and set a password. You probably want to edit ~/.vnc/xstartup to uncomment the two lines that give you the full gnome desktop. Reboot.

Now run Chicken of the VNC, do an "Open Connection..." and you'll see the host in the list. Mine comes up as Display 1, your's might be different.

I wish this stuff was just on by default.

2 comments:

Alastair said...

If you set up your DHCP and DNS server right, you can assign "static" hostnames and IP addresses so that everything should Just Work, without needing a Zeroconf-enabled client.

For each host that I want to set up on my network, I just ssh into my OpenWRT box, add the new host's MAC and IP addresses to /etc/ethers and the corresponding IP and hostname to /etc/hosts. SIGHUP the dnsmasq daemon and it's good to go.

In general I agree that more daemons should be Zeroconf-enabled though.

Also don't overlook XDMCP as a remote desktop, more responsive than VNC in my experience.

marxy said...

I used to use xdmp but it's a bit more complex to set up than I'd like and I ran into trouble exporting KDE or Gnome desktops (errors with sound or something).

VNC seems pretty responsive to me and I have to say that Firefox starts up much faster on my linux box over VNC than it does locally.

I'm a big fan of Zeroconf and it would be great if every service had at least a simple option to register itself available. Can't see any harm in that.