Troubleshoot "Connection timed out" when accessing the Metaserver from a Linux instance

Updated at:

Fix the "curl: (7) Failed to connect to 100.100.XX.XX port 80: Connection timed out" error by resetting DHCP or disabling the firewall.

Symptom

Running a curl command on a Linux instance to connect to the Metaserver at 100.100.XX.XX fails with the following error:

curl: (7) Failed to connect to 100.100.XX.XX port 80: Connection timed out

The connection to port 80 at the specified IP address timed out.

Note

If a Linux instance cannot access the Metaserver, initialization operations such as key pair configuration, hostname setup, and hosts setup may fail.

Cause

The issue typically occurs because the network environment of the Linux instance prevents connections to destination IP addresses. Common causes include:

Solution

Reset the network configuration to DHCP

This example uses a Red Hat series Linux instance. For other distributions, see How to configure the network as DHCP in a Linux image.

  1. Connect to the Linux instance.

    See Connect to a Linux instance by using a password or key.

  2. Modify the network configuration file:

    sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 
  3. Set the following network configurations:

    BOOTPROTO=dhcp
    DEVICE=eth0
    ONBOOT=yes
    STARTMODE=auto
    TYPE=Ethernet
    USERCTL=no
  4. Press Esc to exit Insert mode. Enter :wq and press Enter to save and close the file.

  5. Restart the network service.

    • If the instance runs CentOS 6 or Red Hat 6:

      sudo service network restart
    • If the instance runs CentOS 7, Red Hat 7, Anolis 7, or Alibaba Cloud Linux 2:

      sudo systemctl restart network
    • If the instance runs CentOS 8, Red Hat 8, Anolis 8, Fedora 33, Fedora 34, Fedora 35, or Alibaba Cloud Linux 3:

      1. Reload all NIC configurations:

         sudo nmcli c reload
      2. Enable NICs:

        sudo nmcli d connect eth0

Disable the system firewall

Firewall commands vary by Linux distribution. Adjust as needed.

CentOS 5 and CentOS 6

Manage the firewall in CentOS 5 and CentOS 6:

  • Enable the firewall:

    sudo service iptables start
  • Disable the firewall:

    sudo service iptables stop
  • Check the firewall status:

    sudo service iptables status

CentOS 7, Red Hat 7, and Alibaba Cloud Linux 2

Manage the firewall in CentOS 7, Red Hat 7, and Alibaba Cloud Linux 2:

  • Enable the firewall:

    sudo systemctl start firewalld.service
  • Disable the firewall:

    sudo systemctl stop firewalld.service
  • Check the firewall status:

    sudo firewall-cmd --state

Ubuntu

Manage the firewall in Ubuntu:

  • Enable the firewall:

    sudo ufw enable
  • Disable the firewall:

    sudo ufw disable
  • Check the firewall status:

    sudo ufw status

Debian

Debian has no firewall installed by default. If a firewall is installed, delete all rules to remove traffic blocking.

Important

Back up the rules before deleting them.

  1. Back up firewall rules:

    touch [$Iptables]
    sudo iptables-save > [$Iptables]
    Note

    [$Iptables] specifies the backup file path.

  2. Delete all firewall rules:

    sudo iptables -F