Search code examples
proxycentossudo

issue on making requests through proxy when using "sudo" command


Having problems when using the "sudo" command to make requests through a proxy server:

If i don't use sudo, the request goes through the proxy 10.139.212.25:8080

wget http://www.proxypronto com/

Connecting to 10.139.212.25:8080... connected.

Proxy request sent, awaiting response... 403 Forbidden (Blocked by Trustwave Secure Web Gateway)

2015-12-01 13:11:47 ERROR 403: Forbidden (Blocked by Trustwave Secure Web Gateway).

If I use sudo, the request does not go through the proxy 10.139.212.25:8080

sudo wget http://www.proxypronto com/

Resolving www.proxypronto com ... 96.31.64.186

Connecting to www.proxypronto com |96.31.64.186|:80... failed: Connection refused.

How can I make the requests to go through the proxy when using "sudo"?


Solution

  • Firstly, try the following comand:

    sudo http_proxy=$http_proxy wget "http://stackoverflow.com"
    

    At first glance, you need to add enviroment variables to sudoers config:

     sudo visudo
    

    add these lines

    Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy"
    

    or, use separate lines:

    Defaults  env_keep +="http_proxy"
    Defaults  env_keep +="https_proxy"
    Defaults  env_keep +="HTTP_PROXY"
    Defaults  env_keep +="HTTPS_PROXY"