Powered By

Powered by Blogger

Senin, 11 Oktober 2010

How To Set A Proxy For The Terminal [Quick Linux Tip]

If you set a global proxy in Gnome (I'm not sure about other desktop environments), you'll notice that the terminal ignores it. Here's how to set a proxy for the terminal:

For a HTTP proxy, simply run the following command in a terminal:
export http_proxy='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/'

For a secure connection (HTTPS), use:
export https_proxy='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/'

Obviously, replace everything with your username, password, proxy ip and port. If the proxy does not require an username and password, you can skip the "YOUR_USERNAME:YOUR_PASSWORD@" part.

Example

Here is an example. Using TOR (installation instructions for Ubuntu 10.10), to set a HTTP and HTTPS proxy for the current terminal session, run:
export http_proxy='http://localhost:8118'
export https_proxy='http://localhost:8118'

Note that if you close the terminal (or terminal tab where you've ran these commands), the proxy will not work anymore. To make these changes permanent, add these commands to your ~/.bashrc file.

How to check if the terminal proxy is working

To see if the proxy you've just set actually works, run the following command (firstly, make sure you have curl installed: sudo apt-get install curl):
curl icanhazip.com
Yes, a funny domain name but it does the job =)

The above command should return your new IP (if you don't know your initial IP, firstly run the curl command, then set the proxy and finally run the curl command again to see if the proxy works).

Reset the proxy

If you want to unset a proxy, you can simply close the terminal or alternatively, run the following commands:
unset http_proxy
unset https_proxy


See also: how to get GIT working behind a firewall (use it if the GIT port is blocked by your ISP/network admin).

Tidak ada komentar:

Posting Komentar