How to fix Error: connect ENETUNREACH (no route to destination) in Node.js

Node.jsINTERMEDIATEHIGHUpdated Dec 9, 2025· 198 views

This error occurs when Node.js attempts to establish a TCP connection but the operating system cannot find a network route to the destination. The connection fails because no routing path exists between your system and the target host.

Quick fix

Fixes ENETUNREACH

# Ping the target host
ping example.com

# Check routing table
ip route show  # Linux
route print    # Windows
netstat -rn    # macOS

# Test TCP connection directly
telnet example.com 443
# or
nc -zv example.com 443
  1. Verify network connectivity and routing
  2. Check VPN connection status
  3. Configure IPv4 preference for dual-stack systems
  4. Configure proxy settings if behind corporate firewall
node.js — error
# Ping the target host
ping example.com
# Check routing table
ip route show # Linux
route print # Windows
netstat -rn # macOS
# Test TCP connection directly
telnet example.com 443
# or
nc -zv example.com 443
Error: connect ENETUNREACH (no route to destination)

What this error means

The ENETUNREACH (Network Unreachable) error indicates that a TCP connection attempt has failed because the operating system cannot determine any route to reach the destination network or host. This is a low-level network error reported by the OS networking stack to Node.js. When Node.js makes outbound HTTP/HTTPS requests, connects to databases, or performs other network operations, it relies on the operating system's routing tables to determine how to reach the destination IP address. If no route exists—due to network configuration issues, firewall rules, or intermediate gateway problems—the OS returns ENETUNREACH (errno 101 on Linux systems). This error is distinct from EHOSTUNREACH (host unreachable) and ETIMEDOUT (connection timeout). ENETUNREACH specifically means the network layer cannot find any path to the destination, typically failing immediately rather than timing out after repeated attempts.

Typical symptoms

  • HTTP/HTTPS requests fail immediately with ENETUNREACH error
  • npm install commands fail when fetching packages from registries
  • Database connections cannot be established
  • Error occurs immediately without timeout delay
  • All network operations to specific hosts or networks fail consistently
  • Error message includes "connect ENETUNREACH" followed by an IP address and port

Common causes

  1. VPN disconnection while application tries to reach resources only accessible through VPN
  2. IPv6 connection attempts on systems without IPv6 routing configured
  3. Firewall or security software blocking outbound network connections
  4. Incorrect routing table configuration missing routes to destination networks
  5. Corporate proxy configuration not set for Node.js or npm
  6. Docker container networking misconfiguration preventing external access
  7. Network interface down or not properly initialized
  8. Attempting to connect to private IP addresses from networks without proper routing

How to fix "Error: connect ENETUNREACH (no route to destination)"

1Verify network connectivity and routing

First, check if you can reach the destination host using system networking tools:

bash
# Ping the target host
ping example.com

# Check routing table
ip route show  # Linux
route print    # Windows
netstat -rn    # macOS

# Test TCP connection directly
telnet example.com 443
# or
nc -zv example.com 443

If ping or telnet fails, the issue is at the OS networking level, not specific to Node.js.

2Check VPN connection status

If you're connecting to resources that require VPN access, ensure your VPN is active:

bash
# Check VPN interface is up (Linux/macOS)
ifconfig | grep tun
ip addr show tun0

# Verify VPN routes are present
ip route | grep vpn

Reconnect to your VPN if disconnected, then retry the Node.js operation.

3Configure IPv4 preference for dual-stack systems

If the error shows an IPv6 address (containing colons like 2606:4700::...) but your system doesn't have IPv6 routing:

javascript
// Force IPv4 for HTTP requests
const https = require('https');

const options = {
  hostname: 'example.com',
  port: 443,
  path: '/',
  method: 'GET',
  family: 4  // Force IPv4
};

https.request(options, (res) => {
  // Handle response
}).end();

For axios:

javascript
const axios = require('axios');

axios.get('https://example.com', {
  httpAgent: new (require('http').Agent)({ family: 4 }),
  httpsAgent: new (require('https').Agent)({ family: 4 })
});

For npm, configure registry to use IPv4:

bash
npm config set registry https://registry.npmjs.org/
npm config set fetch-retries 3
4Configure proxy settings if behind corporate firewall

