How to Download Files Using Specific DNS Ubuntu
This article explains how to download files on Ubuntu while forcing the use of a specific DNS resolver. You will learn the exact command-line flags required for tools like wget and curl to bypass system default settings. This method is useful for troubleshooting network issues or accessing resources restricted by local DNS configurations.
Using Wget with a Custom DNS Server
The most common command for downloading files in Ubuntu is
wget. To specify a DNS resolver, use the
--dns-servers flag. This option allows you to define one or
more IP addresses for the DNS lookup without changing your system
network settings.
The basic syntax is:
wget --dns-servers=IP_ADDRESS URLFor example, to download a file using Google’s public DNS server (8.8.8.8), run:
wget --dns-servers=8.8.8.8 https://example.com/file.zipYou can specify multiple DNS servers by separating them with commas. This ensures a fallback if the primary resolver fails:
wget --dns-servers=8.8.8.8,1.1.1.1 https://example.com/file.zipNote that this feature requires wget version 1.20 or
newer, which is standard in Ubuntu 20.04 and later.
Using Curl with a Custom DNS Server
If you prefer using curl, the process is similar. The
curl command also supports the --dns-servers
option to dictate which nameservers handle the domain resolution.
The syntax for curl is:
curl --dns-servers IP_ADDRESS -O URLTo download a file using Cloudflare’s DNS (1.1.1.1), execute:
curl --dns-servers 1.1.1.1 -O https://example.com/file.zipThe -O flag tells curl to save the file using its remote
name. Like wget, this command performs the DNS lookup independently of
your /etc/resolv.conf configuration.
Why Use a Specific DNS Resolver
Using these commands allows you to bypass ISP-level DNS filtering or caching issues. It is particularly helpful when a domain resolves incorrectly on your local network but works correctly via public DNS. This method provides a quick way to test connectivity without altering global network configurations.