This topic describes the cause of and solution to the following issue: You cannot run a curl command to access the Metaserver from a Linux Elastic Compute Service (ECS) instance and the "curl: (7) Failed to connect to 100.100.XX.XX port 80: Connection timed out" error message appears.
Problem description
When you run a curl command on a Linux instance to connect to the Metaserver (metadata server) by using the IP address 100.100.XX.XX, the connection fails and the following error message appears:
curl: (7) Failed to connect to 100.100.XX.XX port 80: Connection timed outThe error message indicates that the connection to port 80 at the preceding IP address timed out and failed.
If a Linux instance cannot access the Metaserver, specific initialization operations on the instance may fail, such as key pair configuration, hostname initialization, and hosts initialization.
Cause
In most cases, the issue occurs because exceptions exist in the network environment of the Linux instance and causes the instance to fail to establish network connections to destination IP addresses. The following exceptions may exist in the network environment of the Linux instance:
Abnormal network configurations: cause the Linux instance to fail to establish network connections. As a result, the instance cannot connect to the Metaserver. To resolve the issue, reset the network configuration to Dynamic Host Configuration Protocol (DHCP). For more information, see the Reset the network configuration to DHCP section in this topic.
Firewall rules that block access to the Metaserver: cause the Linux instance to fail to access the Metaserver by using
100.100.**.**. You can check the system firewall configurations and temporarily disable the system firewall to check whether the firewall configurations cause the Linux instance to fail to access the Metaserver. For more information, see the Disable the system firewall section in this topic.
Solution
Reset the network configuration to DHCP
In this example, a Linux instance that runs a Red Hat series operating system is used to describe how to reset the network configuration to DHCP. For information about how to reset the network configuration to DHCP in other Linux distributions, see How to configure the network as DHCP in a Linux image.
Run the following command to modify the network configuration file:
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0Change the following network configurations:
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=noPress the
Esckey to exit Insert mode. Enter:wqand press the Enter key to save and close the file.Restart the network service.
If the instance runs CentOS 6 or Red Hat 6, run the following command:
sudo service network restartIf the instance runs CentOS 7, Red H, Anolis 7, or Alibaba Cloud Linux 2, run the following command:
sudo systemctl restart networkIf the instance runs CentOS 8, Red Hat 8, Anolis 8, Fedora 33, Fedora 34, Fedora 35, or Alibaba Cloud Linux 3, perform the following operations:
Run the following command to reload all network interface controller (NIC) configurations:
sudo nmcli c reloadRun the following command to enable NICs:
sudo nmcli d connect eth0
Disable the system firewall
The commands that are used to enable or disable the system firewall vary based on the Linux distribution. Modify the following commands based on the actual scenarios.
CentOS 5 and CentOS 6
Run the following commands to enable and disable the system firewall and check the status of the system firewall in CentOS 5 and CentOS 6.
Enable the system firewall.
sudo service iptables startDisable the system firewall.
sudo service iptables stopCheck the status of the system firewall.
sudo service iptables status
CentOS 7, Red Hat 7, and Alibaba Cloud Linux 2
Run the following commands to enable and disable the system firewall and check the status of the system firewall in CentOS 7, Red Hat, and Alibaba Cloud Linux 2.
Enable the system firewall.
sudo systemctl start firewalld.serviceDisable the system firewall.
sudo systemctl stop firewalld.serviceCheck the status of the system firewall.
sudo firewall-cmd --state
Ubuntu
Run the following commands to enable and disable the system firewall and check the status of the system firewall in Ubuntu.
Enable the system firewall.
sudo ufw enableDisable the system firewall.
sudo ufw disableCheck the status of the system firewall.
sudo ufw status
Debian
By default, no firewall is installed on Debian. If a firewall is installed on Debian, you can delete all firewall rules to remove traffic blocking. Perform the following operations.
Before you delete all firewall rules, back up the rules.
Run the following commands to back up firewall rules:
touch [$Iptables] sudo iptables-save > [$Iptables]Note[$Iptables]specifies the directory in which you want to save the firewall rule backup file.Run the following command to delete all firewall rules:
sudo iptables -F