If you're behind a corporate proxy, configure Node.js and npm to use it:

bash
# Set npm proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# Set environment variables for Node.js
export HTTP_PROXY=http://proxy.company.com:8080
export HTTPS_PROXY=http://proxy.company.com:8080

# For git operations via npm
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080

Include credentials if required:

bash
npm config set proxy http://username:password@proxy.company.com:8080
5Check firewall and security software

Verify that firewall rules aren't blocking outbound connections:

bash
# Linux: Check iptables rules
sudo iptables -L -n

# Check if specific port is allowed
sudo iptables -L OUTPUT -n | grep 443

# Temporarily disable firewall for testing (Linux)
sudo systemctl stop firewalld  # Fedora/CentOS
sudo ufw disable               # Ubuntu

On Windows, check Windows Defender Firewall and any third-party security software (Kaspersky, Norton, etc.). Add Node.js and npm to firewall exceptions if needed.

6Fix Docker container networking

If running in Docker and can't reach external networks:

bash
# Use host network mode
docker run --network host your-image

# Or ensure bridge network has proper routing
docker network inspect bridge

In docker-compose.yml:

yaml
services:
  app:
    image: node:18
    network_mode: "host"
    # or
    dns:
      - 8.8.8.8
      - 8.8.4.4

Restart Docker networking:

bash
sudo systemctl restart docker
7Add error handling for transient network issues

Implement retry logic to handle temporary network unreachability:

javascript
const https = require('https');

function requestWithRetry(options, maxRetries = 3) {
  return new Promise((resolve, reject) => {
    let attempts = 0;

    function attempt() {
      attempts++;

      const req = https.request(options, (res) => {
        resolve(res);
      });

      req.on('error', (err) => {
        if (err.code === 'ENETUNREACH' && attempts < maxRetries) {
          console.log(`Retry attempt ${attempts} after ENETUNREACH`);
          setTimeout(attempt, 1000 * attempts); // Exponential backoff
        } else {
          reject(err);
        }
      });

      req.end();
    }

    attempt();
  });
}

Advanced notes

IPv6 vs IPv4 Considerations: Many ENETUNREACH errors occur when DNS returns both IPv6 (AAAA) and IPv4 (A) records, but the system lacks IPv6 routing. Node.js may attempt IPv6 first and fail immediately. Setting family: 4 in connection options forces IPv4 usage.

VPN Split Tunneling: With split-tunnel VPN configurations, only specific routes go through the VPN. ENETUNREACH occurs when applications try to reach VPN-only resources while disconnected. Full-tunnel VPNs may avoid this by routing all traffic through the VPN gateway.

Error Handling Limitations: In some Node.js versions (notably 7.10.0), ENETUNREACH errors may not be catchable via standard error event handlers on sockets, instead throwing uncaught exceptions. Always test error handling thoroughly and consider process-level uncaughtException handlers.

Routing Table Debugging: Use traceroute (Linux/macOS) or tracert (Windows) to identify where routing fails. If the first hop fails, the issue is local routing. If it fails midway, it's an intermediate network problem.

Docker DNS Issues: Docker containers may encounter ENETUNREACH when the host's DNS resolver returns unreachable IP addresses. Explicitly setting DNS servers (--dns 8.8.8.8) can resolve this.

Corporate Network Environments: Some corporate networks use transparent proxies that intercept traffic. ENETUNREACH may indicate the proxy is unreachable or misconfigured. Contact your network administrators for proxy configuration details.

Frequently asked questions

What does "ENETUNREACH" mean?
The ENETUNREACH (Network Unreachable) error indicates that a TCP connection attempt has failed because the operating system cannot determine any route to reach the destination network or host. js. js makes outbound HTTP/HTTPS requests, connects to databases, or performs other network operations, it relies on the operating system's routing tables to determine how to reach the destination IP address.
How do I fix "ENETUNREACH"?
This error occurs when Node.js attempts to establish a TCP connection but the operating system cannot find a network route to the destination. The connection fails because no routing path exists between your system and the target host.
What causes "ENETUNREACH"?
VPN disconnection while application tries to reach resources only accessible through VPN IPv6 connection attempts on systems without IPv6 routing configured Firewall or security software blocking outbound network connections
Is the "ENETUNREACH" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading