Connecting Raspberry pi to proxy server

In this tutorial, I am going to tell you how to connect raspberry pi to the proxy server.

As most of the colleges have internet connection through local ethernet having its own proxy settings so for downloading packages on raspi you have to set up local proxy settings.

Here are the simple steps for connecting raspi to the proxy server.

  1. Open Root Terminal (Ctrl+Alt+T) and then type:
     
    1
    sudo nano /etc/apt/apt.conf.d/10proxy

    This command creates a file named 10proxy and then add proxy settings to this file by typing:
     
    1
    2
    Acquire::http::Proxy "http://username:password@proxy_server_address:port/";
    Acquire::https::Proxy "http://username:password@proxy_server_address:port/";

    and save it. You need to add in the exact format as written above (do not leave any semicolon or space).
  2. Again in Root Terminal  type:
     
    1
    sudo nano /etc/environment

    then add proxy settings to this file by typing:
     
    1
    2
    3
    export http_proxy="http://username:password@proxy_server_address:port/"
    export https_proxy="http://username:password@proxy_server_address:port/"
    export no_proxy="localhost, 127.0.0.1"

    and save it. If you want to know more about environment variables follow this link https://help.ubuntu.com/community/EnvironmentVariables
  3. Again in Root Terminal type:
     
    1
    sudo nano ~/.bashrc

    This opens bash file scroll to the end of the file and type:
     
    1
    2
    export http_proxy=http://username:password@proxy_server_address:port
    export https_proxy=https://username:password@proxy_server_address:port

    and save it. If you want to know more about .bashrc follow this link https://askubuntu.com/questions/540683/what-is-a-bashrc-file-and-what-does-it-do
  4. At last in Root Terminal type
     
    1
    source ~/.bashrc
  5. In order to download the file using sudo, update sudoers. First, open sudoers using
     
    1
    sudo visudo

    Then add the following line so that sudo is able to use the above environment variables
     
    1
    Defaults    env_keep+="http_proxy https_proxy no_proxy"

    Reboot pi for the changes to work.
  6. Then run the following command in the Root Terminal for checking if the internet is working
     
    1
    sudo apt-get update

Hope this helps. Enjoy!!!