Dual-stack name resolution can hide the real cause of a failed download because one address family may work while the other stalls or times out. Forcing wget onto IPv4 or IPv6 makes that difference explicit, which is useful when debugging DNS, routing, firewall policy, or upstream listener problems.
The -4 and -6 flags map to --inet4-only and --inet6-only. They tell wget to ignore the other family completely for that run, and the startup-file directives inet4_only = on and inet6_only = on provide the same behavior when one account needs a persistent preference.
Only one strict family should be enabled at a time. Keep the change on the command line until the same host set consistently needs one family, because a persistent default can break unrelated downloads that rely on normal dual-stack fallback.
$ wget --help | grep -n 'inet4-only\|inet6-only' 66: -4, --inet4-only connect only to IPv4 addresses 67: -6, --inet6-only connect only to IPv6 addresses
$ wget -4 --spider https://downloads.example.net/ 2>&1 | grep -E 'Resolving|Connecting to|HTTP request sent' Resolving downloads.example.net (downloads.example.net)... 198.51.100.24, 198.51.100.25 Connecting to downloads.example.net (downloads.example.net)|198.51.100.24|:443... connected. HTTP request sent, awaiting response... 200 OK
With -4 active, wget ignores AAAA records for that run and refuses IPv6 URL literals.
$ wget -6 --spider https://downloads.example.net/ 2>&1 | grep -E 'Resolving|Connecting to|HTTP request sent' Resolving downloads.example.net (downloads.example.net)... 2001:db8:100::24, 2001:db8:100::25 Connecting to downloads.example.net (downloads.example.net)|2001:db8:100::24|:443... connected. HTTP request sent, awaiting response... 200 OK
IPv6-only mode fails immediately when the host has no usable IPv6 route, which is the point when isolating stack-specific failures.
$ wget --execute='inet4_only = on' --execute='inet6_only = off' --spider https://downloads.example.net/ 2>&1 | grep -E 'Resolving|Connecting to|HTTP request sent' Resolving downloads.example.net (downloads.example.net)... 198.51.100.24, 198.51.100.25 Connecting to downloads.example.net (downloads.example.net)|198.51.100.24|:443... connected. HTTP request sent, awaiting response... 200 OK
The --execute form is useful when a launcher already manages other temporary wgetrc directives for one run only.
~/.wgetrc inet4_only = on inet6_only = off
Do not set both directives to on at the same time. Related: How to configure default options in ~/.wgetrc
$ wget --server-response --spider --inet4-only https://downloads.example.net/ 2>&1 | grep -E 'Resolving|Connecting to|HTTP/1.1 200' Resolving downloads.example.net (downloads.example.net)... 198.51.100.24, 198.51.100.25 Connecting to downloads.example.net (downloads.example.net)|198.51.100.24|:443... connected. HTTP/1.1 200 OK
Dotted-decimal addresses confirm IPv4, while colon-separated addresses confirm IPv6. Related: How to debug wget connections
Related: How to set connection and read timeouts in wget