All Products
Search
Document Center

Elastic Compute Service:Instance metadata

Last Updated:May 15, 2026

Query instance properties such as IDs and IP addresses from within an ECS instance, and enforce security hardening mode to prevent SSRF attacks.

Get instance metadata

Instance metadata includes attributes such as instance ID, network configuration, and access credentials.

Method 1: Security hardening mode (recommended)

Obtain a temporary access token, then include it in your metadata request.

Linux

  1. Log on to the instance.

  2. Obtain a temporary token.

    TOKEN=`curl -X PUT "http://100.100.100.200/latest/api/token" -H "X-aliyun-ecs-metadata-token-ttl-seconds:21600"`
    The X-aliyun-ecs-metadata-token-ttl-seconds parameter specifies the token TTL in seconds. Valid values: 1 to 21600.
  3. Include the token in your request to retrieve metadata.

    curl -H "X-aliyun-ecs-metadata-token: $TOKEN" http://100.100.100.200/latest/meta-data/instance-id
    Replace instance-id with other metadata items as needed, such as mac or hostname.

    On success, the terminal outputs only the instance ID string, for example, i-bp1******.

Windows

  1. Log on to the instance.

  2. Obtain a temporary token.

    $token = Invoke-RestMethod -Headers @{"X-aliyun-ecs-metadata-token-ttl-seconds" = "21600"} -Method PUT -Uri http://100.100.100.200/latest/api/token
    The X-aliyun-ecs-metadata-token-ttl-seconds parameter specifies the token TTL in seconds. Valid values: 1 to 21600.
  3. Include the token in your request to retrieve metadata.

    Invoke-RestMethod -Headers @{"X-aliyun-ecs-metadata-token" = $token} -Method GET -Uri http://100.100.100.200/latest/meta-data/instance-id
    Replace instance-id with other metadata items as needed, such as mac or hostname.

    On success, the terminal outputs only the instance ID string, for example, i-bp1******.

Method 2: Normal mode

Warning

Normal mode is insecure and not recommended.

  • Linux:

    # Send a GET request to get the instance ID.
    curl http://100.100.100.200/latest/meta-data/instance-id
  • Windows:

    # Send a GET request to get the instance ID.
    Invoke-RestMethod -Uri http://100.100.100.200/latest/meta-data/instance-id -Method Get

Enable security hardening mode only

Enable Security Hardening Mode so that metadata can only be accessed with a token. Normal mode requests return a 403 - Forbidden error. By default, ECS instances allow token-free access (normal mode), which poses a high risk of SSRF attacks.

A typical attack exploits an application feature such as downloading an image from an external URL. An attacker crafts a request that tricks the server into querying the metadata service, stealing the RAM role's temporary credentials. If the role has high-level permissions, the attacker could gain control over your cloud resources or your entire Alibaba Cloud account.

Enable security hardening mode for a new instance

Console

When you create an instance, set Advanced Options > Metadata Access Mode to Security Hardening Mode.

If Security Hardening Mode is unavailable when creating an instance from a custom image, upgrade the image.

CLI

Call RunInstances or CreateInstance with HttpEndpoint=enabled and HttpTokens=required. Example:

This example creates a Linux instance in security hardening mode.
aliyun ecs RunInstances \
--region cn-hangzhou \
--RegionId 'cn-hangzhou' \
--ImageId 'aliyun_3_x64_20G_alibase_20250629.vhd' \
--InstanceType 'ecs.g7.large' \
--VSwitchId 'vsw-bp1******trg' \
--SecurityGroupId 'sg-bp1******dgl' \
--SystemDisk.Size 40 \
--SystemDisk.Category cloud_essd \
--HttpEndpoint enabled \
--HttpTokens required

API

Call RunInstances or CreateInstance with HttpEndpoint=enabled and HttpTokens=required.

Upgrade an existing instance

Applicability

  • Windows instances: Security Hardening Mode is not supported. Forcing this mode causes initialization failure and breaks hostname modification and KMS activation.

  • Linux instances: Supported. Complete the dependency checks and modifications in the following sections before upgrading.

Step 1: Check and upgrade code and dependencies

Before switching to Security Hardening Mode, ensure the instance and all deployed applications meet these requirements:

  • Cloud-init version must be 23.2.2 or later. Run cloud-init --version to check. If earlier than 23.2.2, upgrade Cloud-init first — otherwise the instance fails to start after switching.

  • All application code and scripts must access instance metadata using Method 1: Security hardening mode.

    Important

    If your code uses the Credentials library to obtain an STS token for SDK configuration, upgrade to a version that supports security hardening mode.

