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

Solution 1:

The general scheme for the proxy URL is user:password@host: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:password@host: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

Solution 2:

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'