How To Set Proxy For wget Command?

The wget command is a popular command used to download files via the command-line interface. Proxy is used as an intermediate host which redirects HTTP and HTTPS requests to the destination server. In some cases, we may require to set a proxy for the wget command. In this tutorial, we examine how to set a proxy for the wget command.

Set Proxy via Command

The proxy configuration for the wget command can be set via the command line interface during usage of the wget command. The -e use_proxy=yes http_proxy="proxy.linuxtect.com" option can be used to set a temporary proxy for the current command execution time. In the following example, we use the “proxy.linuxtect.com” host as a proxy in order to download “www.windowstect.com”.

$ wget -e use_proxy=yes -e http_proxy="proxy.linuxtect.com"  www.windowstect.com

Every protocol has its own usage and requires different proxy and proxy configurations. The HTTPS proxy can be configured like below for the command line interface usage.

$ wget -e use_proxy=yes -e https_proxy="proxy.linuxtect.com"  https://windowstect.com

Alternatively, an FTP proxy configuration can be set for the FTP protocol usage.

$ wget -e use_proxy=yes -e ftp_proxy="proxy.linuxtect.com"  ftp://windowstect.com

Set Proxy via User wgetrc Configuration File

As an advanced command, the wget provides configuration files. Every user has their own configuration file located in their home directories with the name of .wgetrc . If it doesn’t exist it can be created easily as a text file. This configuration file can be used to set proxy configuration for the wget command. Put the following lines for the related proxy configuration for the current user. The exact location of this configuration file is “~/.wgetrc“. This configuration is permanent and used every time the wget command is executed.

http_proxy="proxy.linuxtect.com"

https_proxy="proxy.linuxtect.com"

ftp_proxy="proxy.linuxtect.com"

Set Proxy via Global wgetrc Configuration File

Alternatively, the wget proxy configuration can be set for the whole system. The systemwide wget configuration file can be used which is located at “/etc/wgetrc“. The same configuration is put like a user proxy configuration file. This configuration is permanent and used every time the wget command is executed.

http_proxy="proxy.linuxtect.com"

https_proxy="proxy.linuxtect.com"

ftp_proxy="proxy.linuxtect.com"

Set Proxy For Operating System

Every Linux distribution provides the proxy configuration for the current user or system-wide the “~/.bash_profile” file is used to set proxy configuration for the current user. The “/etc/profile” file is used to set proxy configuration for all users in a system-wide scope.

export http_proxy=http://proxy.linuxtect.com
export https_proxy=https://proxy.linuxtect.com
export ftp_proxy=ftp://proxy.linuxtect.com

Leave a Comment