After upgrading, verify that no normal mode access remains. See How do I detect if an ECS instance is being accessed in normal mode?. Then enable Security Hardening Mode for the instance.

Step 2: Enable security hardening mode

Console

  1. Go to the ECS console - Instances page. Select a region and a resource group.

  2. In the Actions column, click image > Modify Instance Metadata Access Information.

  3. Turn on the Enable Instance Metadata Access Channel switch, set Instance Metadata Access Mode to Security Hardening Mode, and then click OK.

    image

CLI

Call ModifyInstanceMetadataOptions with HttpEndpoint=enabled and HttpTokens=required to enable Security Hardening Mode. Example:

aliyun ecs ModifyInstanceMetadataOptions \
--region cn-hangzhou \
--RegionId 'cn-hangzhou' \
--InstanceId 'i-bp1******ke' \
--HttpEndpoint enabled \
--HttpTokens required

API

Call ModifyInstanceMetadataOptions with HttpEndpoint=enabled and HttpTokens=required to enable Security Hardening Mode.

After switching, monitor metadata access and application status. If issues occur, revert to Normal And Security Hardening Modes to restore service, then repeat Step 1: Check and upgrade code and dependencies.

Instance metadata details

Metadata is organized in a directory-like hierarchy. Accessing a directory returns its entries or subdirectories. For example, meta-data/instance/ returns instance-name and instance-type.

Category

Metadata

Description

Example

Basic instance information

instance-id

The instance ID.

i-bp13znx0m0me8cquu****

instance/instance-name

The instance name.

iZbp1bfqfsvqzxhmnd5****

hostname

The hostname.

iZbp13znx0m0me8cquu****

instance/instance-type

The instance type.

ecs.g6e.large

serial-number

The serial number.

4acd2b47-b328-4762-852f-998****

region-id

The region of the instance.

cn-hangzhou

zone-id

The zone of the instance.

cn-hangzhou-i

owner-account-id

The Alibaba Cloud account ID of the instance owner.

1609****

tags/instance/[tagKey]

The value of a specified instance tag. [tagKey] is the tag key to query.

To enable this feature, call ModifyInstanceMetadataOptions and set InstanceMetadataTags to enabled.

dev

Image information

image-id

The image ID used to create the instance.

aliyun_3_x64_20G_alibase_20210425.vhd

image/market-place/product-code

The product code of the Alibaba Cloud Marketplace image.

cmjj01****

image/market-place/charge-type

The billing method of the Alibaba Cloud Marketplace image.

PrePaid

source-address

The package manager source (such as yum or apt) used by the Linux instance for updates.

http://mirrors.cloud.aliyuncs.com

Basic network configuration

network-type

The network type. Only VPC is supported.

vpc

vpc-id

The VPC ID of the instance.

vpc-bp1e0g399hkd7c8q****

vpc-cidr-block

The CIDR block of the instance's VPC.

192.168.XX.XX/16

vswitch-id

The vSwitch ID of the instance.

vsw-bp1ygryo03m39xhsy****

vswitch-cidr-block

The CIDR block of the instance's vSwitch.

192.168.XX.XX/24

instance/max-netbw-egress

The maximum outbound internal bandwidth of the instance type. Unit: Kbit/s.

1228800

dns-conf/nameservers

The DNS configuration.

100.100.XX.XX

ntp-conf/ntp-servers

The NTP server address.

ntp1.aliyun.com

Primary ENI IP addresses

mac

The MAC address of the instance. For instances with multiple NICs, only the MAC address on eth0 is returned.

00:16:3e:0f:XX:XX

private-ipv4

The private IPv4 address of the primary ENI.

192.168.XX.XX

public-ipv4

The public IPv4 address of the primary ENI of the instance.

120.55.XX.XX

eipv4

The static public IPv4 address or the Elastic IP Address attached to the primary ENI.

120.55.XX.XX

Elastic network interface details

network/interfaces/macs/[mac]/network-interface-id

The ENI ID.

Replace [mac] with the instance's MAC address from the mac metadata item. The same applies to the following items.

eni-bp1b2c0jvnj0g17b****

network/interfaces/macs/[mac]/vpc-id

The VPC ID of the ENI.

vpc-bp1e0g399hkd7c8q3****

network/interfaces/macs/[mac]/vswitch-id

The vSwitch ID of the ENI.

vsw-bp1ygryo03m39xhsy****

network/interfaces/macs/[mac]/primary-ip-address

The primary private IP address of the ENI.

192.168.XX.XX

