Reliable mDNS with Arch/Manjaro

nerves
linux

#1

Looking for some help having my laptop reliably use mDNS to resolve local nerves projects connected over usb. For this example I am using a Raspberry Pi Zero W, System76 Galago Pro, Majaro Linux (consider this the same as Arch), and a new nerves project burned to the sd card.

Packages installed:

  • avahi
  • nss-mdns

Services disabled and stopped:

  • systemd-resolvd

Services enabled and started:

  • avahi-daemon

Relevant line in /etc/nsswitch.conf:

hosts: files mymachines mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns mdns4 myhostname

When I plug the usb cable in I manually edit the connection and switch it to Local-Link Only. The connection is established and the following lines are shown when viewing the status of the avahi-daemon.service:

Mar 08 08:13:26 schmerz avahi-daemon[558]: Withdrawing address record for fe80::1bd2:2363:f3f0:10fa on enp0s20f0u7.
Mar 08 08:13:26 schmerz avahi-daemon[558]: Leaving mDNS multicast group on interface enp0s20f0u7.IPv6 with address fe80::1bd2:2363:f3f0:10fa.
Mar 08 08:13:26 schmerz avahi-daemon[558]: Interface enp0s20f0u7.IPv6 no longer relevant for mDNS.
Mar 08 08:13:26 schmerz avahi-daemon[558]: Joining mDNS multicast group on interface enp0s20f0u7.IPv6 with address fe80::1bd2:2363:f3f0:10fa.
Mar 08 08:13:26 schmerz avahi-daemon[558]: New relevant interface enp0s20f0u7.IPv6 for mDNS.
Mar 08 08:13:26 schmerz avahi-daemon[558]: Registering new address record for fe80::1bd2:2363:f3f0:10fa on enp0s20f0u7.*.
Mar 08 08:13:32 schmerz avahi-daemon[558]: Joining mDNS multicast group on interface enp0s20f0u7.IPv4 with address 169.254.158.42.
Mar 08 08:13:32 schmerz avahi-daemon[558]: New relevant interface enp0s20f0u7.IPv4 for mDNS.

Sometimes I can ping nerves.local and have it resolve, ssh was tested to work as well :slight_smile: However this is not consistent, and I can’t tell why. Any help would be great, I spent an absurd amount of time dealing with this issue across multiple distros. Majaro is the first to actually work at all, so I am hopeful.

Nerves config, stock generated config:

config :nerves_init_gadget,
  ifname: "usb0",
  address_method: :dhcpd,
  mdns_domain: "nerves.local",
  node_name: node_name,
  node_host: :mdns_domain

Thanks!!


#2

The IP address of the Nerves device will be the same even after reboots. It is computed off the serial number of the Raspberry Pi, so if you have multiple Pi’s connected to your computer, they’ll all have different addresses. Once you have the address, though, you could add it to the hosts file to avoid mDNS altogether.

There might be another problem. I’ve been noticing lately that Raspberry Pi Zeros don’t connect reliably to Linux computers and it’s everything USB. This seems to correlate with a Linux update from https://github.com/raspberrypi/linux, but I don’t understand it. My MacBook Pro does not have this issue at all.

Frank


#3

@frigidcode I second the problem that Frank described. It effects my machine as well (i run Arch btw :stuck_out_tongue:)

A way to test is to do the following:

  1. run dmesg -w in one terminal tab
  2. plug rpi in
  3. observe for messages that look like ...failed to set dts...

If that isn’t the case your avahi daemon conf may be incorrect. I can’t remember where the config file is but i had to make some changes to it on Arch to get reliable mdns.


#4

The failed to set dts message is shown in the dmesg output. Also the rpi zero does not have the same IP per boot.


#5

I have been able to connect multiple times after stopping by disabling ModemManager

sudo systemctl stop ModemManager.service

Edit: Spoke too soon, it’s not consistent :frowning:


#6

I added the IP to my hosts file but SSH isn’t working as connection is refused.


#7

There is an issue with the Raspberry Pi Zero’s USB gadget mode being flaky. It’s really hard to determine what the issue is or even hints to provide upstream. I’ve seen some commits to the Raspberry Pi’s Linux github addressing the dwc2 driver (the gadget mode one), but none of them seem to work. I’m tracking their tip 4.19 revision now.

I have a PR that compiles the dwc2 driver as a module instead of building it into the kernel. At the moment, I’m enjoying a long streak of gadget mode working. The tradeoff is that the time for the USB gadget network and serial to come up is longer. I believe that this only changed the timing and things are “working”. Consistently booting is obviously better than booting slowly, so I’m leaning to merging this assuming it continues working.

As for the other issues, if the USB connection isn’t working, then nothing higher level will work. The ModemManager change will fix a bunch of junk characters being sent over the virtual serial port. I’m not sure why the IP address is changing unless you’re getting a link local one. At any rate, I’m hopeful that PR 100 will make things better and then we can get a new system out.