centos 下squid透明代理

squid部署服务器

在这里插入图片描述
测试内网主机(网卡选用仅主机模式)
网关配置为squid服务器的内网地址网关192.168.164.130 ,dns设置为外部dns 8.8.8.8

在这里插入图片描述

iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j REDIRECT –to-ports 3128
iptables -t nat -A POSTROUTING -p icmp  -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -p udp  -o eth1 -j MASQUERADE



[root@localhost ~]iptables -F
[root@localhost ~]#  iptables -t nat -A PREROUTING -i ens33 -p icmp -s 192.168.164.0/24 -j REDIRECT --to-ports 3128   #ping命令
[root@localhost ~]#  iptables -t nat -A PREROUTING -i ens33 -p tcp --dport 80 -s 192.168.164.0/24 -j REDIRECT --to-ports 3128


"""代理https出现问题未解决"
[root@localhost ~]#  iptables -t nat -A PREROUTING -i ens33 -p tcp --dport 443 -s 192.168.164.0/24 -j REDIRECT --to-ports 3128


	设置转发
			vim /etc/sysctl.conf 
			添加 net.ipv4.ip_forward=1
			sysctl -p
	设置使用外部dns
[root@localhost ~]#  iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 8.8.8.8
把所有的地址的53端口的请求自动转到一个公网的DNS服务器上



			iptables  -A FORWARD -p udp --dport 53 -j ACCEPT
								iptables -t nat -A POSTROUTING  -o ens37 -j MASQUERADE
[root@localhost ~]#  iptables -t nat -A POSTROUTING -p udp --dport 53 -o ens37 -j MASQUERADE  #配置masq
[root@localhost ~]#  service iptables save #保存规则
发如果现访问不了
解决方法
iptables -I INPUT -p tcp --dport 3128 -j ACCEPT
其他防火墙命令
iptables -t nat -L  --line //查看
iptables -t nat -D PREROUTING 1  删除某个

修改squid.conf文件

[root@localhost ~]# vi /etc/squid/squid.conf    #编辑squid.conf文件
	在http_port 3128 后加入tranparent  或者内网网卡地址:3128 transparent
[root@localhost ~]# systemctl restart squid      #重启squid服务

在这里插入图片描述
修改后在客户机测试,显示可以正常访问.
http://cdce.cn

其他

1.MASQUERADE,地址伪装

MASQUERADE就是针对拨号网络或者通过dhcp分配外部网络的IP的情况下设计的,作用是从服务器的网卡上,自动获取当前ip地址来做NAT。
例SNAT :iptables-t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 -o ens37 -j SNAT --to-source1.1.1.0-1.1.1.5
当外部地址变化幅度过大,不在转换后的地址内.
解决方法: iptables -t nat -A POSTROUTING -o ens37 -j MASQUERADE
自动识别外部地址进行地址转换

2.squid属于应用层面 ,NAT属于网络层面
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值