network/interfaces/macs/[mac]/private-ipv4s

The private IPv4 addresses assigned to the ENI.

["192.168.XX.XX"]

network/interfaces/macs/[mac]/ipv4-prefixes

The private IPv4 prefixes assigned to the ENI.

192.168.XX.XX/28

network/interfaces/macs/[mac]/netmask

The subnet mask of the ENI.

255.255.XX.XX

network/interfaces/macs/[mac]/gateway

The IPv4 gateway of the ENI.

192.168.XX.XX

network/interfaces/macs/[mac]/vswitch-cidr-block

The IPv4 CIDR block of the ENI's vSwitch.

192.168.XX.XX/24

network/interfaces/macs/[mac]/vpc-cidr-block

The IPv4 CIDR block of the ENI's VPC.

192.168.XX.XX/16

network/interfaces/macs/[mac]/ipv6s

The IPv6 addresses assigned to the ENI. Only for VPC-type instances with IPv6 configured.

[2408:XXXX:325:a204:1875:217f:184a:e4e]

network/interfaces/macs/[mac]/ipv6-prefixes

The IPv6 prefixes assigned to the ENI.

2001:db8:1234:1a00:XXXX::/80

network/interfaces/macs/[mac]/ipv6-gateway

The IPv6 gateway of the ENI's VPC.

2408:XXXX:325:a204:ffff:ffff:ffff:fff7

network/interfaces/macs/[mac]/vswitch-ipv6-cidr-block

The IPv6 CIDR block of the ENI's vSwitch. Only for VPC-type instances with IPv6 configured.

2408:XXXX:325:a204::/64

network/interfaces/macs/[mac]/vpc-ipv6-cidr-blocks

The IPv6 CIDR block of the ENI's VPC. Only for VPC-type instances with IPv6 configured.

[2408:XXXX:325:a200::/56]

Disk information

disks/

The disk serial number.

bp131n0q38u3a4zi****

disks/[disk-serial]/id

The disk ID.

d-bp131n0q38u3a4zi****

disks/[disk-serial]/name

The disk name.

testDiskName

Security and credentials

public-keys/[keypair-id]/openssh-key

The public key, available only if one was provided at launch.

ssh-rsa ****3NzaC1yc2EAAAADAQABAAABAQDLNbE7pS****@****.com

ram/security-credentials/[role-name]

The temporary security credentials of the RAM role associated with the instance. Replace [role-name] with the RAM role name. Credentials expire at the time in the Expiration field; call again to obtain new ones.

{
    "AccessKeyId": "****",
    "AccessKeySecret": "****",
    "Expiration": "2024-11-08T09:44:50Z",
    "SecurityToken": "****",
    "LastUpdated": "2024-11-08T03:44:50Z",
    "Code": "Success"
}

Advanced instance attributes

instance/virtualization-solution

The ECS virtualization solution. Virt 1.0 and Virt 2.0 are supported.

ECS Virt

instance/virtualization-solution-version

The internal build number.

2

instance/spot/termination-time

The scheduled stop and release time for a spot instance, in UTC+0 format yyyy-MM-ddThh:mm:ssZ.

2020-04-07T17:03:00Z

Windows-specific configuration

kms-server

The KMS activation server for Windows instances.

kms.cloud.aliyuncs.com

wsus-server/wu-server

The update server for Windows instances.

http://update.cloud.aliyuncs.com

wsus-server/wu-status-server

The update status monitoring server for Windows instances.

http://update.cloud.aliyuncs.com

