ssh-ing in to ubuntu comp by hostname suddenly stopped working (`Could not resolve hostname [ubuntu_comp_hostname]: Name or service not known`)
(see EDIT added to end, bout avahi stuff)
It just does this:
> ssh -v [ubuntu_comp_hostname].local
=>
OpenSSH_8.2p1, LibreSSL 3.0.2
debug1: Reading configuration data /home/o1/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
ssh: Could not resolve hostname [ubuntu_comp_hostname].local: Name or service not known
(Like, this didn't even start after rebooting or waking one of the computers from sleep or anything. It was working, I got up for a few minutes to get some tea, came back, and it was suddenly no longer working.)
I can still ssh in by using the IP of the ubuntu computer
(
ie, in place of [ubuntu_comp_hostname].local
)
-- it's the IP I get by running this command: ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'
(I copied it from somewhere I forget and have had it hanging around in an alias for a while)
)
I can still ssh in to the other computer from the ubuntu computer, by using the hostname of the other computer.
And very confusingly to me,
I'm running a synergy client on the ubuntu computer,
and the client and server connect by using the two computers' hostnames,
and that still works just fine
(I just killed and restarted synergy on both computers to check, and yup, it reconnected just fine.)
I have no clue: where do I start on trying to debug this?
EDIT (copied up from my comments below):
I just tried ps -eo cmd|grep avahi
, and found (besides avahi-daemon: chroot helper
)
this:avahi-daemon: running [ubuntu_comp_hostname-2.local]
.
(ie, there's this extra -2
there on the end of the hostname for no apparent reason).
((Trying to connect with ssh ubuntu_comp_hostname-2.local
does work.))
I'm extremely ignorant on all this stuff, but I'm guessing that...
-
avahi crashed or restarted or something?
-
And then it tried to run as plain
[ubuntu_comp_hostname.local]
,
but that was still hanging around in a defunct state or something,
so it automatically appended a-2
to the end of the actual hostname?
And yeah, sudo service avahi-daemon restart
worked
-- ie, there's no more -2
,
and everything connects by hostname.local as expected again
(even though I removed the ~/.ssh/config
file with I added as a workaround as recommended (didn't have any such file before))
I'm still wondering what caused the problem in the first place, though,
and how to prevent it from happening again
(or at least get it to automatically fix itself?)
EDIT
The cause of the problem
As for why the server name is not correctly resolved to the IP, I wouldn't know, this requires diagnosis. Please perform the following actions:
- Post the contents of
/etc/hosts
,/etc/resolv.conf
/etc/nsswitch.conf
. - Post the contents of
${HOME}/.ssh/config
. Try removing (for privacy issues) as little as possible. - Rename
config
and tryssh
-ing. Post the outcome. - Try connecting not using
.local
, using both the IP and server name. Post the outcome. - Specify what is your network configuration... 1) Where are the connecting machines located? 2) Which is the DNS?
- Try
host hostname_of_ubuntu_comp
. Post the outcome. - Further debug with
ssh -vvv ...
. Post the outcome. - Post the output of
netstat -plunt | grep 22
in the server. - Post the output of
systemctl status ssh
in the server.
Related:
- What does ".local" do?
- https://serverfault.com/questions/831747/why-is-ssh-not-resolving-this-hostname/831769
- https://stackoverflow.com/questions/20252294/ssh-could-not-resolve-hostname-hostname-nodename-nor-servname-provided-or-n
- https://docstore.mik.ua/orelly/networking_2ndEd/ssh/ch12_01.htm
A way to make it work
You say you can ssh into the server using the IP. Let's say the command that you use to connect is
$ ssh [email protected]
Then, make sure in ${HOME}/.ssh/config
in your client you have the following lines (the last two are convenient, but optional)
Host server_user
HostName 10.20.10.10
User user_at_server
ServerAliveInterval 30
ForwardX11 yes
Then make sure the right attributes are assigned:
$ chmod 0664 ${HOME}/.ssh/config
$ chmod 0700 ${HOME}/.ssh
You should now be able to
$ ssh server_user