2016-07-30 165 views

回答

10

AWS Command-Line Interface (CLI)可用於返回任何信息/所有的Amazon EC2實例,如:

$ aws ec2 describe-instances --instance-ids i-0c9c9b44b --query 'Reservations[*].Instances[*].PublicIpAddress' --output text 

54.232.200.77 

如果您正在尋求來自其執行該命令的EC2實例,信息,那麼當前IP地址可以通過instance metadata service獲得:

$ curl http://169.254.169.254/latest/meta-data/ 

ami-id 
ami-launch-index 
ami-manifest-path 
block-device-mapping/ 
hostname 
iam/ 
instance-action 
instance-id 
instance-type 
local-hostname 
local-ipv4 
mac 
metrics/ 
network/ 
placement/ 
profile 
public-hostname 
public-ipv4 
public-keys/ 
reservation-id 
security-groups 
services/ 

因此,私有IP地址通過可用3210個

$ curl http://169.254.169.254/latest/meta-data/local-ipv4 

172.31.10.221 

公共IP地址通過可用:

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

54.232.200.77 
+0

我已經添加了兩個公網IP地址,我已經使用捲曲http://169.254.169.254/latest/meta-data/public- ipv4命令,但它顯示我最近添加的IP地址。有沒有辦法在實例中列出所有公共IP地址? – Techiescorner