手机版
你好,游客 登录 注册
背景:
阅读新闻

Squid+Iptalbes实现透明代理配置记录

[日期:2012-05-24] 来源:Linux社区  作者:wanghaipeng [字体:大 中 小]

首先描述下硬件环境cpu P4 2.93\2G\80G 单网卡;系统环境为CentOS 5.4 x86_64,所需的squid由yum安装,squid包的版本为squid-2.6.STABLE21-6.el5.

部署完成后,能成功实现透明代理,如下将贴出配置内容,并且在最后将贴出部分参数的解释优化(不针对透明代理),作为以后一个参考内容;我个人也是在不断磨合,学习,所以也希望看到的朋友如果觉得哪些地方参数等需要进一步的调整优化,请指出,感激不尽!

vi /etc/squid/squid.conf

http_port 192.168.1.6:3128 transparent
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443          #https
acl Safe_ports port 53          #dns
acl Safe_ports port 80                  # http
acl Safe_ports port 21                  # ftp
acl Safe_ports port 443                # https
acl Safe_ports port 70                  # gopher
acl Safe_ports port 210                # wais
acl Safe_ports port 1025-65535     # unregistered ports
acl Safe_ports port 280                # http-mgmt
acl Safe_ports port 488                # gss-http
acl Safe_ports port 591                # filemaker
acl Safe_ports port 777                # multiling http
acl CONNECT method CONNECT
acl mynet src 192.168.1.0/255.255.255.0
http_access allow mynet
http_access deny all
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow all
http_reply_access allow all
icp_access allow all
hierarchy_stoplist cgi-bin ?
cache_mem 512 MB
cache_dir ufs /var/spool/squid 10240 16 256
maximum_object_size_in_memory 256 KB
maximum_object_size 2048 KB
cache_swap_low 88
cache_swap_high 93
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log squid
cache_store_log /var/log/squid/store.log squid
emulate_httpd_log on
pid_filename /var/run/squid.pid
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp:                   1440   20%   10080
refresh_pattern ^gopher:    1440   0%    1440
refresh_pattern .                0        20%   4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
cache_mgr haipeng.wang@simplnano.com
cache_effective_user squid
cache_effective_group squid
visible_hostname ips_squid
udp_incoming_address 0.0.0.0
# udp_outgoing_address 255.255.255.255
dns_nameservers 211.147.6.3
coredump_dir /var/spool/squid

下面是iptables的脚本,此脚本作用关键是重定向80端口,其他规则则允许内网所有包通行,如有相关限制,可再写.

#!/bin/bash
#Filename: firewall
IPS=/sbin/iptables
modprobe ip_tables
modprobe iptable_nat
modprobe iptable_filter
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPS -F
$IPS -X
$IPS -Z
$IPS -F -t nat
$IPS -X -t nat
$IPS -Z -t nat
$IPS -P INPUT DROP
$IPS -P OUTPUT DROP
$IPS -P FORWARD DROP
$IPS -t nat -A PREROUTING -s 192.168.1.0/24 -i eth0 -p tcp --dport 80 -j REDIRECT --to-ports 3128
$IPS -t filter -A INPUT -s 127.0.0.1 -j ACCEPT
$IPS -t filter -A FORWARD -s 192.168.1.0/24 -j ACCEPT
$IPS -t filter -A INPUT -s 192.168.1.0/24 -j ACCEPT
$IPS -t filter -A INPUT -i eth0 -j ACCEPT
$IPS -t filter -A OUTPUT -d 192.168.1.0/24 -j ACCEPT
$IPS -t filter -A OUTPUT -o eth0 -j ACCEPT
#$IPS -t nat -A POSTROUTING -o eth0 -j MASQUERADE

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款