Home Linux Commandline Tips How to Set Wget Connection Timeout in Linux

How to Set Wget Connection Timeout in Linux

Working under a Linux operating system environment grants you the flexibility of choosing how you wish to download your files from a transparent URL. Most users are familiar with Linux’s interactive approach to such file download.

This interactive approach relates to the use of a web browser where a user clicks on an availed download button and waits for the file download to start until it successfully finishes.

The Wget free GNU utility provides an alternative approach for downloading network-based files via a non-interactive or command-line environment. The non-interactive attribute associated with the Wget utility implies that your file downloads can take place or continue in the background without the system user being logged in on the Linux OS.

Wget utility can retrieve your to-be downloaded files via FTP, HTTP, and HTTPS protocols. It also supports file downloads via HTTP proxies. This article guide will address how to set Wget timeout in a Linux operating system environment while downloading files.

Install Wget in Linux

Before we figure out how to set Wget timeout in Linux, we need to make sure that the Wget GNU utility exists in your Linux OS environment. Reference the following installation commands in relation to the Linux operating system distribution you are using.

$ sudo apt install wget         [On Debian, Ubuntu and Mint]
$ sudo yum install wget         [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a net-misc/wget  [On Gentoo Linux]
$ sudo pacman -S wget           [On Arch Linux]
$ sudo zypper install wget      [On OpenSUSE]    

Wget Usage in Linux

The standard syntax for using the Wget GNU utility is as follows:

$ wget [option]… [URL]...

Before we set the Wget timeout in a Linux environment, we have to be specific with the timeout option we want as there are several: --dns-timeout, --connect-timeout, --read-timeout, and --timeout.

All these timeout options are specified in seconds. To understand the above timeout options, let us highlight them one by one.

Wget –dns-timeout Option

The wget --dns-timeout option is specific to the maximum time associated with a DNS lookup.

$ wget --dns-timeout=5 https://github.com/zethra/servy/blob/master/README.md 

The option --dns-timeout=5 implies that DNS lookups exceeding 5 seconds are considered fails.

Wget DNS Timeout Option
Wget DNS Timeout Option

Wget –connect-timeout Option

The wget --connect-timeout option is associated with TCP connections.

$ wget --connect-timeout=3  https://github.com/zethra/servy/blob/master/README.md

The above wget command option (--connect-timeout=3) implies that a TCP connection taking more than 3 seconds to be established will be aborted.

Wget Connect Timeout Option
Wget Connect Timeout Option

Wget –read-timeout Option

The wget --read-timeout option is useful in scenarios where a user has resumed to read/download data/files from a server but a transmission gap occurs forcing Wget to wait on the server.

Instead of dealing with this unknown wait time, you can specify your own wait time with --read-timeout which when exceeded, the file download will be aborted and restarted.

$ wget --read-timeout=3 https://github.com/zethra/servy/blob/master/README.md
Wget Read Timeout Option
Wget Read Timeout Option

By default, this value is usually set to 900 seconds.

Wget –timeout Option

The wget -timeout option is also interpreted as the network timeout and its value is by default inherited by other Wget timeout options. For instance, if its value is x then --dns-timeout, --connect-timeout, and --read-timeout values will assume the x value too.

$ wget --timeout=6 https://github.com/zethra/servy/blob/master/README.md
Wget Timeout Option
Wget Timeout Option

The Wget GNU utility timeout options are effective in initiating and completing file downloads in network environments with unstable connections/servers.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.