简体   繁体   English

如何从 AWS EC2 实例 ping 到我的本地机器?

[英]How to ping to my local machine from AWS EC2 instance?

I have started an ubuntu instance on AWS EC2我已经在 AWS EC2 上启动了一个 ubuntu 实例

e.g. [ec2-user@ip-XXX-XX-XX-XX ~]$

Inside this instance, I am running a socket program for sending the data to my local system.在这个实例中,我正在运行一个套接字程序来将数据发送到我的本地系统。 The program is running properly, but not able to connect to my local IP.该程序运行正常,但无法连接到我的本地 IP。

I am trying to ping my local system also from AWS ec2 user, but it is also not working.But I am able to ping google(8.8.8.8) .我也在尝试从AWS ec2用户 ping 我的本地系统,但它也无法正常工作。但我能够ping google(8.8.8.8)

e.g. [ec2-user@ip-xxx-xx-xx-xx ~]$ ping xxx.xxx.xx.xx(my local IP)

I have set all security groups(inbound), like All Trafic,All TCP and so on.我已经设置了所有安全组(入站),如所有流量、所有 TCP 等。

Sorry for bad English.抱歉英语不好。

Thank You谢谢你

Your computer (PC) cannot be pinged from an AWS hosted machine无法从 AWS 托管机器 ping 您的计算机 (PC)

This is probably because the VM on your computer is using NAT outbound to talk to the LAN, which goes to an Internet router, which sends the packets to AWS The reverse route (inbound to your PC) does not exist so starting a ping echo request from a AWS machine will not work这可能是因为您计算机上的 VM 正在使用 NAT 出站与 LAN 通信,LAN 连接到 Internet 路由器,该路由器将数据包发送到 AWS 反向路由(入站到您的 PC)不存在,因此启动 ping 回显请求从 AWS 机器将无法工作

It is possible to get around this by opening a pass through on your router but generally this is not a great idea可以通过在路由器上打开一个通道来解决这个问题,但通常这不是一个好主意

However if you want to make a socket connection securely there is a way但是,如果您想安全地建立套接字连接,则有一种方法

First, start a ssh session with remote port forwarding.首先,使用远程端口转发启动 ssh 会话。 In the Linux ssh client this is using the -R option.在 Linux ssh 客户端中,这是使用 -R 选项。

For example, if your local system is running a listening service on port 80 and your remote system has the address of 54.10.10.10 then例如,如果您的本地系统在端口 80 上运行侦听服务,而您的远程系统的地址为 54.10.10.10,则

ssh -R 8080:localhost:80 ec2-user@54.10.10.10

Will establish a circuit such that connections to the "localhost" on the remote ec2 server on port 8080 are connected to the "localhost" on port 80 of your local machine将建立一个电路,以便连接到远程 ec2 服务器上 8080 端口上的“localhost”连接到本地机器的 80 端口上的“localhost”

If you are not using a ssh cli program, most ssh clients have a facility of this sort.如果您没有使用 ssh cli 程序,大多数 ssh 客户端都具有这种功能。

Note that it is necessary to keep the ssh session open to be able to use the connections请注意,必须保持 ssh 会话打开才能使用连接

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

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