How to use a proxy on the command line?

  • I can set my proxy username and password along with proxy settings in the proxy ui but these settings do not work on the command line. How can I use apps such as wget & ping on the command line with a proxy?

    Example Details:

    • username: 1234
    • pass: linux
    • proxy: proxy
    • port: 8080
  • Alex

    Alex Correct answer

    9 years ago

    The general scheme for the proxy URL is user:[email protected]:port

    You can set the environment variable http_proxy, https_proxy, ftp_proxy, socks_proxy or all_proxy

    In a bash shell, type this:

    export http_proxy="http://user:[email protected]:port"
    

    To persist this configuration, you can add it to /etc/environment or /etc/bash.bashrc, /etc/profile or to an individual user /home/user/.bashrc

    When I try to wget something it connects to the proxy server but then gets a 407 a says I need authentication

    wget should work using only the environment variable "http_proxy", but you can take a look at the link that @nitstorm posted. It says you can add proxy information to ~/.wgetrc

    If you did add that line to any of those files, you can unset your proxy by removing the same from them.

    It seems like a bad idea to add plaintext passwords into the command prompt, is this really the ideal solution?

  • To set Network proxy settings one can use gsettings

    gsettings changes the configuation files at DConf, which is the core settings for Ubuntu network proxy settings that you see in GUI by going to Network > Network Proxy

    Here is an example

    gsettings set org.gnome.system.proxy.http host ''
    gsettings set org.gnome.system.proxy.http port 0
    gsettings set org.gnome.system.proxy.http host ''
    gsettings set org.gnome.system.proxy.http port 0
    gsettings set org.gnome.system.proxy.ftp host ''
    gsettings set org.gnome.system.proxy.ftp port 0
    
    #Setting the Dynamic socks proxy 
    gsettings set org.gnome.system.proxy.socks host 'localhost'
    gsettings set org.gnome.system.proxy.socks port 1111
    
    #Setting Mode 
    gsettings set org.gnome.system.proxy mode 'manual'
    
  • You can't use proxies in the traditional sense with Ping. Ping works using the ICMP protocol.

    HTTP proxies will only work with HTTP traffic. You can proxy most traffic in most programs using a SOCKSify-wrapper. The "dante-client" package provides a socksify. I used this one on other occasions: https://github.com/gr0gmint/transucks

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM