Complete steps to build a squid proxy server in linux

Complete steps to build a squid proxy server in linux

Preface

This article mainly introduces the relevant content about setting up a squid proxy server in linux. Let's take a look at the detailed introduction.

Experimental environment:

A Linux-based Web server that acts as an intranet web server (and also as an intranet client) 202.100.10.100

A Linux system acts as a gateway server, two network cards, and routing forwarding 192.168.133.131 and 202.100.10.1 is enabled

A Linux-based Web server acts as an external web server (and also as an external client) 192.168.133.131

Experimental steps:

1. Configure the IP addresses of the intranet web server, gateway server, and extranet web server, enable the routing forwarding of the gateway, turn off the firewall of the gateway, and test the connectivity between the intranet web server and the extranet web server to ensure that they can communicate with each other.

2. Install the web services of the intranet web server and the extranet web server, start the services, and create a new test page

3. Test the intranet client accessing the external web server, and the external client accessing the intranet web server

4. Intranet client accesses external web server

5. External network client accesses the internal network web server

Firewall SNAT and DNAT

1. Intranet client accesses external web server

2. View logs on the external web server

tail -f /var/log/httpd/access_log 

3. Set up address translation on the gateway

iptables -t nat -A POSTROUTING -s 192.168.133.0/24 -o eth2 -j SNAT --to-source 202.100.10.1

Or iptables -t nat -A POSTROUTING -s 192.168.133.0/24 -o eth2 -j MASQUERADE

4. Access the external web server from the intranet client again, and then check the external web server to see that the IP recorded in the log file is not the IP of the intranet client.

DNAT:

1. Set up on the gateway and map the intranet web server to the gateway's external network interface

iptables -t nat -A PREROUTING -i eth2 -d 202.100.10.1 -p tcp --dport 80 -j DNAT --to-destination 192.168.133.131

2. Access the gateway's external network interface IP (actually accessing the intranet web server)

3. View the log files of the intranet web server

Squid Proxy Server

1. Configure the squid proxy server on the gateway server and install squid, yum install -y squid

1.1 Traditional Proxy Server

Start the Squid service service squid start

Because the squid.conf configuration file allows all private IPs to pass by default

1.2 Set up the browser on the intranet client, join the proxy, and test

Check the log file on the external server and you can see that the IP is the IP of the proxy server.

1.3 Close the proxy server of the gateway server and test again. The following figure shows that the client accesses the external web server through the proxy server

2. Transparent Proxy Server

2.1 Configure on the gateway server, set up transparent proxy and enable cache, vim /etc/squid/squid.conf

http_port 192.168.133.130: 3128 transparent #192.168.133.130 is the intranet interface IP

cache_dir ufs /var/spool/squid 100 16 256

iptables -t nat -A PREROUTING -i eth1 -s 192.168.133.0/24 -p tcp --dport 80 -j REDIRECT --to-ports 3128 #-i interface is the intranet interface -s follows the intranet segment -j follows REDIRECT (redirection) 

2.2 Restart the squid service, then test on the intranet client, cancel the proxy set by the browser in the previous test, the transparent proxy does not need to be set on the client

2.3 View logs on the external web server

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of how to install Docker CE from a package under Linux
  • How to install and use Docker on Linux
  • Docker installation and configuration tutorial under Linux
  • Docker installation and usage tutorial under Linux
  • Detailed tutorial on how to install WordPress on Linux Docker
  • How to use crontab to add scheduled tasks in Linux
  • A simple method to implement Linux timed log deletion
  • Example explanation of alarm function in Linux
  • Simple steps to create a MySQL container with Docker
  • Install Docker on Linux (very simple installation method)

<<:  Install MySQL database 5.6 source code under Linux and change the login user password

>>:  vue-router hook function implements routing guard

Recommend

Detailed explanation of MySQL Explain

In daily work, we sometimes run slow queries to r...

Ubuntu 19.04 installation tutorial (picture and text steps)

1. Preparation 1.1 Download and install VMware 15...

Basic usage of custom directives in Vue

Table of contents Preface text 1. Global Registra...

The use of mysql unique key in query and related issues

1. Create table statement: CREATE TABLE `employee...

Detailed tutorial on installing MySQL database on Alibaba Cloud Server

Table of contents Preface 1. Uninstall MySQL 2. I...

Tutorial on resetting the root password of Mac MySQL

Disclaimer: This password reset method can direct...

How to use shell to perform batch operations on multiple servers

Table of contents SSH protocol SSH Connection pro...

How to prevent duplicate submission in jquery project

In new projects, axios can prevent duplicate subm...

Summary of Seven Basic XHTML Coding Rules

1. All tags must have a corresponding end tag Prev...

Uniapp realizes sliding scoring effect

This article shares the specific code of uniapp t...

The front-end page pop-up mask prohibits page scrolling

A problem that front-end developers often encount...

Docker meets Intellij IDEA, Java development improves productivity tenfold

Table of contents 1. Preparation before developme...

How to remove the blue box that appears when the image is used as a hyperlink

I recently used Dreamweaver to make a product pres...