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

I‘m behind a squid proxy server. How do I access internet via proxy server when I use wget, lynx and other utilities from a shell prompt on a Linux or Unix-like systems?

Linux and UNIX-like systems has environment variable called http_proxy. It allows you to connect text based session and/or applications via the proxy server. All you need is proxy server IP address (URL) and port values.[donotprint]
Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements None
Time 5m
[/donotprint] This variable is almost used by all utilities such as elinks, lynx, wget, curl and others commands.

ADVERTISEMENTS

Set http_proxy shell variable on Linux/OS X/Unix bash shell

Type the following command to set proxy server:
$ export http_proxy=http://server-ip:port/
$ export http_proxy=http://127.0.0.1:3128/
$ export http_proxy=http://proxy-server.mycorp.com:3128/

If the proxy server requires a username and password then add these to the URL. For example, to include the username foo and the password bar:
$ export http_proxy=http://foo:bar@server-ip:port/
$ export http_proxy=http://foo:bar@127.0.0.1:3128/
$ export http_proxy=http://USERNAME:PASSWORD@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
Add the following information:
export http_proxy=http://proxy-server.mycorp.com:3128/
OR
export http_proxy=http://USERNAME:PASSOWRD@proxy-server.mycorp.com:3128/
Save and close the file.

A note about enabling proxy access to a specific user

To enable proxy access for a specific user, add the lines user shell profile. For the default bash shell, the profile is the file .bash_profile. For example, enable proxy access for a specifc user called vivek, type:
$ vi $HOME/.bash_profile
OR
# vi /home/vivek/.bash_profile
Append the following line:
export http_proxy=http://USERNAME:PASSOWRD@proxy-server.mycorp.com:3128/
Save and close the file.

How do I use password protected proxy server using various command line options?

