Cannot use Rclone with SFTP host using mDNS

What is the problem you are having with rclone?

I have a local server that uses mDNS to publish its hostname as han.local. After I configure rclone to use it (config below), and run rclone ls Han:/, I get:

~ • rclone ls Han:/
2023/02/28 22:41:55 Failed to create file system for "Han:/": NewFs: couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving

Regular old SSH (and SFTP) works fine:

~ • ssh han.local
Linux han 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l

The programs included with the Debian GNU/Linux system are free software;
[etc]

Avahi resolves it fine:

~ • avahi-resolve --name -4 han.local
han.local	192.168.1.101

Ping resolves it fine:

~ • ping han.local
PING han.local (192.168.1.101) 56(84) bytes of data.
64 bytes from han (192.168.1.101): icmp_seq=1 ttl=64 time=1.30 ms

Dig is not happy, but that's by design (note the warning):

~ • dig @127.0.0.53 han.local

; <<>> DiG 9.18.4-2ubuntu2.1-Ubuntu <<>> @127.0.0.53 han.local
; (1 server found)
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 43167
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;han.local.			IN	A

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Tue Feb 28 23:21:38 AWST 2023
;; MSG SIZE  rcvd: 38

/etc/resolv.conf points to systemd's stub resolver:

~ • file /etc/resolv.conf 
/etc/resolv.conf: symbolic link to /run/systemd/resolve/stub-resolv.conf

The non-comment contents are:

nameserver 127.0.0.53
options edns0 trust-ad
search .

Side question: how does rclone "know" to use 127.0.0.53 but without seeming to use the system resolver?

Run the command 'rclone version' and share the full output of the command.

~ • rclone version
rclone v1.61.1
- os/version: ubuntu 22.10 (64 bit)
- os/kernel: 5.19.0-31-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.19.4
- go/linking: static
- go/tags: none

Downloaded using the curl installation instructions. It is installed to a user directory, not /usr/bin.

Which cloud storage system are you using? (eg Google Drive)

For this question, SFTP. Rclone on this machine works with Nextcloud, Drive and Backblaze B2 as well, though.

The command you were trying to run (eg rclone copy /tmp remote:tmp)

~ • rclone ls Han:/
2023/02/28 22:41:55 Failed to create file system for "Han:/": NewFs: couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving

The rclone config contents with secrets removed.

[Nextcloud]
type = webdav
url = https://[redacted]/
vendor = nextcloud
user = [redacted]
pass = [redacted]

[Drive]
type = drive
client_id = [redacted]
client_secret = [redacted]
scope = drive
token = [redacted]
team_drive = 

[Backblaze]
type = b2
account = [redacted]
key = [redacted]

[Han]
type = sftp
host = han.local
user = jason
pubkey_file = ~/.ssh/id_rsa.pub
key_use_agent = true

A log from the command with the -vv flag

2023/02/28 23:35:31 DEBUG : rclone: Version "v1.61.1" starting with parameters ["rclone" "-vv" "ls" "Han:/"]
2023/02/28 23:35:31 DEBUG : Creating backend with remote "Han:/"
2023/02/28 23:35:31 DEBUG : Using config file from "/home/jason/.config/rclone/rclone.conf"
2023/02/28 23:35:31 DEBUG : pacer: low level retry 1/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:31 DEBUG : pacer: Rate limited, increasing sleep to 200ms
2023/02/28 23:35:31 DEBUG : pacer: low level retry 2/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:31 DEBUG : pacer: Rate limited, increasing sleep to 400ms
2023/02/28 23:35:31 DEBUG : pacer: low level retry 3/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:31 DEBUG : pacer: Rate limited, increasing sleep to 800ms
2023/02/28 23:35:32 DEBUG : pacer: low level retry 4/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:32 DEBUG : pacer: Rate limited, increasing sleep to 1.6s
2023/02/28 23:35:33 DEBUG : pacer: low level retry 5/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:33 DEBUG : pacer: Rate limited, increasing sleep to 2s
2023/02/28 23:35:34 DEBUG : pacer: low level retry 6/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:36 DEBUG : pacer: low level retry 7/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:38 DEBUG : pacer: low level retry 8/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:40 DEBUG : pacer: low level retry 9/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:42 DEBUG : pacer: low level retry 10/10 (error couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving)
2023/02/28 23:35:42 Failed to create file system for "Han:/": NewFs: couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving

Other information

Running this on Ubuntu 22.10.

I had a good search for this issue, but surprisingly, did not find a lot of information about rclone interacting with mDNS. Probably because it's designed for cloud services, but in this case, I want to use it to synchronise files from a cloud service to a local SFTP server.

I also spent a... long... time trying to switch from Avahi to systemd's own mDNS resolver, in case that helped. It was beyond me. So I have not done that test yet.

I think this is described in this go issue affected/package: net · Issue #57506 · golang/go · GitHub

There are some things to try in that thread. The fix seemed to be having a correct search directive in /etc/resolv.conf.

Note that if you want to try any of the cgo resolvers, you'll have to compile rclone yourself as the version distributed does not support cgo.

It looks in /etc/resolv.conf I believe.

PS probably worth trying the latest beta also which is compiled with go1.20

That seems to be about local DNS search domains, but I believe avahi doesn't use that (and indeed, would usually conflict with it).

When I use the debugging commands in that issue, I get:

~ • GODEBUG=netdns=cgo+2 rclone ls Han:/
go package net: confVal.netCgo = true  netGo = true
go package net: built with netgo build tag; using Go's DNS resolver
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
2023/03/01 07:51:19 Failed to create file system for "Han:/": NewFs: couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving
~ • GODEBUG=netdns=go+2 rclone ls Han:/
go package net: confVal.netCgo = false  netGo = true
go package net: built with netgo build tag; using Go's DNS resolver
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
go package net: hostLookupOrder(han.local) = files,dns
2023/03/01 07:51:37 Failed to create file system for "Han:/": NewFs: couldn't connect SSH: dial tcp: lookup han.local on 127.0.0.53:53: server misbehaving

(Looks like it's using Go's DNS resolver either way.)

Compare this with /etc/nsswitch.conf, where the hosts line is:

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

Try compiling rclone yourself then the cgo resolver will work. (It's the default)

Yes, this worked. Thanks for the pointers.

Any reason not to use the system resolver in the first place though? Or to not support mDNS during resolution?

Great

rclone needs to be compiled with cgo support to support the system resolver. I don't want to compile rclone with cgo by default for linux as it will mean I need to make different versions for all the different libcs whereas at the moment one binary runs on all Linuxes.

I think this is probably a go runtime bug. I think this is the relevant issue net: pure Go resolver(netdns) can not resolve hostname.local · Issue #35067 · golang/go · GitHub which seems to say the Go team won't fix the problem.

There are other reasons to make a cgo build of rclone and there is an issue about that Provide official CGO/libfuse build of rclone for Linux · Issue #5090 · rclone/rclone · GitHub so putting some effort in to that is probably the solution. Can you add a note to that issue about mDNS failures with netgo as another reason we should do that issue!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.