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=http://10.10.26.254:80

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 https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/repodata/repomd.xml -e "use_proxy=on" -e "http_proxy=http://10.10.26.254:80"
Setting use_proxy (useproxy) to on
Setting http_proxy (httpproxy) to http://10.10.26.254:80

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=http://10.10.26.254:80

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

Note:

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

       /etc/security/pam_env.conf
           Default configuration file

       /etc/environment
           Default environment file

       $HOME/.pam_environment
           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/*
/etc/pam.d/password-auth
/etc/pam.d/su
/etc/pam.d/system-auth

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Connecting to %s