Linux ssh:无法解析主机名 [主机名]:提供的节点名或服务名,或未知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20252294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:28:41  来源:igfitidea点击:

ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known

linuxnetworkingsshdns

提问by qaxf6auux

I am trying to set up a VPN with a Raspberry Pi, and the first step is gaining the ability to sshinto the device from outside my local network. For whatever reason, this is proving to be impossible and I haven't the slightest clue why. When I try to sshinto my server with user@hostname, I get the error:

我正在尝试使用 Raspberry Pi 设置 VPN,第一步是获得ssh从本地网络外部进入设备的能力。无论出于何种原因,这被证明是不可能的,我没有丝毫线索。当我尝试使用ssh进入我的服务器时user@hostname,出现错误:

ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known 

However, I can log into the server with,

但是,我可以登录到服务器,

ssh user@[local IP]

The server is a Raspberry Pi Model B running the latest distribution of Raspbian and the machine I am trying to connect to it with is a Macbook Pro running Mavericks. sshwas enabled on the Raspberry Pi when I set up Raspbian.

该服务器是运行 Raspbian 最新发行版的 Raspberry Pi Model B,我尝试连接到它的机器是运行 Mavericks 的 Macbook Pro。ssh当我设置 Raspbian 时,已在 Raspberry Pi 上启用。

I have perused Stack Overflow for hours trying to see if anyone else had this problem and I have not found anything. Every sshtutorial I find says that I should just be able to set it up on the remote machine and log in from anywhere using a hostname, and I have never had success with that.

我已经仔细阅读了 Stack Overflow 几个小时,试图看看其他人是否有这个问题,但我没有发现任何问题。ssh我找到的每个教程都说我应该能够在远程机器上设置它并使用主机名从任何地方登录,但我从来没有成功过。

采纳答案by ekwaters

Recently I came across the same issue. I was able to ssh to my pi on my network, but not from outside my home network.

最近我遇到了同样的问题。我能够在我的网络上 ssh 到我的 pi,但不能从我的家庭网络之外。

I had already:

我已经:

  • installed and tested ssh on my home network.
  • Set a static IP for my pi.
  • Set up a Dynamic DNS service and installed the software on my pi. I referenced these instructionsfor setting up the static ip, and there are many more instructional resources out there.
  • 在我的家庭网络上安装并测试了 ssh。
  • 为我的 pi 设置一个静态 IP。
  • 设置动态 DNS 服务并在我的 pi 上安装该软件。我引用这些指令用于设置静态IP,并有更多的教学资源在那里。

Also, I set up port forward on my router for hosting a web site and I had even port forward port 22 to my pi's static IP for ssh, but I left the field blank where you specify the application you are performing the port forwarding for on the router. Anyway, I added 'ssh' into this field and, VOILA! A working ssh connection from anywhere to my pi.

此外,我在我的路由器上设置了端口转发以托管网站,我什至将端口转发端口 22 端口转发到 ssh 的 pi 静态 IP,但我将字段留空,您指定要为其执行端口转发的应用程序路由器。无论如何,我在这个字段中添加了“ssh”,瞧!从任何地方到我的 pi 的有效 ssh 连接。

I'll write out my router's port forwarding settings.

我会写出我的路由器的端口转发设置。

(ApplicationTextField)_ssh     (external port)_22     (Internal Port)_22     (Protocal)_Both     (To IP Address)_192.168.1.###     (Enabled)_checkBox

(ApplicationTextField)_ssh(外部端口)_22(内部端口)_22(协议)_Both(到 IP 地址)_192.168.1.###(启用)_checkBox

Port forwarding settings can be different for different routers though, so look up directions for your router.

但是,不同路由器的端口转发设置可能不同,因此请查看路由器的方向。

Now, when I am outside of my home network I connect to my pi by typing:

现在,当我在家庭网络之外时,我通过键入以下内容连接到我的 pi:

ssh pi@[hostname]

ssh pi@[主机名]

Then I am able to input my password and connect.

然后我就可以输入我的密码并连接了。

回答by grebneke

If you need access to your VPN from anywhere in the world you need to register a domain name and have it point to the public ip address of your VPN/network gateway. You could also use a Dynamic DNS service to connect a hostname to your public ip.

如果您需要从世界任何地方访问您的 VPN,您需要注册一个域名并将其指向您的 VPN/网络网关的公共 IP 地址。您还可以使用动态 DNS 服务将主机名连接到您的公共 IP。

If you only need to ssh from your Mac to your Raspberry inside your local network, do this: On your Mac, edit /etc/hosts. Assuming the Raspberry has hostname "berry" and ip "172.16.0.100", add one line:

