Saturday, August 16, 2014

Setup Avahi to Use mDNS with a Raspberry Pi Running Arch Linux

Avahi is a simple open source Zero Configuration networking solution for Linux. It is tantamount to Bonjour for the OSX platform. The setup is pretty simple and straight forward. Since we have connected our Pi's to our laptops with a static IP it is really not necessary to use Avahi for name resolution because we could just add a line to our /etc/hosts file. However, if we have printers and other network clients that we would like to make available to our Pi and Laptop Avahi is a good choice to use to access these other DHCP clients on our network and the setup is simple enough.

Step 1:

Make sure you have a hostname set in the /etc/hostname on your Pi:

nano /etc/hostname
# /etc/hostname 

Make sure a hostname is set on your laptop also. If using systemd:

nano /etc/hostname 
# /etc/hostname 

or if your laptop uses systemv: 

nano /etc/conf.d/hostname 
# Set to the hostname of this machine 

Step 2:

Install Avahi on your Pi:

pacman -Sy avahi nss-mdns 

Install on your laptop per your distro's package manager.

On both the Pi and the laptop, setup mDNS in your nsswitch.conf file. This will tell your OS to do a lookup with Avahi along with other name resolution methods:

nano /etc/nsswitch.conf 

find the hosts line and edit it as such:

hosts: files myhostname mdns4_minimal [NOTFOUND=return] dns mdns4 

Step 3:

Start the daemon on your Pi:

systemctl enable avahi-daemon
systemctl start avahi-daemon.service 

Start the daemon on your laptop the same way if you use systemd.
If you use rc-update do:

rc-update add avahi-daemon default

and start the daemon:

/etc/init.d/avahi-daemon start 

Step 4:

See if it all works as expected.

avahi-browse --all 

on each box to see what is shown on your network. You will need Zero Config software on every client in your network you would like to interact by name.local.
Now try to ping from your laptop:

ping my-pi.local

and from the Pi:

ping my-laptop.local

To see if your ping is working.

Step 5

If all works as expected, reboot and retest with Step 4.


If you still have an old IP assigned to the name for some reason (e.g. and earlier yet removed entry in /etc/hosts) try:

avahi-resolve -n my-pi.local 

to fix.


avahi-discover Cannot be used without X, so you are out of luck if you run your Pi Headless, but you can still use it from your laptop and such.

Thursday, August 14, 2014

Connect a Laptop Running WICD to a Raspberry Pi with a Persistent Peer to Peer Connection

Connect a Raspberry Pi to a Laptop that uses WICD for WiFi management with a Persistent Peer to Peer Wired Ethernet Connection and Connect Both to the Internet Simultaneously Without Blowing your brains out.....

This article assumes:

The two computers are connected with a crossover cable or at least one of the adapters are CrossOver aware. (see: Do you need a crossover cable?
Both the Raspberry Pi and the Laptop are connected to the internet and each other with a WiFi connection and the Pi is accessible with ssh..
The Laptop uses Wicd to manage Wifi connections....

Note: If at least one of the two cards supports Auto-MDIX, then the cross-over function will be taken care of automatically.

Your Pi should be Auto-MDIX.


I recently purchased a Raspberry Pi and a WiFi dongle to connect to my WiFi router. I also have a WiFi connection on my laptop. However, the limitations of this type of connection became apparent when using NFS and trying to access my rtl dongle with a tcp connection. The wireless was just too slow.
It is usually simple enough in a case such as this to simply add a peer to peer wired link to share such services. However, I ran into problems because I use WICD to manage my WiFi connection on my Laptop. WICD is not scheduled to manage two connections simultaneously until version 2. Not having much luck using Network Manager with my Atheros wireless card I was a bit leery of ditching WICD for Network Manager. So I decided to figure out how to use the connection scripts in WICD to make my wired connection persistent. The main advantage of this method is my wired connection to the Pi is only attempted if I am at home. Since the connection scripts are per connection if I connect to another WiFi hotspot the wireless adapter will never attempt to connect to the Pi or attempt to mount my NFS shares. In short, the secret to making this all work was to blank out the entry for the wired connection in WICD and just manage the connection with ifconfig in the script.


Here is a Network Diagram showing the layout of our Network:

Step 1:

Connect manually to see if it works:

On Pi:
ifconfig eth0 netmask broadcast

On laptop:
ifconfig eth0 netmask broadcast

from latop to test
from pi to test

Use mii-tool to diagnose connection problems:
mii-tool eth0
And look for this in output:
eth0: negotiated 100baseTx-FD flow-control, link ok

The “link ok” is the important part. This means that your cables have a connection on the link layer.
mii-tool eth0 -r

to fix problems. This command resets the link layer connection.

Depending on your distro, you wired connection may not be eth0. Use ifconfig with no switches from the command line to determine the name of your wired interface.

You will need to install mii-tool from your distro's package manager to use it. Refer to your distro's package manager documentation.

Step 2:

Make the connections persistent.

Setup the Pi:

Copy netctl static profile
cp /etc/netctl/examples/ethernet-static /etc/netctl/static

Then edit
nano /etc/netctl/static

To edit ip setting:

add line:

NOTE: the 'SkipNoCarrier' line should come before the 'Address' line.

The line above will make sure your Pi assigns an IP address to the interface regardless of whether the cable is connected or not.

make sure ifplugd is disabled with systemctl
systemctl disable ifplugd

Enable and start your new profile:
netctl enable static
netctl start static

Alternate method (probably better)

If you use this method do not create a netctl service for the interface. If you already have a netctl service for this interface, disable it with netctl.

cd /etc/systemd/network

Edit file to look like:







NOTE: Don't add an address line in the netctl profile if you have set an address here.

Setup Laptop

Open wicd tray icon
Preferences → General Settings → wired interface: blank

Add post connect script:

nano /etc/wicd/scripts/postconnect/start-wire

Now add these lines to the script:

# /bin/bash
ifconfig eth0 netmask broadcast
# wait
# mount /mnt/<nfs-share>

Reboot to test.

You may need to add a static ip address for your interface to avoid DHCP errors on boot if you use OpenRC on your laptop.

nano /etc/conf.d/net

Add the line:

config_eth0=" netmask broadcast"

Now you should have a static wired connection between your laptop and Pi. Next article will be on setting up an avahi server on the Pi for local network name resolution.