Set up Proxy using http_proxy, https_proxy and no_proxy in Linux

Tested on Ubuntu 26.04 LTS (Resolute Raccoon)
Package curl
Applies to Ubuntu, Debian, Kali Linux, Linux Mint, Pop!_OS, Raspberry Pi OS, elementary OS, Zorin OS, Parrot OS, MX Linux, RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream, Fedora, Arch Linux
Privilege read-only (no elevated privileges)
Scope Learn how to configure http_proxy, https_proxy and no_proxy environment variables in Linux temporarily, permanently, system-wide, and for tools like curl, wget, apt, git and Docker.
Related guides curl
wget
How to set up http or https proxy with special characters in username and password
where to set environment variables in Linux
fix curl SSL certificate problem behind corporate proxy

Behind a corporate or campus firewall, many Linux tools reach the internet only through an HTTP proxy. Exporting http_proxy, https_proxy, and no_proxy is the fastest way to make command-line programs — curl, wget, apt, git, and others — use that path without editing each tool separately.

This guide walks through temporary and permanent setup, lowercase vs uppercase variable names, authenticated URLs, no_proxy bypass lists, and per-tool configuration when environment variables are not enough.


What is a proxy server?

A proxy sits between your machine and the internet. Your client sends the request to the proxy; the proxy forwards it and returns the response. On Linux servers and desktops, HTTP proxies are the most common type you configure with environment variables.

Common proxy categories:

  • HTTP proxies — web and API traffic over HTTP/HTTPS (most corporate setups).
  • SOCKS proxies — broader traffic types (mail, FTP, some apps).
  • SSL proxies — TLS between client and proxy endpoint.
  • Transparent proxies — caching or policy enforcement; they do not hide your origin IP.

For browser-based workflows, some teams use third-party proxy providers or fingerprint-isolated browsers paired with managed proxy endpoints. That use case is different from configuring http_proxy on a Linux shell, but the same proxy concepts apply.


Quick reference

Variable Typical use Example value
http_proxy / HTTP_PROXY HTTP traffic http://proxy.example.com:8080
https_proxy / HTTPS_PROXY HTTPS (often via CONNECT) http://proxy.example.com:8080
ftp_proxy / FTP_PROXY FTP http://proxy.example.com:8080
all_proxy / ALL_PROXY Catch-all for schemes http://proxy.example.com:8080
no_proxy / NO_PROXY Hosts that skip the proxy localhost,127.0.0.1,.example.com

For most HTTP proxy servers, both http_proxy and https_proxy use an http:// URL. See the next section on lowercase vs uppercase names before you debug a tool that “ignores” your exports.


http_proxy vs HTTP_PROXY: lowercase or uppercase?

There is no single standard. Many programs read lowercase names, many read uppercase, and some read both — but not always with the same rules.

Practical guidance:

  • Set lowercase http_proxy, https_proxy, and no_proxy first — they are the most widely documented.
  • Also set uppercase HTTP_PROXY, HTTPS_PROXY, and NO_PROXY when a daemon or language runtime might only check uppercase (some Java, Node, and Python stacks do).
  • curl is the important exception for HTTP: it uses lowercase http_proxy for http:// URLs and does not use HTTP_PROXY for HTTP because of historical CGI security concerns. It can use HTTPS_PROXY for HTTPS URLs.

On a clean shell, exporting only http_proxy sends HTTP requests through the proxy; exporting only HTTP_PROXY may let HTTP requests go direct while HTTPS still uses HTTPS_PROXY. Always verify with curl -v when behavior looks wrong.

Check what your current session has:

bash
env | grep -i proxy | sort

Sample output:

output
http_proxy=http://proxy.example.com:8080
https_proxy=http://proxy.example.com:8080
no_proxy=localhost,127.0.0.1

Set http_proxy and https_proxy temporarily

Exports apply to the current shell and child processes. They are lost when you close the terminal unless you add them to a startup file (covered below).

Without username and password

For a typical corporate HTTP proxy, use http:// for both variables:

bash
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"

Example with a literal IP:

bash
export http_proxy="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"

Use https://proxy.example.com:port in https_proxy only when the proxy service itself accepts HTTPS connections on that port. Most HTTP proxy appliances expect http:// even when the destination site uses HTTPS.

With username and password

bash
export http_proxy="http://username:password@proxy.example.com:8080"
export https_proxy="http://username:password@proxy.example.com:8080"

With domain, username, and password

bash
export http_proxy="http://mydomain\\user123:pass123@192.168.1.1:8080"
export https_proxy="http://mydomain\\user123:pass123@192.168.1.1:8080"

Verify the exports:

bash
echo "$http_proxy"
echo "$https_proxy"

Special characters in proxy URLs

Usernames and passwords that contain @, #, $, &, or / must be URL-encoded or the shell and the URL parser will misread the string. See How to set up http or https proxy with special characters in username and password for a full walkthrough.

Common encodings:

Character Encoded
@ %40
# %23
$ %24
: %3A
/ %2F
& %26

Example — password $&@pass becomes %24%26%40pass:

bash
export http_proxy="http://user123:%24%26%40pass@192.168.1.1:8080"
export https_proxy="http://user123:%24%26%40pass@192.168.1.1:8080"

Credentials in environment variables are visible to other processes on the same host (/proc/PID/environ). Prefer tool-specific credential files when your security policy requires it.


Set proxy environment variables permanently

Temporary export lines disappear after reboot. For persistence, use user-level shell startup files or system-wide files. More background on load order is in where to set environment variables in Linux.

Per user (~/.bashrc or ~/.profile)

bash
vi ~/.bashrc

Add at the end:

bash
export http_proxy="http://username:password@proxy.example.com:8080"
export https_proxy="http://username:password@proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,.example.com"

Apply immediately:

bash
source ~/.bashrc

On zsh, use ~/.zshrc instead. On fish: set -gx http_proxy 'http://proxy.example.com:8080'.

System-wide (/etc/environment)

/etc/environment is not a shell script — do not use export.

bash
sudo vi /etc/environment

Add:

text
http_proxy="http://username:password@proxy.example.com:8080"
https_proxy="http://username:password@proxy.example.com:8080"
no_proxy="localhost,127.0.0.1,.example.com"

Log out and back in (or reboot) for login sessions to pick up changes.

System-wide login shells (/etc/profile.d/)

For scripts that run at login on many distributions:

bash
sudo tee /etc/profile.d/proxy.sh <<'EOF'
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,.example.com"
EOF
sudo chmod 644 /etc/profile.d/proxy.sh

Bypass the proxy with no_proxy

no_proxy (and NO_PROXY) lists hosts that should connect directly. Values are usually comma-separated.

Local and loopback:

bash
export no_proxy="localhost,127.0.0.1,::1"

Internal DNS suffixes:

bash
export no_proxy="localhost,127.0.0.1,.example.com"

Private RFC1918 ranges (common in labs):

bash
export no_proxy="10.0.0.0/8,192.168.0.0/16,172.16.0.0/12"

Wildcards and mixed lists:

bash
export no_proxy="*.example.com,.example.org,127.0.0.0/8"
WARNING
no_proxy matching is not identical across every tool. Some programs support CIDR notation or * wildcards; others only match exact hostnames or domain suffixes. curl documents NO_PROXY with domain suffix, *, and CIDR support in recent versions; Docker and other clients may behave differently. Test with curl -v when in doubt.

Persist no_proxy in the same files as http_proxy (~/.bashrc, /etc/environment, or /etc/profile.d/proxy.sh).

Verify:

bash
echo "$no_proxy"

Use curl and wget with a proxy

curl

Without authentication:

bash
curl -x http://proxy.example.com:8080 http://example.com

With authentication:

bash
curl -U username:password -x http://proxy.example.com:8080 http://example.com

When environment variables are set, curl picks up lowercase http_proxy / https_proxy automatically. Force a direct connection to localhost when a proxy is exported:

bash
curl --noproxy '*' http://127.0.0.1:8080/

Use curl -v to see whether traffic goes through proxy.example.com or direct.

wget

One-off proxy on the command line:

bash
wget -e use_proxy=yes -e http_proxy=http://proxy.example.com:8080 http://example.com

With credentials in the URL:

bash
wget -e use_proxy=yes -e http_proxy=http://user:pass@proxy.example.com:8080 http://example.com

When http_proxy and https_proxy are exported, a plain wget http://example.com uses them. wget also reads ~/.wgetrc and /etc/wgetrc — if exports seem ignored, check for overrides there. See the GNU wget proxy manual.


Configure proxy for apt and apt-get

sudo apt update does not always inherit your user shell exports. Configure APT directly:

bash
sudo tee /etc/apt/apt.conf.d/95proxy <<'EOF'
Acquire::http::Proxy "http://proxy.example.com:8080/";
Acquire::https::Proxy "http://proxy.example.com:8080/";
EOF

Authenticated proxy in the URL:

text
Acquire::http::Proxy "http://user:pass@proxy.example.com:8080/";
Acquire::https::Proxy "http://user:pass@proxy.example.com:8080/";

If the proxy requires authentication and you do not want credentials inside /etc/apt/apt.conf.d/95proxy, use APT authentication configuration such as /etc/apt/auth.conf or /etc/apt/auth.conf.d/ where supported by your APT version and distribution. See Debian APT proxy configuration.

Test:

bash
sudo apt update

Remove the file when you no longer need a proxy: sudo rm /etc/apt/apt.conf.d/95proxy.

dnf and yum (RHEL, Rocky Linux, AlmaLinux)

Add to /etc/dnf/dnf.conf:

text
proxy=http://proxy.example.com:8080
proxy_username=user
proxy_password=pass

Then run sudo dnf makecache or sudo dnf update to test.


Configure proxy for Git

Git reads http.proxy and https.proxy from configuration — independent of shell exports unless you rely on environment variables.

Set globally:

bash
git config --global http.proxy http://proxy.example.com:8080
git config --global https.proxy http://proxy.example.com:8080

Unset:

bash
git config --global --unset http.proxy
git config --global --unset https.proxy

Verify:

bash
git config --global --get http.proxy

Configure proxy for Docker containers and builds

