Use HTTP PROXY via command line in Linux/FreeBSD

Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable

Linux / UNIX has environment variable called http_proxy. It allows you to connect text based session / application via the proxy server. All you need is proxy server IP and port values. This variable is almost used by all utilities such as elinks, lynx, wget, curl and others.

Assuming that your HTTP Proxy IP address is 192.168.0.1 port 3128 (standard proxy port)

Set http_proxy shell variable

Type the following command to set proxy server:

$ export http_proxy=http://server-ip:port/
$ export http_proxy=http://192.168.0.1.1:3128/
$ export http_proxy=http://proxy-server.mycorp.com:3128/

How do I setup proxy variable for all users?

To setup the proxy environment variable as a global variable, open /etc/profile file:
$ vi /etc/profile

In order to make this proxy permanent, add the line to your ~/.profile or /etc/profile or ~/(bash|ksh|sh)rc file.

Add the following information:
export http_proxy=http://proxy-server.mycorp.com:3128/

Save and close the file.

How do I use password protected proxy server?

$ export HTTP_PROXY='http://username:password@192.168.0.1:3128'

You can simply use wget as follows:

$ wget --proxy-user=USERNAME --proxy-password=PASSWORD http://path.to.domain.com/some.html

Lynx has following syntax:
$ lynx -pauth=USER:PASSWORD http://domain.com/path/html.file

Curl has following syntax:
$ curl --proxy-user user:password http://url.com/

To unset this, use:

$ export HTTP_PROXY=' '


0 Response to "Use HTTP PROXY via command line in Linux/FreeBSD"

Post a Comment