A proxy server is used to redirect network traffic from a client to a target resource. It can perform caching, access control, anonymization, or bypass restrictions.
In this guide, we will look at how to set up a proxy on a client machine (Linux) and how to deploy a simple proxy server based on squid.
Configuring a proxy on the client
To configure a proxy server on the client side, you must specify the proxy address and port in the system or user environment variables.
Step 1. Setting environment variables
Add the following lines to your ~/.bashrc or ~/.bash_profile:
export https_proxy="http://:"
export ftp_proxy="http://:"
export no_proxy="localhost,127.0.0.1,::1"
Example:
export https_proxy="http://192.168.1.100:3128"
Apply changes:
Step 2. Installing a proxy in apt (for Debian/Ubuntu)
Create or edit the file /etc/apt/apt.conf.d/95proxies:
Acquire::https::Proxy "http://192.168.1.100:3128/";
Configuring a proxy server (Squid)
Squid is a popular caching proxy server with flexible configuration.
Step 1. Install Squid
For Debian / Ubuntu:
sudo apt install squid -y
For CentOS / RHEL:
Step 2. Configure Squid
Open the configuration file:
Find and edit the following parameters:
acl localnet src 192.168.1.0/24
http_access allow localnet
##Specify the port (default is 3128):
http_port 3128
Save the changes and restart the service:
sudo systemctl enable squid
Step 3. Checking the work
From the client, make a request:
If the proxy works, you will receive an HTML response from the site.
For authentication, add auth_param to the Squid configuration. The work logs are located in /var/log/squid/access.log. Proxy configuration is a useful tool for administering network traffic. You can set proxy server parameters both on the client and run your own server based on Squid. This will provide control, acceleration and filtering of connections.