如何从 EC2 实例内部(即连接后)查看分配给 EC2 实例的公共 IP 地址?我可以看到分配给它的公共 IP 地址,只需在管理控制台中查看即可。
从AWS 文档中,我们可以使用以下 curl 命令获取公共 IP 地址。
$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data
但看起来它不起作用。
$ TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56 100 56 0 0 28000 0 --:--:-- --:--:-- --:--:-- 56000
* Trying 169.254.169.254:80...
* TCP_NODELAY set
* Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta-data HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/7.68.0
> Accept: */*
> X-aws-ec2-metadata-token: AQAAAEKVNCUB3KPoodSB0SFUkkn1aSah2MRUxAVQQx_3SeVBllVoFA==
>
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Accept-Ranges: bytes
< Content-Length: 324
< Content-Type: text/plain
< Date: Tue, 29 Nov 2022 11:29:43 GMT
< Last-Modified: Wed, 23 Nov 2022 18:36:36 GMT
< X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21600
< Connection: close
< Server: EC2ws
<
ami-id
ami-launch-index
ami-manifest-path
auth-identity-credentials/
block-device-mapping/
events/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-keys/
reservation-id
security-groups
services/
知道如何在 EC2 实例中获取公共 IP 吗?