wget - force ipv4/ipv6 connection

In this article, we would discuss how to force ipv4/ipv6 connection for wget. Wget is command-line network utility which is used to retrieve/download files from web. It supports recursive downloads. It was first released in January 1996. And, at the time of writing the article, the latest stable release for wget is 1.20.3.

With wget, we can retrieve files through following protocols –

  1. HTTPS
  2. HTTP
  3. FTP

In addition to, we can retrieve content through HTTP proxies also.

wget – force ipv4/ipv6 connection

There could be numerous reasons which would make us switch between ipv4 and ipv6 connections for wget downloads. When you face such a scenario, wherein you have to choose either of them. Else, it will leave you stuck. Then, issue following options with wget.

So, if you choose to go ahead with ipv4 then use --inet4-only or -4 option with wget. This forces wget to connect to ipv4 addresses. Only A records (for ipv4) are used in DNS, thus ignoring AAAA records. Thereby, it refuses to connect to ipv6 addresses.

wget -4 https://<domain-name>/<file-name>

or,

wget --inet4-only https://<domain-name>/<file-name>

Similarly, use following options to connect wget to ipv6 addresses --inet6-only or -6 . This makes wget to use AAAA records in DNS thereby ignoring A records, which are mainly used to map ipv4 domain name.

wget -6 https://<domain-name>/<file-name>

or,

wget --inet6-only https://<domain-name>/<file-name>

It is worth mentioning here that, both options shouldn’t be used at the same time.

In conclusion, we have discussed how to force wget to connect to ipv4/ipv6 addresses.

Additional Info –

By default, wget connects as per configuration specified in host’s DNS record. But, what if host’s DNS record supports both ipv4/ipv6 connections. Then, how wget will prioritize between the two connections.

Under such a scenario, unless we specify which one to prefer – wget will always connect as per the address order returned by the DNS.

We can make wget to prefer either of the two connections i.e. ipv4 or ipv6 through option --prefer-family=none/IPv4/IPv6. This is only useful in cases where configuration in host’s DNS record supports both ipv4 and ipv6 connections.

Similar Posts