Ubuntu 18.04:ssh 不允许我登录小型家庭网络上的另一台计算机

Ubuntu 18.04:ssh 不允许我登录小型家庭网络上的另一台计算机

我家里有两台笔记本电脑和一台台式电脑,都运行 Ubuntu 18.04。每台电脑上都安装了 Openssh-server 和 ssh。但是,我无法从其中一台电脑登录到另一台电脑;例如,在主机名为 Machine-1 的电脑上,尝试使用以下命令登录 Machine-2:

ssh <mylogin-name>@Machine-2 

失败。我尝试编辑/etc/hosts中的 和 文件/etc/ssh。我认为我的问题应该很容易解决;非常感谢您的帮助。

$ ssh -v saul@NullA-3
OpenSSH_7.6p1 Ubuntu-4ubuntu0.1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Connecting to nulla-3 [192.168.1.5] port 22.
debug1: connect to address 192.168.1.5 port 22: No route to host
ssh: connect to host nulla-3 port 22: No route to host

答案1

尝试登录不存在的 IP 地址,

$ ssh [email protected]
ssh: connect to host 192.168.1.11 port 22: No route to host

尝试使用现有 IP 地址登录我的 [本地] 服务器,

$ ssh [email protected]
[email protected]'s password: 

No route to host表示 IP 地址错误或 LAN 出现问题,例如路由器不工作或配置不正确。


您可以安装并使用arp-scan扫描连接的 IP 和 MAC 地址,

sudo apt update
sudo apt install arp-scan

sudo arp-scan -lv  # minus ell vee

答案2

问题解决了。命令

ssh username@machine-2

总是能正常工作。我曾愚蠢地尝试让它在机器 2 处于休眠状态时工作——例如,当笔记本电脑关闭时;或者当机器 2 处于睡眠状态时。

我发现这个实用程序nmap对此非常有用;命令

nmap -sn 192.168.1.0-24

提供了有关本地网络的许多有用信息。

答案3

连接到地址 192.168.1.5 端口 22:没有到主机的路由

这似乎是路由器/网络问题。

我建议使用更高级的实用程序,而不是 ping:

mtr 192.168.1.5

我还建议您检查路由器设置,并为两台计算机分配静态 IP。

PS 具体操作步骤取决于路由器型号。我建议检查路由器上的标签,上面通常有型号。

答案4

首先,您应该检查所有计算机是否在同一个网络中。

  • 转到每台计算机,运行终端并输入ifconfig,您将看到每台计算机上的 IP 地址。
  • 您在每台计算机上都连接到同一个网络吗?(同一个 WIFI/电缆?)

使用nmap

If it's not installed:

$ sudo apt install nmap

then

$ nmap -sP 192.168.0.0/24
$ nmap -sP 192.168.1.0/24 
# This command depends on Your network configuration. Check it with `ifconfig`

以下是我的网络上的一个例子:

felixd@docker:~$ ifconfig 
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.15  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::a00:27ff:fe26:bbd1  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:26:bb:d1  txqueuelen 1000  (Ethernet)
        RX packets 908  bytes 1173342 (1.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 678  bytes 50398 (50.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • inet 192.168.10.15 网络掩码 255.255.255.0 广播 192.168.10.255

就我而言,我将使用nmap这种方式,因为我的 IP 地址是 192.168.10.15

$ nmap -sP 192.168.10.15/24 

网络掩码是 255.255.255.0,所以我在 nmap 命令中使用 /24 来检查整个本地网络。

我的输出:

felixd@docker:~$  nmap -sP 192.168.10.15/24 

Starting Nmap 7.60 ( https://nmap.org ) at 2018-12-22 21:24 CET
Nmap scan report for 192.168.10.1
Host is up (0.0019s latency).
Nmap scan report for 192.168.10.2
Host is up (0.0021s latency).
.
.  Lot of other devices ;)
.
Host is up (0.049s latency).
Nmap scan report for 192.168.10.82
Host is up (0.0014s latency).
Nmap done: 256 IP addresses (12 hosts up) scanned in 15.13 seconds

现在我知道 192.168.10.82 是我的 Ubuntu 服务器,我可以尝试登录到这台机器:

$ ping 192.168.10.82 ;) to check if it's alive ;)

然后

$ ssh [email protected]

祝你好运。干杯,Paweł。

相关内容