Introduction
Using a proxy server as an internet access intermediary is a common business scenario. However, personal users can also benefit from increased network security, privacy, and speed provided by proxies.
In this tutorial, you will learn how to set up your Ubuntu 20.04 system to work with a proxy server.
Prerequisites
- Ubuntu 18.04 or later
- Access to terminal with sudo privileges
- Proxy info (web or IP address, username, and password)
Note: If you wish to set up one of your machines to act as a proxy, refer to How to Set Up & Install Squid Proxy Server on Ubuntu.
Setting Up Proxy with Ubuntu Desktop GUI
1. To access proxy settings using the Ubuntu GUI, open Ubuntu’s main Settings.
2. Select the Network setting in the menu on the left side of the window.
3. Then, click the cog in the Network Proxy section.
4. A Network Proxy dialogue appears. Choose Manual and enter your proxy info into the fields below.
5. Exit the dialogue and Ubuntu will automatically apply the proxy settings.
Setting up Proxy With Ubuntu Desktop Terminal
Use the command line interface for more granular control of proxy settings. This allows you to:
- Make temporary or permanent changes to the configuration.
- Set up proxy for a single user or for all users.
Setting Up Temporary Proxy for a Single User
A temporary proxy connection resets after a system reboot. To establish such a connection for the current user, use the export
command.
The syntax for establishing a temporary proxy connection is:
export HTTP_PROXY=[username]:[password]@[proxy-web-or-IP-address]:[port-number]
export HTTPS_PROXY=[username]:[password]@[proxy-web-or-IP-address]:[port-number]
export FTP_PROXY=[username]:[password]@ [proxy-web-or-IP-address]:[port-number]
...
export NO_PROXY=localhost,127.0.0.1,::1
Provide the proxy address (web or IP), followed by the port number. If the proxy server requires authentication, add your proxy username and password as the initial values.
This is what the set of commands should look like in terminal:
The purpose of the NO_PROXY
line is to tell the system that local traffic should ignore the proxy.
Setting Up Permanent Proxy for a Single User
As stated above, proxy settings configured through a terminal window reset after you reboot your system. To make permanent changes for a single user, edit the .bashrc file.
1. Open the file with a text editor of your choice:
sudo nano ~/.bashrc
2. Now add the following lines at the bottom of the .bashrc file:
export HTTP_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export HTTPS_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export FTP_PROXY="[username]:[password]@ [proxy-web-or-IP-address]:[port-number]"
...
export NO_PROXY="localhost,127.0.0.1,::1"
3. Save and exit the file.
4. Then, run the following command in to apply the new settings to the current session:
source ~/.bashrc
Setting Up Permanent Proxy for All Users
To permanently set up proxy access for all users, you have to edit the /etc/environment file.
1. First, open the file in a text editor:
sudo nano /etc/environment
2. Next, update the file with the same information you added to the .bashrc file in the previous scenario:
export HTTP_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export HTTPS_PROXY="[username]:[password]@[proxy-web-or-IP-address]:[port-number]"
export FTP_PROXY="[username]:[password]@ [proxy-web-or-IP-address]:[port-number]"
...
export NO_PROXY="localhost,127.0.0.1,::1"
3. Save the file and exit. The changes will be applied the next time you log in.
Setting Up Proxy for APT
On some systems, the apt command-line utility needs a separate proxy configuration, because it does not use system environment variables.
1. To define proxy settings for apt, create or edit (if it already exists) a file named apt.conf in /etc/apt directory:
sudo nano /etc/apt/apt.conf
2. Add the following lines to the file:
Acquire::http::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
Acquire::https::Proxy "http://[username]:[password]@ [proxy-web-or-IP-address]:[port-number]";
3. Save the file and exit. The configuration will be applied after a reboot.
Conclusion
This tutorial provided instructions on how to set up proxy settings on Ubuntu 20.04. You should now know how to make temporary and permanent changes to your system’s proxy configuration, for a single user or for the entire system.
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/224262.html