Type the following command to set proxy server in linux command line.
export http_proxy=http://1.2.3.4:3128/
Put a back tick character (`) before and after that command so that bash will execute the EXPORT command.
Note: 1.2.3.4 is your proxy server ip address and 3128 is the port for example.
To remove the variable value, use this command.
unset VARIABLE_NAME
Exmaple:
unset http_proxy
Try this:
#! /bin/sh
echo "# Generated by Application"
export http_proxy='http://$1/'
export ftp_proxy='http://$1/'
Note:
- your argument string($1) should be like this
user_id:pass@proxy.server.addr:proxy_port
- If you do not use userid and password then argument string($1) should be
proxy.server.addr:proxy_port
- you can export https_proxy and socks_proxy if you need.
- To see if your proxy is set or not use
env | grep proxy
To change system proxy using shell script try these:
gsettings set org.gnome.system.proxy mode 'manual'
gsettings set org.gnome.system.proxy.http enabled true
gsettings set org.gnome.system.proxy.http host 'proxy.server.addr'
gsettings set org.gnome.system.proxy.http port proxy_port
If you have user authentication pass and id
gsettings set org.gnome.system.proxy.http authentication-user 'user_id'
gsettings set org.gnome.system.proxy.http authentication-password 'password'
To use http_proxy for all other proxy
gsettings set org.gnome.system.proxy use-same-proxy true
To set bypass proxy for any host
gsettings set org.gnome.system.proxy ignore-hosts "['localhost', '127.0.0.1', 'all', 'other', 'hosts']"
Best Answer
System-wide proxies in Ubuntu Studio, Xubuntu and XFCE must be set via environment variables
Ubuntu Studio, like Xubuntu, uses the XFCE desktop environment which does not contain a graphical settings tool to set systemwide proxies (unlike the default Ubuntu desktop environment, Unity).
1. Set up the proxy/proxies for most programs
/etc/environment
file withgksudo leafpad
(or your favorite editor). This file stores the system-wide variables initialized upon boot.Add the following lines, modifying appropriately. You must duplicate in both upper-case and lower-case because (unfortunately) some programs only look for one or the other:
2. Then set up proxies for GTK3 programs such as Rhythmbox:
Some newer GTK3 programs such as Rhythmbox ignore the environment variables set above, and rely on Gnome settings instead. To make sure they are covered, open a terminal and paste the below line-by-line, modifying as appropriate:
3. Finally, set up the proxies for
apt-get
and Update ManagerThese programs will not obey the environment variables either. Create a file called
95proxies
in/etc/apt/apt.conf.d/
, and include the following:Finally, logout and reboot to make sure the changes take effect.
Sources: 1, 2, 3. See 1 in particular for additional help, including a script to quickly turn on/off the proxies.
Scripts for turning Proxy server on/off:
Disclaimer:: Before proceeding, note that I have tried this on Lubuntu 14.04 and it is IMPORTANT that before you run the mentioned scripts, the file
/etc/environment
should have only one line in it i.e. '$PATH...' and there should be nothing else in the file, else you might need to modify the script's code. These scripts set and unset the proxy as described above, but they rely upon file truncation and file appending to change/etc/environment
and/etc/apt/apt.conf.d/95proxies
files. So make sure that:1)
/etc/environment
contains only one line i.e. '$PATH:...'. And nothing else.2) The file
/etc/apt/apt.conf.d/95proxies
does not exist or does not have anything important in it.So! If you want to automate the process of turning proxy on and off without having to type allot. you can make two executable shell scripts
proxyon.sh
andproxyoff.sh
as:proxyon.sh:
proxyoff.sh
:How to use: Once you have made these scripts, make them executable, you may keep them anywhere you like. To turn on proxy all you have to do is go to the directory containing the 'proxyon.sh' script and then you need to type
sudo ./proxyon.sh {host} {port}
. As an example consider this:Where '10.2.20.17' is the proxy server's IP - you can also type something like myproxy.server.com - and '8080' is the port. After that just log out and login to your account, to make sure that everything is set. You can start using the internet or whatever then. And when you want to turn the proxy off, go to the directory containing 'proxyoff.sh' and type:
This will unset all of your proxies. Now logout and login again to switch to normal mode.