ErrorKind::HostUnreachable
RustERRORCommonNetwork
Host is unreachable
Quick Answer
Verify routing table, DNS resolution, and firewall rules for the target host.
What this means
No route to the target host exists from this machine.
Why it happens
- 1No route in routing table
- 2Target IP unreachable from this network segment
- 3ICMP unreachable returned by a router
Fix
Validate host before connecting
Validate host before connecting
use std::net::ToSocketAddrs;
let addrs: Vec<_> = "example.com:443".to_socket_addrs()?.collect();
if addrs.is_empty() { return Err("DNS resolution failed".into()); }Why this works
DNS resolution failure surfaces before a connection attempt wastes time.
Code examples
Noterust
// Added in Rust 1.83; maps to EHOSTUNREACH on Linux
Same error in other languages
Sources
Official documentation ↗
Rust std::io
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev