Strange problem with http_proxy environment variable

Strange problem I ran into today: http_proxy environment at shell level doesn’t work no matter I use curl or wget.

export http_proxy=

Curl works when I specify the proxy setting with “–proxy” or “-x”. With “-v” verbose option, I can see curl still tries to connect to the destination directly when http_proxy is set.

For wget, no matter I use ~/.wgetrc file or put proxy in the command directly with use_proxy=on (using -e option), none works.

When set use_proxy and http_proxy in ~/.wgetrc file, I don’t see wget uses the proxy. When put the options in the command line, it seems they are picked up:

# wget --debug -e "use_proxy=on" -e "http_proxy="
Setting use_proxy (useproxy) to on
Setting http_proxy (httpproxy) to

DEBUG output created by Wget 1.12 on linux-gnu.

However, when I set ALL_PROXY environment variable, both curl & wget works. And I see curl connects to proxy first with verbose output.

export ALL_PROXY=

I tried on different servers with OL6, OL7 and they all behave the same. Totally lost why http_proxy is not picked up.


You may see http_proxy defined in the file /etc/environment for RHEL7/OL7 above as a permanet proxy. But be aware that /etc/environment is not part of POSIX and it’s NOT a shell script. It belongs to PAM (Pluggable Authentication Module), and only programs compiled with PAM support are able to use it (primarily login systems, which subsequently start the shell or user environment). This means it isn’t even read by your shell.

In other words, if you want http_proxy to be set in your shell for all users, better add a script under /etc/profile.d. Or use local ~/.bash_profile & ~/.bashrc for individual users.

If you “man pam_env”, you will see files used for PAM environment:

man pam_env

           Default configuration file

           Default environment file

           User specific environment file

And you can see the programs using /etc/environment with grep -l pam_env /etc/pam.d/*.

root@joetest:/boot# grep -l pam_env /etc/pam.d/*

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s