如果您只需要从 Mac ssh 到本地网络中的Raspberry ,请执行以下操作:在 Mac 上,编辑/etc/hosts. 假设 Raspberry 具有主机名“berry”和 IP“172.16.0.100”,添加一行:

# ip           hostname
172.16.0.100   berry

Now: ssh user@berryshould work.

现在:ssh user@berry应该工作。

回答by tokhi

I had the same issue connecting to a remote machine. but I managed to login as below:

我在连接到远程机器时遇到了同样的问题。但我设法登录如下:

ssh -p 22 myName@hostname

or:

或者:

ssh -l myName -p 22 hostname

回答by tokhi

I had the same problem: The address shown in Preferences -> Sharing -> Remote Login didn't work and I got a '... nodename nor servname provided, or not known'. However, when I manually edited the settings (in Preferences -> Sharing -> Remote Login -> edit) and enabled "Use dynamic global hostname", it suddenly worked.

我遇到了同样的问题:首选项 -> 共享 -> 远程登录中显示的地址不起作用,我得到一个“... nodename 或 servname 提供,或未知”。但是,当我手动编辑设置(在首选项 -> 共享 -> 远程登录 -> 编辑中)并启用“使用动态全局主机名”时,它突然起作用了。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by horcle_buzz

I had the same issue, which I was able to resolve by adding a .local to the host name, ala ssh [email protected]

我遇到了同样的问题,我可以通过向主机名添加 .local 来解决这个问题,ala ssh [email protected]

回答by horcle_buzz

Try this, considering your allowed ports. Store your .pemfile in your Documentsfolder for instance.

试试这个,考虑你允许的端口。例如.pem,将您的Documents文件存储在您的文件夹中。

To gain access to it now all you have to do is cd [directory], which moves you to the directory of the allotted file. You can first type ls, to list the directory contents you are currently in:

现在要访问它,您所要做的就是cd [directory]将您移动到分配文件的目录。您可以先输入ls, 以列出您当前所在的目录内容:

ls
cd /Documents
chmod 400 mycertificate.pem
ssh -i "mycertificate.pem" [email protected] -p 80

回答by Monkpit

This was happening to me when trying to access Github. The problem is that I was in the habit of doing:

我在尝试访问 Github 时发生了这种情况。问题是我习惯于这样做:

git remote add <xyz> ssh:\\[email protected]......

git remote add <xyz> ssh:\\[email protected]......

But, if you are having this error from the question, removing ssh:\\may resolve the issue. It solved it for me!

但是,如果您在问题中遇到此错误,则删除ssh:\\可能会解决问题。它为我解决了!

Note that you will have to do a git remote remove <xyz>and re-add the remote url without ssh:\\.

请注意,您必须执行 agit remote remove <xyz>并重新添加不带ssh:\\.

回答by Mo Bitar

If you're on Mac, restarting the DNS responder fixed the issue for me.

如果您使用的是 Mac,则重新启动 DNS 响应程序为我解决了该问题。

sudo killall -HUP mDNSResponder

回答by karthik vee

If your command is:

如果您的命令是:

$ ssh -p 1122  path/to/pemfile user@[hostip/hostname]

You will also face the same error

你也会面临同样的错误

ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known

when you miss the option -i /path/to/pemfileof ssh

当您错过-i /path/to/pemfilessh选项时

So Command should be:

所以命令应该是:

$ ssh -p 1122 -i path/to/pemfile user@[hostip/hostname]

回答by mythicalcoder

I needed to connect to remote Amazon server

我需要连接到远程亚马逊服务器

ssh -i ~/.ssh/test.pem -fN -L 5555:localhost:5678 [email protected]

ssh -i ~/.ssh/test.pem -fN -L 5555:localhost:5678 [email protected]

I was getting the following error.

我收到以下错误。

ssh: Could not resolve hostname <hostname.com>: nodename nor servname provided, or not known

ssh: Could not resolve hostname <hostname.com>: nodename nor servname provided, or not known

Solution For Mac OSX

Mac OSX 解决方案

Pinging the host resolved the issue. I am using Mac OSX Seirra.

Ping 主机解决了该问题。我正在使用 Mac OSX Seirra。

ping hostname.com

ping hostname.com

Now problem resolved. Able to connect to the server.

现在问题解决了。能够连接到服务器。

Note: I tried this solutionalso. But it didn't work out. Then pingresolved the issue.

注意:我也试过这个解决方案。但它没有成功。然后ping解决了这个问题。