Updated on 2024-04-15 GMT+08:00

Why Can't My Linux ECS Obtain Metadata?

Symptom

The security group of the Linux ECS has been configured based on the prerequisites in Obtaining Metadata in the outbound direction, but the ECS still cannot obtain the metadata through the route with the destination of 169.254.169.254.

Root Cause

Run the following command on the Linux ECS configured with a static IP address:

# ip route| grep 169.254

The route with the destination of 169.254.169.254 does not exist, but the route with the destination of 169.254.0.0/16 exists.

Figure 1 Route information

After the network is restarted, the original route with the destination of 169.254.169.254 is changed to the route with the destination of 169.254.0.0/16 without a next hop, as shown in Figure 1. As a result, the Linux ECS cannot obtain metadata.

Solution

  1. Add the route with the destination of 169.254.169.254, and specify the next hop (gateway) and the output device (primary NIC of the Linux ECS). The following is an example:

    # ip route add 169.254.169.254 via 192.168.1.1 dev eth0

    192.168.1.1 is the gateway address of the subnet that the primary NIC resides, and eth0 is the primary NIC.

    How Do I View the Primary NIC?

    How Do I View the Gateway Address?

  2. Run the following command to verify that the metadata can be obtained:

    # curl http://169.254.169.254

    Figure 2 Obtaining metadata
  1. Run the following command to create or modify the /etc/sysconfig/network-scripts/route-eth0 file to prevent the static route from being changed after network restart:

    # vi /etc/sysconfig/network-scripts/route-eth0

    Add the following content to the file:

    In this example, the primary NIC is eth0 and gateway address is 192.168.1.1. Replace them based on site requirements.

    # 169.254.169.254 via 192.168.1.1

How Do I View the Primary NIC?

  1. Log in to the management console.
  2. Click in the upper left corner and select your region and project.
  3. Under Computing, click Elastic Cloud Server.
  4. Click the name of the target ECS.

    The page providing details about the ECS is displayed.

  5. Click the Summary tab to view details about the primary NIC.
    Figure 3 Primary NIC details

How Do I View the Gateway Address?

  1. Log in to the management console.
  2. Click in the upper left corner and select your region and project.
  3. Under Computing, click Elastic Cloud Server.
  4. Click the name of the target ECS.

    The page providing details about the ECS is displayed.

  5. Click the VPC name to go to the VPC list page.
    Figure 4 VPC name
  6. Locate the row that contains the target VPC and click the number in the Subnets column to go to the subnet list page.
    Figure 5 Number in the Subnets column
  7. Click the target subnet name to go to the subnet details page and view the gateway address.
    Figure 6 Gateway address