Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Set Wget Connection Timeout in Linux?
Wget is a free GNU command-line utility for downloading files from web servers using HTTP, HTTPS, and FTP protocols. When downloading files over unreliable network connections, you may encounter timeouts that cause downloads to fail. Linux provides several wget timeout options to handle these situations effectively.
Installing Wget in Linux
Most modern Linux distributions come with wget pre-installed. To check if wget is available, open your terminal and type wget. If installed, you'll see "wget: missing URL". If not installed, you'll see "command not found".
Ubuntu and Debian
sudo apt install wget
CentOS and Fedora
sudo yum install wget
Wget Timeout Options
Wget provides four main timeout options to control different aspects of the connection process. The basic syntax is
wget [timeout-option] [URL]
DNS Timeout (--dns-timeout)
Sets the maximum time allowed for DNS lookups. If DNS resolution takes longer than the specified time, the operation fails.
wget --dns-timeout=5 https://example.com/file.zip
This command allows 5 seconds for DNS lookup. If DNS resolution exceeds this time, wget terminates the operation.
Connect Timeout (--connect-timeout)
Specifies the maximum time to wait for establishing a TCP connection to the server.
wget --connect-timeout=3 https://example.com/file.zip
If the TCP connection cannot be established within 3 seconds, wget abandons the attempt.
Read Timeout (--read-timeout)
Controls how long wget waits for data transmission from the server. This is useful when the server becomes unresponsive during file transfer.
wget --read-timeout=10 https://example.com/file.zip
If no data is received for 10 seconds during download, wget will timeout and potentially retry the connection.
Network Timeout (--timeout)
Sets a universal timeout value that applies to all network operations (DNS, connect, and read). This option overrides individual timeout settings.
wget --timeout=15 https://example.com/file.zip
All network operations will timeout after 15 seconds using this global setting.
Combining Timeout Options
You can combine multiple timeout options for fine-grained control over different connection phases
wget --dns-timeout=2 --connect-timeout=5 --read-timeout=30 https://example.com/largefile.zip
Common Use Cases
| Scenario | Recommended Setting | Purpose |
|---|---|---|
| Slow DNS servers | --dns-timeout=10 | Allow more time for DNS resolution |
| Unreliable connections | --connect-timeout=15 | Handle connection establishment delays |
| Large file downloads | --read-timeout=60 | Prevent timeouts during data transfer |
| General purpose | --timeout=30 | Universal timeout for all operations |
Conclusion
Wget timeout options provide essential control over network operations when downloading files in unreliable network environments. Understanding these settings helps optimize downloads by preventing premature failures while avoiding excessive wait times for unresponsive servers.