FAQ

  • What is an SSRF attack, and how does security hardening mode defend against it?

    SSRF is a vulnerability where an attacker tricks a server into making unauthorized network requests to access internal systems such as the metadata service or databases. For example, an attacker can submit a URL containing http://100.100.100.200/latest/meta-data/ to trick an application into fetching and returning sensitive metadata.

    By default, ECS instances allow token-free access (normal mode). Security hardening mode enforces token validation: the client first sends a PUT request for a temporary token, then includes it in GET requests. Because SSRF attacks cannot initiate PUT requests, they cannot obtain a token, effectively blocking unauthorized access.

  • I cannot access instance metadata using commands in security hardening mode. How do I fix this?

    Common command errors:

    • The TTL of the instance metadata access credential is out of range (400 - Missing or Invalid Parameters)

      The TTL must be 1 to 21,600 seconds. Values outside this range return 400 - Missing or Invalid Parameters.

      curl -X PUT "http://100.100.100.200/latest/api/token" -H "X-aliyun-ecs-metadata-token-ttl-seconds: 21700"
    • The request contains the X-Forwarded-For header (403 - Forbidden)

      curl -X PUT "http://100.100.100.200/latest/api/token" -H "X-Forwarded-For: www.ba****.com"
    • The specified instance metadata access credential is invalid (401 - Unauthorized)

      curl -H "X-aliyun-ecs-metadata-token: aaa" -v http://100.100.100.200/latest/meta-data/
  • What do I do if my high-frequency access to the metadata service is throttled?

    The metadata service has rate limits. Retrieve rarely-changing items such as instance-id once at startup and cache them locally with a reasonable TTL.

  • My application stopped working after I changed the instance metadata access mode to security hardening mode. How do I troubleshoot this issue?

    An application or script on the instance may still use normal mode. Follow Upgrade an existing instance to check and upgrade them.

  • Can I access the metadata address from a local host?

    No. 100.100.100.200 is a link-local address reachable only from within an ECS instance over its virtual network interface. Requests from outside the instance cannot be routed to this address.

  • What do I do if I cannot select security hardening mode when I create an instance from a custom image?

    When creating an ECS instance from a custom Linux image, you may find that Security Hardening Mode is unavailable. This means the image does not meet the requirements. Upgrade the image as follows:

    1. Create a temporary instance: Use the custom image to create a temporary ECS instance.

    2. Modify the temporary instance: On the temporary instance, perform the following modifications. See Upgrade an existing instance.

      • Upgrade Cloud-init: Upgrade Cloud-init to version 23.2.2 or later.

      • Modify applications and scripts: Update all applications or scripts that use normal mode to security hardening mode.

    3. Create a new image and update its attributes: Create a new custom image from the instance. Then call ModifyImageAttribute to set Features.ImdsSupport to `v2`.

    4. Release resources: Release the temporary instance after the new image is created.

  • Which versions of the Credentials tool support security hardening mode?

    Earlier versions of Credentials do not support metadata access in security hardening mode. Switching to security hardening mode without upgrading prevents the SDK from obtaining STS tokens, causing service interruptions.

    Upgrade the Credentials dependency to a supported version before switching modes:

    • Java: credentials-java version >= 0.3.10.

    • Node.js: credentials version >= 2.3.1.

    • PHP: credentials version >= 1.2.0.

    • Python: alibabacloud_credentials version >= 0.3.6.

    • Go: credentials-go version >= 1.3.10.

  • How do I detect if an ECS instance is being accessed in normal mode?

    Use the following methods to detect and locate processes that access metadata in normal mode.

    Method 1: Use CloudMonitor to check for normal mode access

    Check ECS metadata monitoring data in the CloudMonitor console to determine whether the instance has been accessed in normal mode.

    1. Log on to the CloudMonitor console.

    2. In the left-side navigation pane, choose Cloud Resource Monitoring > Cloud Service Monitoring. Search for and go to the ECS Metadata monitoring page.

    3. View the Successful Normal Mode Accesses metric for the target instance.

    4. If this metric is not 0, the instance is being accessed in normal mode. Find and upgrade the applications using normal mode.

    Method 2: Use a Cloud Assistant plugin to locate a specific process

    Use a Cloud Assistant plugin to locate processes that access metadata in normal mode.

    Supported operating systems

    • Alibaba Cloud Linux 3

    • Alibaba Cloud Linux 3 Pro

    • Anolis OS 8

    • CentOS Stream 8/9

    • CentOS 8

    • Ubuntu: 20/24

    • Debian:10,11,12

    • Fedora 35+

    • AlmaLinux 8/9

    • Rocky Linux 8/9

    • Red Hat Enterprise Linux 8/9

    • For Red Hat, download an RPM package to install Cloud Assistant Agent.

    • SUSE 15.1/15.2/15.3/15.4/15.5/15.6

    • OpenSuse 15.2/15.3/15.4/15.5/15.6

    Procedure

    1. Install and enable the Cloud Assistant plugin

      Log on to the ECS instance and install the monitoring service. This service consumes some instance resources.

      # Deploy the monitoring service.
      sudo acs-plugin-manager --exec --plugin ACS-ECS-ImdsPacketAnalyzer
      
      # Check the status of the monitoring service.
      sudo systemctl status imds_tracer_tool

      p940998

    2. Locate the problematic process Check which processes still access metadata in normal mode. The log shows the process IDs (PIDs).

      cat /var/log/imds/imds-trace.* | grep WARNING

      p940995

    3. Analyze and modify Find the applications or scripts corresponding to the PIDs and upgrade them to security hardening mode.