How Does wget Handle IPv4 and IPv6 Connections?

The GNU wget utility is a powerful command-line tool for downloading files from the web, built to navigate both IPv4 and IPv6 network environments seamlessly. By default, wget automatically resolves domain names to available IP addresses, prioritizing IPv6 when available but gracefully falling back to IPv4 if the connection fails. Network administrators and users can also explicitly control this behavior using specific command-line flags to force a particular protocol or manage fallback settings.

Default Resolution and Dual-Stack Behavior

In modern networking environments, many domains use a dual-stack configuration, meaning they possess both IPv4 (A records) and IPv6 (AAAA records) addresses. When you initiate a request, wget leverages the operating system’s underlying name resolution functions (such as getaddrinfo).

Forcing a Specific IP Version

There are scenarios where you must bypass wget’s automatic selection—such as troubleshooting a broken IPv6 tunnel or testing a specific network path. You can force wget to use one protocol exclusively by employing the following flags:

wget -4 https://example.com/file.zip
wget -6 https://example.com/file.zip

Handling Explicit IP Addresses in URLs

When bypassing DNS entirely and passing raw IP addresses directly into the wget command, the syntax changes based on the protocol version.

wget http://192.0.2.1/file.zip
wget http://[2001:db8::1]/file.zip

Persistent Configuration

If you consistently operate in an environment where one protocol is unreliable, you can modify your global or user-specific configuration file (/etc/wgetrc or ~/.wgetrc). Adding the line prefer-family = IPv4 or prefer-family = IPv6 alters the default sorting order of resolved addresses, giving you permanent control over how wget navigates dual-stack networks.