×
configure proxy on ubuntu

Generally Proxies are used in business networks to prevent attacks and unexpected access and intrusions into the internal networks.

A proxy server can act as an intermediary between the client computer and the internet, and allows you to implement Internet access controls like authentication for Internet connection, sharing Internet connections, bandwidth control and content filtering and blocking.

If your home or office network is behind a proxy server, then you will need to setup proxy in order to browse the Internet.

In this tutorial, we will show you several ways to configure proxy settings in Ubuntu desktop.

Setting Up Proxy with Ubuntu Desktop GUI

You can setup the proxy in Ubuntu Desktop by following the below steps:

1. Open System Settings in Ubuntu as shown below:

2. Click on the Network => Network Proxy as shown below:

3. In the Method drop down list, choose Manual, provide proxy server’s hostname or IP address and port number.

4. Click on Apply system wide to apply the changes.

 

Setting Up Proxy with Ubuntu Desktop Terminal

You can also set proxy settings using environment variables. There are several environment variables available in Linux to setup a proxy for HTTP, HTTPS and FTP.

You can setup proxy for temporary usage and permanent for single and all users.

The basic syntax of setting up proxy as shown below:

proxy_http=username:password@proxy-server-ip:port

Or

proxy_https=username:password@proxy-server-ip:port

Or

proxy_ftp=username:password@proxy-server-ip:port

Setting Up Permanent Proxy for Single User

You can setup a permanent proxy for a single user by editing the ~/.bashrc file:

First, login to your Ubuntu system with a user that you want to set proxy for.

Next open the terminal interface and edit the ~/.bashrc file as shown below:

nano ~/.bashrc

Add the following lines at the end of the file that matches with your proxy server:

export http_proxy=username:password@proxy-server-ip:8080
export https_proxy=username:password@proxy-server-ip:8082
export ftp_proxy=username:password@proxy-server-ip:8080
exprot no_proxy=localhost, 127.0.0.1

Save and close the file when you are finished.

Then to activate your new proxy settings for the current session, use the following command:

source ~/.bashrc

 

Setting Up Permanent Proxy for All User

You can also setup Permanent proxy for all users by setting up global variables in /etc/environment file.

To do so, login with root or administrative user and edit the /etc/environment file:

nano /etc/environment

Add the following lines at the end of the file that matches with your proxy server:

http_proxy="http://username:password@proxy-server-ip:8080/"
https_proxy="http://username:password@proxy-server-ip:8082/"
ftp_proxy="http://username:password@proxy-server-ip:8083/"
no_proxy="localhost,127.0.0.1,::1

Save and close the file when you are finished. You will need to logout and login again to activate the proxy settings.

 

Setting Up Proxy Temporary for Single User

In some cases, you don’t want to use proxy settings everytime. Then, you can set proxy environment variables temporary from the command line.

To setup and export the HTTP_PROXY variable temporary, open your terminal interface and run the following command:

export HTTP_PROXY=username:password@proxy-server-ip:8080

To setup and export the HTTPS_PROXY variable, run the following command:

export HTTPS_PROXY=username:password@proxy-server-ip:8081

Setting Up Proxy for APT

If you want to install some packages from the Ubuntu repository, you will need to create a separate proxy configuration file for APT.

To configure proxy settings for APT, you can simply create proxy configuration file under /etc/apt/apt.conf.d/.

nano /etc/apt/apt.conf.d/apt.conf

Add the following lines:

Acquire::http::Proxy "http://username:password@proxy-server-ip:8080/";
Acquire::https::Proxy "https://username:password@proxy-server-ip:8081/";

Save and close the file when you are finished. Now, you can install any package in your system.

You can also install the package by specifying your proxy settings with your command as shown below:

'http://username:password@proxy-server-ip:8080' apt-get install package-name

Conclusion

In the above guide, we learned how to setup proxy in Ubuntu using several methods. I hope you have now enough knowledge to setup proxy on Ubuntu system.