You are not logged in.

#1 2018-06-15 12:53:00

ss
Member
Registered: 2018-06-04
Posts: 89

ssh can't resolve hostname : Name or service not known

I have several computers with Arch installed. They are all in a local network, with dynamic IPs. Normally, if I install avahi and have avahi-daemon.service running, they can ssh each other with hostname instead of IP address. But there is one computer can't get access with hostname, although to my best knowledge it has exactly the same setup.

cat /etc/hosts
127.0.0.1 localhost.localdomain localhost xxx 

Then if I ssh to it from other computers, hostname is unknown

ssh user@xxx
ssh: Could not resolve hostname xxx: Name or service not known

If I ping xxx, same thing.
But ssh and ping with IP address to this computer do work.

What could be the problem and what else should I look at?

Offline

#2 2018-06-15 13:01:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: ssh can't resolve hostname : Name or service not known

I've never ran a LAN to know if this would be the cause but the /etc/hosts line should be:

127.0.0.1 xxx.localdomain localhost xxx

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2018-06-15 13:10:58

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

I tried your suggestion, but it didn't help.
In fact, my other computers which are working also have the same format of /etc/hosts, so I assume it was probably not the cause ...
Thank you all the same.

Offline

#4 2018-06-15 14:06:47

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,601

Re: ssh can't resolve hostname : Name or service not known

Normally you should just use
127.0.0.1    localhost

for 127.0.1.1 you can use FQDN
127.0.1.1    localhost.localdomain    localhost
edit:
so a translate would be
127.0.1.1 mymachine.domain     mymachine
/edit

Though this may/will work on 127.0.0.1 too

You shouldn't use the machine name after the localhost

See man hosts

Last edited by qinohe (2018-06-15 14:12:23)

Offline

#5 2018-06-15 14:11:56

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,848

Re: ssh can't resolve hostname : Name or service not known

What is "xxx"? avahi by default only handles foo.local, see https://wiki.archlinux.org/index.php/Av … resolution
Ensure the daemon is actually running, port 5353 on that system is listening and in case you tampered w/ the avahi config (see above), please paste your alterations.

Online

#6 2018-06-15 15:05:38

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

seth wrote:

What is "xxx"? avahi by default only handles foo.local, see https://wiki.archlinux.org/index.php/Av … resolution
Ensure the daemon is actually running, port 5353 on that system is listening and in case you tampered w/ the avahi config (see above), please paste your alterations.

xxx was myhostname without '.local', as the output of cat /etc/hostname.
Now I added .local to it, and /etc/hosts looks like

127.0.0.1       localhost       xxx.local

I am not aware of having ever touched the avahi config. Here is my /etc/avahi/avahi-daemon.conf

[server]
#host-name=foo
#domain-name=local
#browse-domains=0pointer.de, zeroconf.org
use-ipv4=yes
use-ipv6=yes
#allow-interfaces=eth0
#deny-interfaces=eth1
#check-response-ttl=no
#use-iff-running=no
#enable-dbus=yes
#disallow-other-stacks=no
#allow-point-to-point=no
#cache-entries-max=4096
#clients-max=4096
#objects-per-client-max=1024
#entries-per-entry-group-max=32
ratelimit-interval-usec=1000000
ratelimit-burst=1000

[wide-area]
enable-wide-area=yes

[publish]
#disable-publishing=no
#disable-user-service-publishing=no
#add-service-cookie=no
#publish-addresses=yes
publish-hinfo=no
publish-workstation=no
#publish-domain=yes
#publish-dns-servers=192.168.50.1, 192.168.50.2
#publish-resolv-conf-dns-servers=yes
#publish-aaaa-on-ipv4=yes
#publish-a-on-ipv6=no

[reflector]
#enable-reflector=no
#reflect-ipv=no

[rlimits]
#rlimit-as=
#rlimit-core=0
#rlimit-data=8388608
#rlimit-fsize=0
#rlimit-nofile=768
#rlimit-stack=8388608
#rlimit-nproc=3

I can verify avahi-daemon.service is running

