Curl error : No route to host

Curl error : No route to host

  1. Blog
  2. 15 November 2026
  3. 5 min read

Stefan Bogdanescu

Founder & Senior Architect

Curl error : No route to host

When building a PHP web application that consumes an external API via Guzzle, encountering cURL error 7: Failed to connect to external.api.com port 443: No route to host is frustrating, especially when the same code works perfectly in development but fails on production. The error message explicitly states that the connection cannot be established at the network layer before any SSL handshake or certificate validation occurs.

In your specific scenario, you are running Apache on Linux with SSL enabled, targeting an external API that also uses HTTPS (port 443) and requires client-side certificate authentication. The fact that requests to public domains like https://google.com and https://facebook.com succeed while requests to your target API fail is the critical diagnostic clue. This rules out a complete network outage or a blanket firewall blocking all outbound traffic. Instead, it points to a routing or host-specific restriction.

The "No route to host" error in cURL (and underlying OpenSSL/libcurl) indicates that the operating system's kernel has no active route to reach the destination IP address of external.api.com. This is distinct from a DNS resolution failure; if DNS were broken, you would typically see an error like "Could not resolve host." Here, the name resolves (or cURL attempts to), but the packet cannot leave the interface or reach its gateway.

Investigating Routing and Network Configuration

Since the issue is isolated to specific external hosts, your initial suspicion regarding Apache configuration is partially understandable but technically unlikely to be the root cause in this form. Apache itself does not dictate whether the PHP process can make outbound network calls; it only dictates inbound traffic handling. The libcurl library runs within the PHP-FPM or Apache worker process and uses the system's standard networking stack. Therefore, you should not look for cURL-specific directives in your .htaccess files or main Apache config (httpd.conf) to fix routing issues.

The suggestion to modify /etc/network/interface (likely referring to /etc/netplan/, /etc/network/interfaces, or /etc/sysconfig/network-scripts/ depending on the specific Linux distribution) is relevant only if you are trying to define static routes or change default gateways manually. However, modifying these files without a deep understanding of your VPC or datacenter topology can break connectivity for all services.

To diagnose why external.api.com is unreachable while others are not, you need to inspect the kernel's routing table using netstat -rn or the more modern ip route. Run the following command:

ip route get $(dig +short external.api.com)

This command resolves the domain and then asks the kernel how it plans to reach that specific IP. If the output shows something like "no route to host" or relies on a default gateway that is unreachable, you have identified the bottleneck. Check if there are source-specific routes or policy-based routing rules in /etc/iproute2/rt_rules that might be intercepting traffic from your Apache PHP processes specifically.

Firewall and Security Groups

A common cause for this specific error in production environments is a security group or firewall rule that allows outbound traffic to public IPs (like Google) but restricts access to private IP ranges or specific external APIs. If external.api.com resolves to an IP address within a private subnet (e.g., 10.x.x.x), your Linux host might not have a route back into that private network, resulting in the "No route to host" error because it tries to send traffic via its default gateway which assumes public routing.

Additionally, check if there are egress filters on your cloud provider (AWS, Azure, GCP) or a local firewall (iptables or firewalld) that explicitly drops packets destined for the IP range of external.api.com. Since you cannot ping external hosts to test connectivity directly from the server (due to the error), relying on successful connections to major public sites is your only baseline confirmation that the network stack itself is functional.

Client Certificate Authentication

You mentioned that the HTTP requests include a certificate for authentication. While this is an application-layer concern, it is worth noting that if the certificate file permissions are too restrictive or if the system library cannot read the CA bundle to verify the server's identity during the handshake, you might see errors later in the process. However, error 7 happens before the SSL handshake begins. If the error were related to the client certificate, cURL would typically return an error regarding "certificate verify failed" or "unable to get local issuer certificate." The routing error suggests the TCP connection cannot even be established with the server's IP.

Next Steps for Resolution

To resolve this without breaking your existing connectivity:

  1. Verify DNS Resolution: Ensure the application server resolves external.api.com to an IP address that is reachable via the default gateway.
  2. Check Routing Tables: Confirm that the resolved IP has a valid route in the kernel table (ip route show).
  3. Inspect Egress Rules: If you are in a cloud environment, verify security group egress rules allow traffic to the target IP/Port.
  4. Avoid Hardcoded Network Changes: Do not blindly edit interface configuration files unless you have confirmed that the current routing table is missing a necessary static route for the API's subnet.

If the issue persists and you are unsure of the network topology, capturing packets with tcpdump on the server can reveal exactly where the connection drops:

sudo tcpdump -i any -n host <resolved_ip_of_external.api.com> -w capture.pcap

Analyzing this capture will show whether the SYN packet is never sent, sent but dropped by a firewall, or if the kernel itself refuses to route it.

Our network