aws ec2: how to know public ip from inside ubuntu instance [closed]

梦想与她 提交于 2019-12-06 09:13:47
mootmoot

This question has been ask many time. What you need is Instance Metadata and User Data.

Just do this and refer to the mentioned documentation, you get the public ip address :

curl http://169.254.169.254/latest/meta-data/public-ipv4

You can't really just get the Public IP from the standard linux command

You can check the web console (but apparently its not something you want) or use the aws CLI

[xxx@IP-xxxx ~]# aws ec2 describe-addresses
{
    "Addresses": [
        {
            "Domain": "vpc",
            "InstanceId": "xxxx",
            "NetworkInterfaceId": "eni-xxxx",
            "AssociationId": "eipassoc-xxxx",
            "NetworkInterfaceOwnerId": "xxxx",
            "PublicIp": "THE PUBLIC IP",
            "AllocationId": "eipalloc-xxxx",
            "PrivateIpAddress": "THE INTERNAL IP the instance knows"
        }
    ]
}

The format of your ssh command is sommething like

ssh -i "xxx.pem" ubuntu@ec2-54-252-113-980.ap-souheast-1.compute.amazonaws.com

than the public IP of your instance is 54.252.113.980, the numbers after ubuntu@ec2.

Other command line options for getting the public IP on ubuntu are:

  1. curl ipecho.net/plain ; echo
  2. wget http://ipinfo.io/ip -qO -
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!