简体   繁体   English

通过公共互联网连接到树莓派

[英]connect to raspberry pi through public internet

I have a raspberry pi and I have a program which has to run only when I want it from an app. 我有一个覆盆子pi,我有一个程序,只有当我想从应用程序中运行时才能运行。 So, basically need to connect to my raspberry pi from public internet. 所以,基本上需要从公共互联网连接到我的覆盆子pi。 Not sure about this, I think I need to make my raspberry pi ssh from public internet, ie connect directly through some IP address. 不确定这一点,我想我需要从公共互联网上制作我的覆盆子pi ssh,即直接通过某个IP地址连接。

How can I do this? 我怎样才能做到这一点? I am trying to connect to my linux system through simple ssh and its not working. 我试图通过简单的ssh连接到我的linux系统,它无法正常工作。 Any guides and pointers to go about? 有任何指南和指针吗?

Thanks 谢谢

First, you should make sure that the ssh daemon is installed properly on your RP. 首先,您应该确保在RP上正确安装了ssh守护程序。 You can install it with 你可以安装它

sudo apt-get update && apt-get install ssh

Next, you should try to connect to your SSH server locally, that means, open up a terminal directly on your RP and try to connect to your locally running SSH server: 接下来,您应该尝试在本地连接到SSH服务器,这意味着,直接在RP上打开终端并尝试连接到本地运行的SSH服务器:

ssh root@localhost

Or even better, use the current IP address of the RP instead of localhost. 或者甚至更好,使用RP的当前IP地址而不是localhost。 If you can connect, everything works on this side. 如果你可以连接,一切都在这方面工作。 Now you can try to connect to your RP from another box inside your local network. 现在,您可以尝试从本地网络中的另一个框连接到RP。 It should also work. 它也应该工作。 If it does not, you most probably have a firewall blocking outgoing SSH connections on this box, or your RP itself is blocking incoming connections. 如果没有,您很可能在此框上有防火墙阻止传出SSH连接,或者您的RP本身阻止传入连接。 Usually, it should not block it, unless you configured something like that with iptables, for example. 通常,它不应该阻止它,除非您使用iptables配置类似的东西,例如。

If you can connect within your LAN, you can take it one step further. 如果您可以在局域网内连接,则可以更进一步。 You need to configure your router's firewall to forward the ports needed for SSH to your RP. 您需要配置路由器的防火墙,以将SSH所需的端口转发到RP。 Alternatively, many routers have offer the ability to put hosts into a so-called DMZ. 或者,许多路由器提供将主机置于所谓的DMZ中的能力。 This is quite useful for testing, as it gives you unrestricted access from the internet. 这对测试非常有用,因为它可以让您从互联网上无限制地访问。

Next, you need to find out your public IP address on the WAN side. 接下来,您需要在WAN端找到您的公共IP地址。 There are many sites like this that show your current external IP address. 有许多网站这样是显示您当前的外部IP地址。 If everything is configured correctly, you should now be able to connect to root@[your external ip] . 如果一切配置正确,您现在应该能够连接到root@[your external ip] It should work from your local network as well as from the internet. 它应该可以在您的本地网络和互联网上运行。 Additionally, you should consider using a dynamic DNS service client either on your RP or in your router, so you can connect to a static hostname instead of changing dynamic IP addresses. 此外,您应该考虑在RP或路由器上使用动态DNS服务客户端,这样您就可以连接到静态主机名而不是更改动态IP地址。

maybe the ip address of your pi changes because of DHCP. 也许你的pi的ip地址因DHCP而改变。 If this is your problem, you may read this: http://developer-blog.net/en/programming/get-your-external-ip-address/#more-1267 如果这是您的问题,您可以阅读: http//developer-blog.net/en/programming/get-your-external-ip-address/#more-1267

Another possibility is that your router blocks needed ports. 另一种可能是您的路由器阻塞了所需的端口。 For SSH port 22 should be open. 对于SSH端口22应该是打开的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM