iptables 使用squid安装代理
一、先准备两台虚拟机:一台客户端服务器,一台squid代理服务器
二、先关闭防火墙:
systemctl stop firewalld
setenforce 0
三、在两台虚拟机上执行安装:
1、使用 yum install iptables-services 安装或更新服务
2、使用systemctl enable iptables 启动iptables
3、systemctl start iptables 打开iptables
4、service iptables save可以操作了
四、在代理服务器上配置:
1、安装squid
yum install squid -y
yum install iptables-services
2、编辑squid配置文件
vim /etc/squid/squid.conf
在配置文件中添加:
acl local src 192.168.92.0/24 #允许192.168.92.0/24网段内所有客户机访问代理服务器
http_access allow localnet #该记录一定要添在deny all之前
http_port 3128
3、防火墙配置
systemctl stop firewald.service
systemctl disable firewald.service
yum install iptables-services iptables-devel -y
systemctl enable iptables.service
systemctl start iptables.service
iptables -I INPUT 1 -s 192.168.92.0/24 -p tcp --dport 3128 -j ACCEPT
iptables -I INPUT 2 -p tcp --dport 3128 -j DROP
4.启动squid服务
systemctl start squid
systemctl enable squid
五、在客户端上配置:
1、客户端配置正向代理
export http_proxy=http://192.168.92.169:3128 #192.168.92.169是代理服务器ip
export https_proxy=http://192.168.92.169:3128
echo "export http_proxy=http://192.168.92.169:3128" >>/etc/profile
echo "export https_proxy=http://192.168.92.169:3128" >>/etc/profile
2、测试http
wget http://www.cmake.org/files/v3.3/cmake-3.3.1.tar.gz
3.代理服务器上查看日志/var/log/squid/access.log
4.测试https
wget https://codeload.github.com/gflags/gflags/tar.gz/v2.1.2
5.在代理服务器上查看日志/var/log/squid/access.log
六、查看客户端结果:
七、服务端结果: