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 a proxy for wget on Linux?
Wget is a Linux command-line utility used to retrieve files from the World Wide Web (WWW) using protocols like HTTP, HTTPS, and FTP. It is a freely available package that can be downloaded and installed on any Linux-supporting architecture.
One of the key features of wget is its ability to automatically resume downloading where it left off in case of network issues. It also supports recursive downloads and will keep trying to download files until they are retrieved completely.
Installing wget
For Ubuntu/Debian
sudo apt-get install wget
For CentOS/RHEL/Fedora
sudo yum install wget
Basic wget Example
Here's a simple example of downloading a file using wget ?
wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz
immukul@192 linux-code % wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz --2021-07-11 12:12:20-- http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20 Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 446966 (436K) [application/x-gzip] Saving to: 'wget-1.5.3.tar.gz' wget-1.5.3.tar.gz 100%[========================================================>] 436.49K 285KB/s in 1.5s 2021-07-11 12:12:23 (285 KB/s) - 'wget-1.5.3.tar.gz' saved [446966/446966]
Setting Proxy for wget
When working behind a corporate firewall or need to route traffic through a specific proxy server, you can configure wget to use a proxy. There are several methods to achieve this.
Method 1: Command-Line Options
You can specify proxy settings directly in the wget command using the -e option ?
wget -e use_proxy=yes -e http_proxy=localhost:8080 http://example.com/file.zip
For HTTPS URLs, use the https_proxy option ?
wget -e use_proxy=yes -e https_proxy=localhost:8080 https://example.com/file.zip
Method 2: Environment Variables
Set proxy environment variables before running wget ?
export http_proxy=http://proxy.company.com:8080 export https_proxy=http://proxy.company.com:8080 export ftp_proxy=http://proxy.company.com:8080 wget http://example.com/file.zip
Method 3: Configuration File
Create or edit the ~/.wgetrc file to set permanent proxy settings ?
use_proxy=yes http_proxy=localhost:8080 https_proxy=localhost:8080 ftp_proxy=localhost:8080
Proxy Authentication
If your proxy requires authentication, include username and password in the proxy URL ?
wget -e use_proxy=yes -e http_proxy=http://username:password@proxy.company.com:8080 http://example.com/file.zip
Bypassing Proxy for Specific Domains
To bypass the proxy for certain domains, use the no_proxy setting ?
export no_proxy=localhost,127.0.0.1,.local.domain wget http://localhost/file.zip
Comparison of Proxy Methods
| Method | Scope | Persistence | Best For |
|---|---|---|---|
| Command-line options | Single command | Temporary | One-time downloads |
| Environment variables | Current session | Session-based | Multiple downloads in same session |
| Configuration file | All wget commands | Permanent | Regular proxy usage |
Conclusion
Setting a proxy for wget can be accomplished through command-line options, environment variables, or configuration files. Choose the method that best fits your use case ? temporary proxy settings for single downloads or permanent configuration for regular use. The configuration file approach is most convenient for users who consistently work behind a proxy.
