When a host resolves to both A and AAAA records, wget normally tries the returned addresses in sequence until one works. Forcing one address family is useful when you need to prove whether a failure belongs to IPv4 or IPv6, or when one family must be excluded for a specific job.
On current GNU wget builds with IPv6 support, -4 and --inet4-only force IPv4, while -6 and --inet6-only force IPv6. The matching inet4_only and inet6_only directives in /$HOME/.wgetrc/ make the same choice persistent, and --prefer-family is the alternative when you only want to change which family is tried first without blocking the other one.
Keep the forced setting narrow. Command-line flags are safest for troubleshooting or a single automation job, while a saved /$HOME/.wgetrc/ rule makes sense only when the same account should always stay on one family. Never set both startup-file directives to on at the same time.
Steps to force IPv4 or IPv6 in wget:
- Force one probe onto IPv4 and confirm the Connecting to line shows a dotted-decimal address.
$ wget --inet4-only --spider https://example.com/ Spider mode enabled. Check if remote file exists. --2026-04-22 10:58:55-- https://example.com/ Resolving example.com (example.com)... 172.66.147.243, 104.20.23.154 Connecting to example.com (example.com)|172.66.147.243|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Remote file exists and could contain further links, but recursion is disabled -- not retrieving.
The dotted-decimal address confirms that wget stayed on IPv4 for that run.
- Force the same probe onto IPv6 and confirm wget stays on the colon-separated addresses returned by DNS.
$ wget --inet6-only --tries=1 --timeout=10 --spider https://example.com/ Spider mode enabled. Check if remote file exists. --2026-04-22 10:55:10-- https://example.com/ Resolving example.com (example.com)... 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a Connecting to example.com (example.com)|2606:4700:10::ac42:93f3|:443... failed: Operation timed out. Connecting to example.com (example.com)|2606:4700:10::6814:179a|:443... failed: Operation timed out. Giving up.
With --inet6-only active, wget does not fall back to IPv4. On a host with working IPv6 routing, the same command ends with 200 OK after the IPv6 Connecting to line.
- Persist one address-family default in /$HOME/.wgetrc/ only when every future wget command for that account should inherit it.
~/.wgetrc inet4_only = on inet6_only = off
Flip the two values when the account should stay on IPv6 instead. Related: How to configure default options in ~/.wgetrc
- Verify the saved default without repeating the family flag on the command line.
$ wget --spider https://example.com/ Spider mode enabled. Check if remote file exists. --2026-04-22 10:58:55-- https://example.com/ Resolving example.com (example.com)... 172.66.147.243, 104.20.23.154 Connecting to example.com (example.com)|172.66.147.243|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Remote file exists and could contain further links, but recursion is disabled -- not retrieving.
If the saved default is IPv6 instead, the Connecting to line should show a colon-separated address. Related: How to debug wget connections
Related: How to set connection and read timeouts in wget
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