systemctl status avahi-daemon.service 
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
   Loaded: loaded (/usr/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2018-06-15 16:35:51 CEST; 18min ago
 Main PID: 361 (avahi-daemon)
   Status: "avahi-daemon 0.7 starting up."
    Tasks: 2 (limit: 4915)
   Memory: 1.8M
   CGroup: /system.slice/avahi-daemon.service
           ├─361 avahi-daemon: running [xxx.local]
           └─375 avahi-daemon: chroot helper

But how can I check if the computer is listening to port 5353?

Offline

#7 2018-06-15 15:08:34

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

OK, now I find out another thing. I have a fritzbox router, every computer in the local network seem to be actually named xyz.fritz.box.
If I ssh user@xxx.fritz.box to this problematic computer, it works.
What I don't understand is that for other computers, i don't have to append fritz.box to the hostname.

Offline

#8 2018-06-15 17:59:30

circleface
Member
Registered: 2012-05-26
Posts: 639

Re: ssh can't resolve hostname : Name or service not known

You could try adding

domain fritz.box

to /etc/resolv.conf.  That way, you can refer to your machines as xxx or xyz without the full domain name.

Offline

#9 2018-06-15 18:06:39

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,848

Re: ssh can't resolve hostname : Name or service not known

You can check the port status with eg. nmap, however we can infer that it's open.
The .local tld should not be required, but you should (only) be able to address the IP under this tld, ie. "ping xxx.local" should work.
The "xyz.fritz.box" will most likely work w/o avahi, the systems report their hostname via dhcp and the DNS(masq, I think) server of the fritzbox will resolve them (iow: w/ a capable router, you don't need avahi at all)

Reg. the avahi situation:
- do you set the static hostname? (see "hostnamectl")
- what if you announce the hostname via the "#host-name=foo" key in avahi-daemon.conf?

Online

#10 2018-06-15 21:13:39

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

seth wrote:

You can check the port status with eg. nmap, however we can infer that it's open.
The .local tld should not be required, but you should (only) be able to address the IP under this tld, ie. "ping xxx.local" should work.
The "xyz.fritz.box" will most likely work w/o avahi, the systems report their hostname via dhcp and the DNS(masq, I think) server of the fritzbox will resolve them (iow: w/ a capable router, you don't need avahi at all)

ping xxx.local doesn't work.
I would like to get it work with avahi, not with the help with the router, which actually belongs to the ISP company.

Reg. the avahi situation:
- do you set the static hostname? (see "hostnamectl")
- what if you announce the hostname via the "#host-name=foo" key in avahi-daemon.conf?

hostnamectl shows it has static hostname: xxx, which is the same as in /etc/hostname

Now my avahi-daemon.conf has the line host-name=xxx, then restart avahi-daemon.service, or even the computer, nothing seems to change.

I also checked all the points you mentioned in another working computer, but could not identify any real difference.

Offline

#11 2018-06-15 21:17:55

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

circleface wrote:

You could try adding

domain fritz.box

to /etc/resolv.conf.  That way, you can refer to your machines as xxx or xyz without the full domain name.

Here is another surprise to me. Although I don't remember ever touching /etc/resolv.conf, but it already contains the line

domain fritz.box

Then, on another computer which I can access without fritz.box, there isn't this line in /etc/resolv.conf ...

Offline

#12 2018-06-16 20:03:04

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,848

Re: ssh can't resolve hostname : Name or service not known

Firewall? Let's see whether the port does really respond:

nmap -p 5353 <IP of "xxx" here>

Online

#13 2018-06-17 00:32:59

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

seth wrote:

Firewall? Let's see whether the port does really respond:

nmap -p 5353 <IP of "xxx" here>

Here is the output

Starting Nmap 7.70 ( https://nmap.org ) at 2018-06-17 02:28 CEST
Nmap scan report for xxx.fritz.box (192.168.xxx.xx)
Host is up (0.0075s latency).

PORT     STATE  SERVICE
5353/tcp closed mdns

Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds

Offline

#14 2018-06-17 00:43:57

ss
Member
Registered: 2018-06-04
Posts: 89

Re: ssh can't resolve hostname : Name or service not known

Now I discovered that the problem was not the server, but the computer i am using to ssh the server!

I tried it on another two Arch computers and they were able to ssh the server with its hostname directly. In fact, all computers, except the one I am actually using on a daily basis, can ssh each other with hostname...

On my daily computer, it only works with xxx.fritz.box

What to look for next?

Offline

#15 2018-06-17 05:46:53

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,848

Re: ssh can't resolve hostname : Name or service not known

The port is closed, either avahi isn't running or it's faulty or you're blocking the port w/ some iptables rule (at that time)
As for the "it's rather an DNS query issue", compare the /etc/nsswitch.conf of the systems (ie. the one that fails to resolve the domain compared to those succeeding)
Also compare the nmap results among the machines.

Online

Board footer

Powered by FluxBB