Environment variables in your shell do not configure the Docker daemon. For client operations (pull, build), Docker reads ~/.docker/config.json:

json
{
  "proxies": {
    "default": {
      "httpProxy": "http://proxy.example.com:8080",
      "httpsProxy": "http://proxy.example.com:8080",
      "noProxy": "localhost,127.0.0.1,.example.com"
    }
  }
}

Create or merge that block into ~/.docker/config.json. New builds and containers started by the CLI can inherit these values.

NOTE
This config affects containers and builds started by the Docker CLI. If docker pull itself fails because the Docker daemon cannot reach the registry, configure the Docker daemon proxy separately.
WARNING
Docker documents that proxy credentials in config.json are stored as plain text and may appear in container configuration inspect output. Use network policy and file permissions accordingly. See Docker proxy configuration.

Proxy with npm and pip

Node and Python tools often honor uppercase proxy variables:

bash
export HTTP_PROXY="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"
export NO_PROXY="localhost,127.0.0.1"
npm install express

For pip:

bash
pip install --proxy http://user:pass@proxy.example.com:8080 somepackage

Or export http_proxy / https_proxy before pip install in the same shell.


Why proxy works as a normal user but not with sudo

sudo resets most environment variables unless your administrator allows them through.

Preserve your environment for one command:

bash
sudo -E apt update

Or pass variables explicitly:

bash
sudo env http_proxy="$http_proxy" https_proxy="$https_proxy" no_proxy="$no_proxy" apt update

For permanent sudo access, a sysadmin can add to /etc/sudoers via visudo:

text
Defaults env_keep += "http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY"

Systemd services never read your ~/.bashrc. Add Environment=http_proxy=... in a service drop-in under /etc/systemd/system/your.service.d/ when a daemon needs a proxy.


Unset or remove proxy environment variables

To remove proxy settings from the current shell:

bash
unset http_proxy https_proxy ftp_proxy all_proxy no_proxy
unset HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY

Verify:

bash
env | grep -i proxy

If you configured proxy permanently, also remove the entries from ~/.bashrc, ~/.profile, /etc/environment, /etc/profile.d/proxy.sh, or the tool-specific configuration file.


Troubleshooting http_proxy and https_proxy issues

Problem What to check
curl ignores proxy for HTTP Use lowercase http_proxy; HTTP_PROXY alone may not affect HTTP in curl
curl to localhost fails Set no_proxy=localhost,127.0.0.1 or curl --noproxy '*'
sudo apt update ignores proxy Use /etc/apt/apt.conf.d/95proxy, sudo -E, or env_keep in sudoers
wget ignores exported vars Check ~/.wgetrc and /etc/wgetrc for conflicting http_proxy
Docker build cannot reach internet Set proxies in ~/.docker/config.json
Proxy works in shell but not in a service Add Environment= to systemd unit drop-in
407 Proxy Authentication Required Wrong user/password or encoding; confirm with curl -v -U user:pass -x http://proxy.example.com:8080 https://example.com
curl: (60) SSL certificate problem: unable to get local issuer certificate Corporate TLS inspection without the proxy root CA in the Linux trust store
apt still fails with auth proxy Use /etc/apt/auth.conf or /etc/apt/auth.conf.d/ instead of embedding secrets only in apt.conf

Summary

You can point Linux CLI tools at an HTTP proxy by exporting http_proxy, https_proxy, and no_proxy, using http:// URLs for both HTTP and HTTPS in most corporate setups, and mirroring lowercase names with uppercase when needed. Persist values in ~/.bashrc, /etc/environment, or /etc/profile.d/. Tools such as apt, Git, and Docker often need their own configuration or sudo -E — shell exports alone are not always enough.


References


Frequently Asked Questions

1. What is the difference between http_proxy and HTTP_PROXY?

Many programs read both forms, but behavior is not standardized. curl uses lowercase http_proxy for HTTP URLs and intentionally ignores HTTP_PROXY for HTTP because of historical CGI security rules; it can still use HTTPS_PROXY for HTTPS. Export both lowercase and uppercase if you need the widest tool compatibility.

2. Should https_proxy use http:// or https:// in the URL?

For most corporate HTTP proxies, set both http_proxy and https_proxy to http://proxy.example.com:port. HTTPS sites are tunneled with HTTP CONNECT through that proxy. Use https:// in the variable only when the proxy service itself listens with TLS.

3. Why does sudo apt update ignore my proxy?

sudo often drops environment variables from your shell. Use sudo -E, sudoers env_keep, or set the apt Acquire proxy directive in /etc/apt/apt.conf.d/ so apt does not depend on exported variables.

4. How do I bypass the proxy for localhost and internal hosts?

Set no_proxy (or NO_PROXY) to a comma-separated list such as localhost,127.0.0.1,.example.com,10.0.0.0/8. Matching rules differ by tool - curl, wget, apt, and Docker do not all parse CIDR or wildcards the same way.

5. How do I set a proxy for Git only?

Run git config --global http.proxy http://proxy.example.com:8080 and the same for https.proxy. Unset with git config --global --unset http.proxy when you no longer need it.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)