squid代理介绍----透明代理

一、透明代理

1.拓扑图

在这里插入图片描述

2.环境

在这里插入图片描述

  • 客户端不需要指定代理服务器的ip地址和监听端口号,感觉是直接和公网通信,但是必须把网关地址指向代理服务器的内网接口ip地址。
  • 特点:对用户是透明的,即用户意识不到防火墙的存在。常用在服务器集群前端。
  • 要想实现透明模式,防火墙必须在没有IP地址的情况下工作,不需要对其设置IP地址,用户也不知道防火墙的IP地址。
    优点:既增加了网络的安全性,又降低了用户管理的复杂程度。

3.部署操作

1.打开浏览器–设置页面–首选项–高级–网络–连接设置—不使用代理

2.关闭squid服务

[root@squid ~]# systemctl stop squid   关闭服务

3.开启路由功能

[root@squid ~]# vi /etc/sysctl.conf 
[root@squid ~]# sysctl -p   
添加
net.ipv4.ip_forward=1

在这里插入图片描述
4.设置网管指向squid同网段的ip

[root@client ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
[root@client ~]# systemctl restart network
[root@client ~]# route -n    #查看路由

在这里插入图片描述
5.web1上添加路由

[root@web1 ~]# route add -net 192.168.1.0/24 gw 192.168.2.10  
[root@web1 ~]# route -n  

在这里插入图片描述
6.测试客户机访问web服务器

[root@client ~]# ping 192.168.2.11
[root@client ~]# ping 192.168.2.12

在这里插入图片描述
配置透明代理服务器
在squid上配置
1.编辑配置文件

[root@squid ~]# vi /etc/squid.conf
[root@squid ~]# systemctl start squid       #启动squid服务
[root@squid ~]# netstat -anpt | grep squid     #查看端口状
修改
http_port 192.168.1.10:3128 transparent     #接收客户端的地址

在这里插入图片描述
在这里插入图片描述

[root@squid ~]# iptables -F   清空所有规则
[root@squid ~]#  iptables -t nat -I PREROUTING -i ens33 -s 192.168.1.0/24 -p tcp --dport=80 -j REDIRECT --to 3128
#插入一条规则入站时,入站网卡ens33源地址192.168.1.0/24协议名tcp目标端口80,重定向到3128端口
[root@squid ~]#  iptables -t nat -I PREROUTING -i ens33 -s 192.168.1.0/24 -p tcp --dport=443 -j REDIRECT --to 3128
[root@squid ~]# iptables -I INPUT -p tcp --dport=3128 -j ACCEPT  
[root@squid ~]# iptables -t nat -L  #查看nat表中的规则
[root@squid ~]# iptables -L   #列出所有表中的链,指定链中的规则

在这里插入图片描述
客户机访问之前先确定web1、web2的apache服务有没有开启
web1

[root@web1 ~]# systemctl start httpd
[root@web1 ~]# curl http://localhost
<h1>This is Web1</h1>

web2

[root@web2 ~]# systemctl start httpd
[root@web2 ~]# curl http://localhost
<h1>This is Web2</h1>

测试:
192.168.2.11
192.168.2.12
在这里插入图片描述
在这里插入图片描述
查看日志

[root@web1 ~]# tail -f /var/log/httpd/access_log 

在这里插入图片描述

[root@web2 ~]# tail -f /var/log/httpd/access_log 

在这里插入图片描述
在squid上查看日志

[root@squid ~]# tail -f /usr/local/squid/var/logs/access.log 

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/F2001523/article/details/111465242