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.
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.
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 a result, the Linux ECS cannot obtain metadata.
# 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.
# 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