iptables+squid透明代理

Monday, September 22, 2008

squid 2.6 简单配置
=========================
cat squid.conf|sed '/^\#/d'|sed '/^$/d'或者grep -v -E '^$|^#' squid.conf

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
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
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
icp_access allow all
http_port 3128 transparent
hierarchy_stoplist cgi-bin ?
cache_mem 96 MB
cache_dir ufs /var/spool/squid 100 16 256
access_log /var/log/squid/access.log squid
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 tech@xintv.com
visible_hostname CentOS5
error_directory /usr/share/squid/errors/Simplify_Chinese
coredump_dir /var/spool/squid

==============================
iptables 命令

如果防火墙和代理服务器在一起
eth0:内网IP eth1:外网IP
iptables -t nat -A PREROUTING -s 172.168.100.0/24 -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

如果不在一起,代理服务器:172.168.100.191
iptables -t nat -A PREROUTING -s 172.168.100.0/24 -i eth0 -p tcp -m tcp --dport 80 -j DNAT --to 172.168.100.191:3128
iptables -t nat -A POSTROUTING -o eth0 -s 172.168.100.0/24 -d 172.168.100.191 -j SNAT --to 172.168.100.201

===========================
iptables 的一些管理
acl badsite url_regex -i taobao.com
http_access deny badsite
限制访问特定的网站
acl numconn maxconn 2
http_access deny all numconn
限制访问每个IP的链接数(注意:client_db要设为on)

===========================
开启ip_forward转发
只修改当前环境的转发
echo 1 > /proc/sys/net/ipv4/ip_forward
永久修改环境的转发
vi /etc/sysctl.conf
修改
net.ipv4.ip_forward = 0

net.ipv4.ip_forward = 1

直接vi编辑/proc/sys/net/ipv4/ip_forward是会报错的,因为/proc里面是虚拟档案系统目录,都是在ram上。里面的文档通过重导或者修改sysctl.conf达到修改的目的。通过重导重启以后,或者重启网卡后就恢复原状了。

reference for iptables
http://iptables-tutorial.frozentux.net/cn/iptables-tutorial-cn-1.1.19.html
http://bbs.chinaunix.net/viewthread.php?tid=477137
http://bbs.chinaunix.net/viewthread.php?tid=281136
http://blog.platinum.net.cn/index.php?op=ViewArticle&articleId=59&blogId=1
http://bbs.chinaunix.net/viewthread.php?tid=536582&extra=&page=1
http://www.chinaunix.net/jh/4/293819.html
http://bbs.chinaunix.net/viewthread.php?tid=559519
http://bbs.chinaunix.net/viewthread.php?tid=602090
http://www.linuxaid.com.cn/engineer/ideal/article/policy_pouting.htm
http://bbs.chinaunix.net/viewthread.php?tid=304033
http://chinaunix.net/jh/38/505206.html
http://www.vbird.org/linux_server/0420squid.php

========================
ipp2p模块
http://linux.chinaunix.net/bbs/viewthread.php?tid=914377

========================
命令补充
# lsmod
lsmod(list modules)

功能说明:显示已载入系统的模块。

语  法:lsmod

补充说明:执行lsmod指令,会列出所有已载入系统的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放入核心。您可以将这些功能编译成一个个单独的模块,待需要时再分别载入。

# modinfo
modinfo(module infomation)

功能说明:显示kernel模块的信息。

语  法:modinfo [-adhpV][模块文件]

补充说明:modinfo会显示kernel模块的对象文件,以显示该模块的相关信息。

参  数:
-a或--author  显示模块开发人员。
-d或--description  显示模块的说明。
-h或--help  显示modinfo的参数使用方法。
-p或--parameters  显示模块所支持的参数。
-V或--version  显示版本信息。

# modprobe
modprobe(module probe)

功能说明:自动处理可载入模块。

语  法:modprobe [-acdlrtvV][--help][模块文件][符号名称 = 符号值]

补充说明:modprobe可载入指定的个别模块,或是载入一组相依的模块。modprobe会根据depmod所产生的相依关系,决定要载入哪些模块。若在载入过程中发生错误,在modprobe会卸载整组的模块。

参  数:
-a或--all  载入全部的模块。
-c或--show-conf  显示所有模块的设置信息。
-d或--debug  使用排错模式。
-l或--list  显示可用的模块。
-r或--remove  模块闲置不用时,即自动卸载模块。
-t或--type  指定模块类型。
-v或--verbose  执行时显示详细的信息。
-V或--version  显示版本信息。
-help  显示帮助。

Posted by Michael.Ding at 10:46 AM

0 comments:

Post a Comment