You can simply use wget command as follows:
$ wget --proxy-user=USERNAME --proxy-password=PASSWORD http://path.to.domain.com/some.html
Lynx command has the following syntax:
$ lynx -pauth=USER:PASSWORD http://domain.com/path/html.file
Curl command has following syntax:
$ curl --proxy-user user:password http://url.com/

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
42 comments… add one
  • Raphael May 9, 2008 @ 16:07

    For password protected proxies, I know it sometimes work directly included in http_proxy variable (ok it’s not so secure but it can make the work easier) :

    $ export http_proxy=http://user:password@server-ip:port/

    • Ajey Feb 8, 2011 @ 13:03

      Great work. This worked for me. Thanks.

    • RAFEE Oct 17, 2012 @ 6:07

      thank you , It is working fine :)

    • Varun Oct 4, 2014 @ 4:03

      My proxy login id contains ‘@’ what should I do now?
      eg.
      export http_proxy=http://abc:xyz@123@192.168.25.10:3128/
      Is there anyway to sort this out?

      P.S – I cannot request to change my password since It is associated with many other services.

      • irfan Jan 8, 2015 @ 8:52

        I am travelling in same board :(

        Did you found something?

      • DaveTashner Jan 8, 2015 @ 19:58

        Can you try:

        export http_proxy=http://abc:xyz%40123@192.168.25.10:3128/

        The @ sign can be replaced with the HTML identifier, which is %40.

        • Vachas Nov 9, 2015 @ 15:10

          Hey thanks, it worked for me :)

  • Slavko May 9, 2008 @ 16:52

    It is really correct?

    export export http_proxy=http://proxy-server.mycorp.com:3128/

    • Houssem Eddinn Kaabachi Mar 29, 2012 @ 10:50

      You have typed one more “export”. So you have to type only this
      export http_proxy=http://proxy-server.mycorp.com:3128/

  • 🐧 nixCraft May 9, 2008 @ 17:45

    Slavko,

    It was a typo. The faq has been updated.

  • Pravin Sep 18, 2008 @ 10:10

    Hi

    I tried this, but still, I cannot ping google or any other site from within the shell.. it says ‘destination host unreachable’..

    I’m using Redhat Enterprise 2.4..

    Any idea what might be going wrong?

    Thanks
    Pravin

    • kiran khairnar Dec 27, 2010 @ 13:26

      Until and unless you put the DNS server it won’t ping

  • Breno Apr 5, 2009 @ 19:23

    Very Good Man!
    Thanks!

  • la_89 Jun 5, 2009 @ 21:00

    above is good for for text based but for a simple linux user using firefox how can b a proxy server can b used like fedora core 8

  • Kyaw Soe Htet Jun 2, 2011 @ 9:54

    Hey how do I use a proxy server .My service provider blocked the proxy server websites.

  • ishtiyaq Oct 4, 2011 @ 11:59

    proxy setting syntax:
    export http_proxy=http://:@:/
    export ftp_proxy=http://:@:/

    it works for ishtiyaq :)

    • ishtiyaq Oct 4, 2011 @ 12:00

      export http_proxy=http://user:pasword@proxy-server.mycorp.com:port/
      export ftp_proxy=http://user:pasword@proxy-server.mycorp.com:port/

  • El Lobo Oct 26, 2011 @ 13:45

    Is there support for excluding sites or a regex from using the proxy?

    It seems that there is options for some commands, but is there a centralized option?

    I.E. something like:

    export no_http_proxy=*.ibm.com,10.0.0.0\24,…

  • arun Mar 3, 2012 @ 7:47

    wanna no can i download from a server which has a block on downloads by using linux

  • thisara Mar 6, 2012 @ 16:02

    Hi My case is little different because my user name is domain\username

    export http_proxy=http://domain\user:pasword@proxy-server.mycorp.com:port/
    i try above way but didn’t work it.Can any one help me about

  • printer305 Mar 28, 2012 @ 4:57

    use:
    export http_proxy=”http://user:password@proxy-ip:port”

    I think the previous people forgot to put the quotes.

    And another question, what if I have a proxy server enabled using the above command and want to remove it? What command do I have to use?

  • Sivaprakash Apr 5, 2012 @ 10:43

    Hey People,

    I got a doubt. My password is have a special character ‘@’. Due to this the character before the ‘@’ in my password are ignored. Can anyone include ‘@’ in your password and let me know if that works.

    Thanks,
    SP

    • srinivas Apr 29, 2013 @ 14:00

      Hi SP,

      I am also facing same problem .If you are out of this problem .
      Can you tell me the way to work it out.

      Thanks
      srinu

    • Tim Jul 18, 2013 @ 1:01

      try substituting ‘%40’ for ‘@’ in your password.

      • venkatesh Aug 20, 2015 @ 17:17

        For ‘%40’ is not working

  • droid.manic Apr 17, 2012 @ 6:10

    If you have a domain and you have a \ you have to escape it since \ it self is an escape char. You should do this:
    export http_proxy=http://domain\\user:pasword@proxy-server.mycorp.com:port/

  • Sachin May 4, 2012 @ 9:11

    hi,
    seems like for proxy
    Only below setting is working

    export http_proxy=

  • Fernando Aug 3, 2012 @ 15:03

    Hello!
    I need to configure complete internet access behind a proxy.
    I can access 80 port, but i need 443 and all ports for Skype for example.
    Thanks for anyone who can help me.

    Thanks

    • Vincent Sep 5, 2012 @ 17:57

      you can use ‘https_proxy’ with the same settings if you need proxy over https
      you can also use ‘ftp_proxy’ if needed, as well

  • titus Jan 18, 2013 @ 9:29

    Hi guys,How can i remove the proxy from elinks?i was accessing a server that needed validation and that worked fine,then when i went to a no proxy server,i couldint access interned due to earlier proxy setting,please help me with the command or file to remove the proxy settings.

  • Ambot Lang Mar 4, 2013 @ 22:33

    I just curious and my password doesn’t work because it has a character ‘@’ it generates error says unable to resolve host address especially using wget. How do i overcome it?Thanks

  • bartender Mar 5, 2013 @ 10:25

    cd /etc
    sudo gedit bash.bashrc

    once gedit opens the file in text form,goto the end and type the following,edit if already exists:

    export http_proxy=http://:@:8080/
    export ftp_proxy=http://:@:/

    example: lets say your username is simpson , password is bartrocks, the proxy server for your connection is http://10.1.1.32 ,port address is 8080, then to set up http proxy you have to write:

    export http_proxy=http://simpson:bartrocks@10.1.1.32:8080/

    Then Save and exit as you do for text files.Close and reopen the terminal and now you can use tools like wget to download web-pages from terminal :)

  • bartender Mar 5, 2013 @ 10:26

    cd /etc
    sudo gedit bash.bashrc

    once gedit opens the file in text form,goto the end and type the following,edit if already exists:

    export http_proxy=http://username:password@proxyserveraddress:8080/
    export ftp_proxy=http://username:password@serveraddress:port/

    example: lets say your username is simpson , password is bartrocks, the proxy server for your connection is http://10.1.1.32 ,port address is 8080, then to set up http proxy you have to write:

    export http_proxy=http://simpson:bartrocks@10.1.1.32:8080/

    Then Save and exit as you do for text files.Close and reopen the terminal and now you can use tools like wget to download web-pages from terminal :)

  • Nobody!! May 20, 2013 @ 5:32

    I’m a Student.. I’ve Lab Exams comming up.. Programs are too Lengthy..
    I’m Slow with Keyboard..

    Do the above Export Command need SuperUser Privilege??

  • abii Jun 20, 2013 @ 5:21

    export http_proxy=http://username:password@14@proxyserver.fid.cb:8080/

    I have “@” in my password, how to enter the password in this scenario? in double quotes?

    • srinivas Jul 10, 2013 @ 14:33

      you can use the above command ,if you want you can use double quotes.

      problem will come when you use ! or $ . then u have use \ like: password\!test

      in this case don’t use double quotes

  • Bilal Aug 6, 2013 @ 13:57

    I was trying to set permanently environment variable for proxy in /etc/profile as mentioned in guide. But it wont work even on reboot.
    I explored and figured out that users ~/.bashrc file is used for permanent save environment variable.

  • Prasoon Sep 16, 2013 @ 7:08

    How will you access the https sites from command line, as you only configured it for http as of now…is there a way out..

    Regards,
    Prasoon

  • Rahul R Upadhye Oct 14, 2013 @ 9:32

    @Tim

    Thanks you so much :)

    %40 works instead @ in the password….

  • mklim Nov 26, 2013 @ 3:25

    Hi,

    My shell script

    #!bin/bash

    export http_proxy=”http://example123.edu.my:80″

    Not working…any idea?

    Becoz it can execute but no changes made..:-(

  • Aries Jun 30, 2014 @ 9:47

    Hello folks,

    I’m using WebSphere Application server 8.0 which is hosted in the linux server, How can I enable the proxy so that the Applicaition server picks up the proxy settings

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.