How to Set Custom DNS Timeout for wget on Ubuntu
This article provides a direct method for configuring a specific DNS lookup timeout when using wget on Ubuntu systems. It addresses scenarios where default settings cause delays due to unresponsive name servers. You will learn the exact command-line flags and configuration file edits needed to enforce these limits.
Using the Command Line Flag
The most immediate way to specify a custom DNS timeout is by using
the --dns-timeout option directly in your terminal. This
flag accepts a value in seconds. If the DNS resolution does not complete
within this timeframe, wget will abort the attempt.
Run the following command, replacing 10 with your
desired number of seconds and http://example.com with your
target URL:
wget --dns-timeout=10 http://example.comYou can combine this with other timeout options for stricter control. For example, to set a DNS timeout of 5 seconds and a connection timeout of 30 seconds, use:
wget --dns-timeout=5 --connect-timeout=30 http://example.comSetting a Permanent Configuration
To avoid typing the flag every time, you can set the default DNS timeout in your wget configuration file. This applies the setting to all future wget commands executed by your user account.
Open or create the
.wgetrcfile in your home directory:nano ~/.wgetrcAdd the following line to the file:
dns_timeout = 10Save the file and exit the editor.
Verifying Your Settings
To confirm that wget recognizes the timeout settings, you can use the verbose flag during a download attempt. This will display the timeout values being used during the connection process.
wget -v http://example.comIf the DNS lookup exceeds the specified limit, wget will return a “Timeout” error message specifically indicating that the DNS resolution failed within the allotted time.