squid实现局域网的正向代理,透明代理,上网策略

squid实现局域网的正向透明代理,附上网策略

首先看一下网络拓扑图:

需要实现的目的:
192.168.3.x网段中的电脑可以通过squid192.168.3.250代理服务器上外网。
192.168.1.x网段中的电脑通过squid192.168.1.250代理服务器上外网。
并且192.168.3.x和192.168.1.x网段互通。

路由器IP:192.168.1.1
代理服务器IP1:192.168.1.250
代理服务器IP2:192.168.3.250
客户端IP:192.168.1.251
客户端IP:192.168.3.6

安装前准备:
1、关闭SELinux

    vi /etc/selinux/config
   #SELINUX=enforcing     #注释掉
   #SELINUXTYPE=targeted  #注释掉
   SELINUX=disabled  #增加
   :wq  保存,关闭。
setenforce 0    【临时关闭(不用重启机器)】   

2、修改主机的路由模式

# vi /etc/sysctl.conf
    net.ipv4.ip_forward = 1    #0为关闭,1为开启路由
# sysctl -p                     # 使之生效
echo '1' > /proc/sys/net/ipv4/ip_forward  【开启ip转发,立即生效】
echo '0' > /proc/sys/net/ipv4/ip_forward  【关闭ip转发,立即生效】

3、设置防火墙端口转发规则
    代理服务器的ip为
eth0:192.168.1.250 —->网关指向路由器(192.168.1.1)DNS指向114.114.114.114。
eth1:192.168.3.250

[root@localhost ~]# ifconfig | grep addr
eth0     inet addr:192.168.1.250  Bcast:192.168.1.255  Mask:255.255.255.0
eth1     inet addr:192.168.3.250  Bcast:192.168.3.255  Mask:255.255.255.0
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
[root@localhost ~]# cat /etc/resolv.conf
nameserver 114.114.114.114
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.37) 56(84) bytes of data.
64 bytes from 14.215.177.37: icmp_seq=2 ttl=55 time=9.77 ms

这样eth0通过192.168.1.1可以上公网,局域网网络中的都通过192.168.1.250作为网关上公网。

**********************网上参考设置:*********************************************

外网IP:192.168.21.160   eth0
内网IP:192.168.237.160  eth1

设置防火墙端口转发规则
   iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp –dport 80 -j REDIRECT –to-ports 3128  #开启端口转发功能,把内网eth1的80端口转发到外网eth0的3128端口
   iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  #开启外网eth0的NAT网络地址转换功能
   service iptables save  #保存规则
   /etc/init.d/iptables restart  #重启防火墙

*************************网上参考设置END******************************************

**********************自己使用的配置:*********************************************

外网IP:192.168.1.250   eth0
内网IP:192.168.3.250   eth1

4、设置防火墙端口转发规则

service iptables status
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128  #开启端口转发功能,把eth1的80端口转发到3128端口
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128    #开启端口转发功能,把eth0的80端口转发到3128端口
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  #开启外网eth3的NAT网络地址转换功能
service iptables save  #保存规则
/etc/init.d/iptables restart  #重启防火墙
service iptables status

*************************自己使用的配置END******************************************

5、安装Squid

# yum install squid       #安装(Squid 3.1.10)
# chkconfig squid on      #设置开机启动

6、配置Squid

设置Squid系统的缓存目录为:

/home/squid/cache

Squid日志目录

/home/squid/log

#mkdir -p /home/squid/{cache,log,deny}
#chown squid.squid -R /home/squid/

配置可以根据需要做:

但是透明代理以下三点必须做。

#cp /etc/squid/squid.conf /etc/squid/squid.confbak  #备份
#vi  /etc/squid/squid.conf  #编辑文件
    http_access allow all        --把deny all改民allow all
    cache_dir ufs /home/squid/cache 4096 16 256    --把缓存目录这一句打开注释,并且修改100为256
    http_port 3128 transparent

squid常用控制命令:

service squid stop  #停止
service squid reload
/usr/sbin/squid  -z    #初始化cache缓存目录
service squid start    #启动
service squid restart  #重启
squid -z 初始化缓存空间
squid -k shutdown 停止
squid -k parse    配置检查
#squid -k reconfigure  应用更改后的配置(不必重启squid)
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