加入收藏 | 设为首页 | 会员中心 | RSS
您当前的位置:首页 > Linux技术 > 网络管理

Iptables+squid 多网段透明代理的实现

时间:2008-06-06 10:33:52  来源:  作者:

作者:liheng

Email:liheng_2006@hotmail.com

首先,还是将我的测试环境介绍一下:

代理服务器

OS:RedHat Enterprise LINUX AS 4.0

Proxy Server Version: squid-2.5.STABLE6-3.4E.5 (系统自带)

网卡设置

Eth0:192.168.0.251 (连接外网)

Eth1:192.168.1.254 (连接内网)

路由器:(主要是用来连接内网的各个子网间的通信,路由器我是用LINUX来做的软路由

OS: OS:RedHat Enterprise LINUX AS 4.0

网卡设置:

Eth0:192.168.1.1

Eth1:192.168.2.1

客户端:

Client-1:

OS: Windows 2000 Professional

网卡设置:

IP address: 192.168.1.111

Netmask: 255.255.255.0

Gateway:192.168.1.1

DNS:61.144.56.100

Client-2

OS:Windows XP Professional

IP address: 192.168.2.120

Netmask: 255.255.255.0

Gateway:192.168.2.1

DNS:61.144.56.100

网络拓朴:

 

本次测试的目的:

1.实现多个网段的透明代理

2.通过Squid + Iptables的透明代理实现在客户端可以用OE收发外网邮箱的邮件

二、具体的设置

代理服务器的配置

1.Squid的配置

http_port 3128

hierarchy_stoplist cgi-bin ?                          
hierarchy_stoplist -i ^https:// ?                          
acl QUERY urlpath_regex -i cgi-bin /? /.asp /.php /.jsp /.cgi  
acl denyssl urlpath_regex -i ^https://                    
no_cache deny QUERY                                
no_cache deny denyssl

cache_mem 24 MB

cache_swap_low 90 

cache_swap_high 95 

maximum_object_size 4096 KB

maximum_object_size_in_memory 8 KB 

ipcache_size 1024                               

ipcache_low 90                                 

ipcache_high 95                               
fqdncache_size 1024

cache_dir aufs /usr/local/squid/var/cache1 100 16 256           
cache_dir aufs /usr/local/squid/var/Cache2 200 16 256

access_log /usr/local/squid/var/logs/access.log squid 

cache_log /usr/local/squid/var/logs/cache.log 

cache_store_log /usr/local/squid/var/logs/store.log

pid_filename /usr/local/squid/var/logs/squid.pid

ftp_user Squid@ 

ftp_passive on 

refresh_pattern ^ftp:                1440        20%        10080            


refresh_pattern ^gopher:        1440        0%        1440          
refresh_pattern .                0        20%        4320                

connect_timeout 1 minute

peer_connect_timeout 30 seconds

request_timeout 2 minutes

persistent_request_timeout 1 minute

cache_mgr webmaster@localhost

cache_effective_user squid

cache_effective_group   squid

visible_hostname redhat

/****************      下面四行是实现透明代理的关键之处       *****************/

httpd_accel_host virtual                            

httpd_accel_port 80

httpd_accel_with_proxy on

httpd_accel_uses_host_header on

2.iptables的配置

以下是我写的一个脚本:脚本名为:firewall(当然你也可以根据自己的喜好设置名称,用VI编辑器编译器好保存,然后将文件的属性设置为可执行,用chmod 777 firewall (这只是一个示例,可根据实际情况更改)命令更改文件的属性为可执行文件)

#!/bin/bash

echoenable ip forwarding

#打开路由转发功能

echo1> /proc/sys/net/ipv4/ip_forward

#加载IPTABLES所需要的模块

echostarting iptables rules

/sbin/modprobe iptable_fileter

/sbin/modprobe ip_tables

/sbin/modprobe iptables_nat

/sbin/modprobe ip_conntrack_ftp

/sbin/modprobe ip_nat_ftp

#刷新IPTABLES的规则链

/sbin/iptables

来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
相关文章
    无相关信息
栏目更新
栏目热门