Are you curious about how a proxy server works? Proxy servers useful to control and monitor internet traffic in your network. In this article, we will provide a step-by-step guide on how to create proxy server on Linux – Squid.
Table of Contents
Regarding proxy servers for Linux, many options are available in the market. However, one of the best proxy servers for Linux is to create one yourself. Doing so gives you complete control over the server’s configuration and security, ensuring that it meets your specific needs.
So creating your own proxy server can be a cost-effective option in the long run, as you won’t have to pay for a third-party service.
How does a Proxy Server Work?
Before we dive into creating a proxy server, let’s briefly explain how a proxy server works. A proxy server acts as an intermediary between a client and a server. When a client requests a server, the request is first sent to the proxy server. The proxy server then forwards the request to the server and receives the response. The response is then sent back to the client by the proxy server.
This process allows the proxy server to act as a middleman between the client and server, and it can control and monitor traffic between the two.
How to Create Proxy server
Before we begin, make sure you have the following prerequisites –
- Linux server with root access
- Static IP address
- Basic Linux command line knowledge
Step 1: Install Squid
Squid is one of the best open-source proxy servers available for Linux. To install Squid, run the following command –
sudo apt-get install squid
This command downloads and installs Squid.
Step 2: Configure Squid
Once Squid is installed, we need to configure it as a proxy server. Squid’s configuration file is located at
/etc/squid/squid.conf. Open this file with text editor such as nano and make the following changes –
Set the HTTP and HTTPS port
By default, Squid listens on port 3128 for HTTP traffic. You can change this port by modifying the following lines in the configuration file –
http_port 3128 https_port 3129
In this example, we have changed the HTTP port to 3128 and added an HTTPS port at 3129.
Set allowed IP addresses
Next, we need to specify which IP addresses can use the proxy server. By default, Squid denies all traffic, so we need to add rules to allow traffic from specific IP addresses. You can add the following lines to allow traffic from a single IP address –
acl mynetwork src 192.168.0.0/24 http_access allow mynetwork
In this example, we have allowed traffic from the IP address range
Finally we can enable logging for Squid by adding the following lines to the configuration file –
access_log /var/log/squid/access.log squid
This will create a log file at
/var/log/squid/access.log to track all incoming requests.
Step 3: Start Squid
Once the configuration file has been updated, save and close the file. Start Squid by running the following command –
sudo systemctl start squid
This will start the Squid proxy server.
Step 4: Test the Proxy Server
To test the proxy server, you can configure your web browser to use the IP address of your Linux server as the proxy server. Open your browser’s network settings and add the IP address of your Linux server with the HTTP port number (e.g.,
192.168.0.1:3128) as the proxy server. Once configured, try browsing the web to ensure the proxy server is working.
Proxies are a valuable tool for improving network security, privacy, and performance. In this tutorial, we looked at the basics of proxies and how to create a proxy server in a Linux environment. Whether you are using a Linux desktop or server, setting up a proxy server is a straightforward process. It can provide significant benefits for your network.