简体   繁体   English

AWS EC2实例 - ssh“连接超时”怀疑iptables

[英]AWS EC2 Instance - ssh “Connection timed out” suspecting iptables

I am new to firewalls. 我是防火墙的新手。 I was playing with iptables on ec2 instance earlier today but now I am unable to connect via ssh - "Connection timed out". 我今天早些时候在ec2实例上玩iptables,但现在我无法通过ssh连接 - “连接超时”。 The console shows the instance is running and the ssh keys are good, ping is successful. 控制台显示实例正在运行且ssh密钥正常,ping成功。 So my conclusion is that I might have disabled/disallowed the ssh port connections while playing with the iptables. 所以我的结论是我可能在玩iptables时禁用/禁止ssh端口连接。

Is there a way to undo the changes without going for a complete re-install ? 有没有办法在不进行完全重新安装的情况下撤消更改?

Note: I don't have access to shell since I cannot ssh 注意:我无法访问shell,因为我不能ssh

A simple reboot from the AWS console should do. 从AWS控制台进行简单的重新启动即可。 Hopefully you didn't enable the iptables service in the instance so that it starts at boot up. 希望你没有在实例中启用iptables服务,以便它在启动时启动。

If you enabled the iptables services you are going to have to create another instance, instance B (hopefully you are using EBS instances). 如果启用了iptables服务,则必须创建另一个实例,即instance B (希望您使用的是EBS实例)。 Also assuming your original instance is instance A : 假设您的原始实例是instance A

  1. Detach the root EBS volume from instance A instance A分离根EBS卷
  2. Attach that EBS volume to instance B as say /dev/xvdf 将该EBS卷附加到instance B如/ dev / xvdf
  3. On instance B run: mkdir -p /mnt/xvdf; mount /dev/xvdf /mnt/xvdf instance B运行: mkdir -p /mnt/xvdf; mount /dev/xvdf /mnt/xvdf mkdir -p /mnt/xvdf; mount /dev/xvdf /mnt/xvdf
  4. Repair your volume mounted on /mnt/xvdf on instance B 修复安装在instance B上的/mnt/xvdf上的卷
  5. Unmount volume from instance B : umount /mnt/xvdf instance B卸载卷: umount /mnt/xvdf
  6. Attach volume back to instance A as root. 以root身份将卷附加回instance A
  7. Restart instance A 重启instance A

If you are using instance-store types of instances you are out of luck. 如果您使用的是instance-store类型的实例,则表示运气不佳。

If you did in fact hose your firewall settings, you could try this: 如果您确实软管防火墙设置,您可以尝试这样做:

Stop the instance. 停止实例。 Start another instance and attach the volume from the original instance to the new instance. 启动另一个实例并将卷从原始实例附加到新实例。 Mount the volume, fix iptables in the mounted volume. 安装卷,将iptables固定在已安装的卷中。 Then detach and reattach the volume to the original instance (eg as /dev/sda1) and restart your original instance. 然后分离并将卷重新连接到原始实例(例如,作为/ dev / sda1)并重新启动原始实例。

Or maybe you made an AMI out of an instance earlier, then launched a new instance from the AMI using a new key, but the new key isn't working? 或者您可能之前从实例中创建了AMI,然后使用新密钥从AMI启动了一个新实例,但是新密钥不起作用? try the key embedded in the original instance when you putty in, that older key may still work. 当你使用putty时,尝试嵌入原始实例中的键,旧键可能仍然有效。

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

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