实验描述
我们现在用Ip或者域名访问到的互联网页面底层是由很多的服务器在运作的,但是我们不可能直接去访问服务器的Ip来访问页面,因此就出现了代理IP,代理IP主要的作用是将私网IP进行伪装,伪装成公网IP,这样互联网允许访问,我们就可以正常访问页面了,这次的实验内容是将一台物理机的IP伪装成另一台物理机的Ip,用另一台物理机的身份去访问互联网,从小的层面上实现了SNAT
环境
| 物理机 | IP |
|---|---|
| 客户端 | 192.9.191.31 |
| squid代理 | 192.9.191.30 |
代理服务器配置
1 安装squld
yum install squid -y
yum install squid -y
yum install iptables-services
2 编辑squid 配置文件
vim /etc/squid/squid.conf
acl local src 192.9.191.0/24 //允许192.9.191.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.9.191.0/24 -p tcp --dport 3128 -j ACCEPT
iptables -I INPUT 2 -p tcp --dport 3128 -j DROP
4 安装openssl
yum install openssl
5 启动squid服务
客户端配置
inux客户端配置正向代理
export http_proxy=http:/192.9.191.30:3128 \\192.9.191.30是代理服务器ip
export https_proxy=http://192.9.191.30:3128
echo "export http_proxy=http://192.9.191.30:3128" >>/etc/profile
echo "export https_proxy=http://192.9.191.30:3128" >>/etc/profile
测试http
wget http://www.cmake.org/files/v3.3/cmake-3.3.1.tar.gz
代理服务器上查看日志/var/log/squid/access.log
测试https
wget https://codeload.github.com/gflags/gflags/tar.gz/v2.1.2
在代理服务器上查看日志/var/log/squid/access.log