问题描述
我正在尝试使用 Raspberry Pi 设置 VPN,第一步是获得从本地网络外部ssh
进入设备的能力.无论出于何种原因,这被证明是不可能的,我没有丝毫线索.当我尝试使用 user@hostname
将 ssh
连接到我的服务器时,出现错误:
I am trying to set up a VPN with a Raspberry Pi, and the first step is gaining the ability to ssh
into 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 ssh
into my server with user@hostname
, I get the error:
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]
服务器是运行最新 Raspbian 发行版的 Raspberry Pi Model B,我尝试连接的机器是运行 Mavericks 的 Macbook Pro.当我设置 Raspbian 时,在 Raspberry Pi 上启用了 ssh
.
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. ssh
was enabled on the Raspberry Pi when I set up Raspbian.
我已经仔细阅读了 Stack Overflow 几个小时,试图看看其他人是否有这个问题,但我没有发现任何问题.我发现的每个 ssh
教程都说我应该能够在远程机器上设置它并使用主机名从任何地方登录,但我从来没有成功过.
I have perused Stack Overflow for hours trying to see if anyone else had this problem and I have not found anything. Every ssh
tutorial 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.
推荐答案
最近我遇到了同样的问题.我能够在我的网络上通过 ssh 连接到我的 pi,但不能从我的家庭网络之外.
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 设置一个静态 IP.
- 设置动态 DNS 服务并在我的 pi 上安装该软件.我参考了这些说明进行设置静态 ip,还有更多的教学资源.
- 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 instructions for setting up the static ip, and there are many more instructional resources out there.
此外,我在我的路由器上设置了端口转发以托管网站,我什至将端口转发端口 22 转发到 ssh 的 pi 静态 IP,但我将字段留空,您指定正在执行的应用程序端口在路由器上转发.无论如何,我在这个字段中添加了ssh",瞧!从任何地方到我的 pi 的有效 ssh 连接.
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.
我会写出我路由器的端口转发设置.
I'll write out my router's port forwarding settings.
(ApplicationTextField)_ssh (外部端口)_22 (内部端口)_22 (Protocal)_Both (到IP地址)_192.168.1.### (启用)_checkBox
不过,不同路由器的端口转发设置可能不同,因此请查看路由器的说明.
Port forwarding settings can be different for different routers though, so look up directions for your router.
现在,当我在家庭网络之外时,我通过键入以下内容连接到我的 pi:
Now, when I am outside of my home network I connect to my pi by typing:
ssh pi@[主机名]
然后我就可以输入密码并连接了.
Then I am able to input my password and connect.
这篇关于ssh:无法解析主机名 [主机名]:提供的节点名或服务名,或未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!