LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1400|回复: 7

suse下用squid+iptables做代理服务器!

[复制链接]
发表于 2004-10-20 13:16:26 | 显示全部楼层 |阅读模式
以前找了很多关于代理服务器的配置,发现大都不是很理想。前段时间实际操作了一
了一下,居然可以配置好了。
eth0是对外的网卡,配置好可以上网就行了。
eth1是对内的网卡,IP是192.168.0.1,做网关。let's go!
squid部分:
安装的时候把squid选择上,然后修改/etc/squid/squid.conf文件,有下面的一些选项就可以了,你要是觉得麻烦的话,干脆把这个文件备份后,自己新建一个,内容如下:
http_port 192.168.0.1:3128
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
cache_mem 8 MB
cache_dir ufs /var/cache/squid 5000 16 256(此处5000为cache的大小为5G,可自行调整大小)
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
ftp_user Squid@
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
refresh_pattern ^ftp:                1440        20%        10080
refresh_pattern ^gopher:        1440        0%        1440
refresh_pattern .                0        20%        4320
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 563
acl Safe_ports port 80                # http
acl Safe_ports port 21                # ftp
acl Safe_ports port 443 563        # https, snews
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
acl test src 192.168.0.0
http_access allow test
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
cache_mgr chgtg@163.com(这个信箱地址写你自己的哦)
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
保存退出。
然后运行
#squid -z
#chmod 777 /var/cache/squid
#chmod 777 /var/log/squid
如果需要高级的管理功能,还要继续配置该文件!

iptables部分:

在/etc/init.d目录下建立了firewall文件,然后在/etc/init.d/boot.local中加入内容如下:
#!/bin/sh

echo "Enabling IP Forwarding..."
echo 1 > /proc/sys/net/ipv4/ip_forward

echo "Starting iptables rules..."

#Refresh all chains

/usr/sbin/iptables -F -t filter
/usr/sbin/iptables -F -t nat

#############Define packets from Internet server to Intranet#######################
iptables -A FORWARD -p tcp -s 0/0 --sport ftp-data -d 198.168.0.1/24 -i eth0 -j ACCEPT
iptables -A FORWARD -p udp -d 198.168.0.1/24 -i eth0 -j ACCEPT

#############Define packets from Intranet to Internet###############
iptables -A FORWARD -s 198.168.0.1/24 -i eth0 -j ACCEPT

#################################Define Proxy rule##################################
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
iptables -t nat -A POSTROUTING -s 192.168.0.1/24 -o ppp0 -j MASQUERADE
保存退出。
#chkconfig  看看squid是否在启动的服务里面。(应该是在的哦)
好了,可以了。
当然,一个好的代理服务器是还需要dhcp,你也可以开ssh,管理起来很方便的。还可以用yast。
一个字,爽!
发表于 2005-1-8 10:40:57 | 显示全部楼层
这个是代理服务器的配置吧,
这个每个客户机还要配置代理,
有没有路由的资料呢?
发表于 2005-1-9 12:54:58 | 显示全部楼层
我在下 SuSE 服务器版的有必要吗?

yast里头的 Route项指的是指作为客户机指向那个网关吧,
不是自己作为路由的配置吧,是不是这样呢?
发表于 2005-1-10 15:12:29 | 显示全部楼层
一定要装那个 squid 吗?
发表于 2005-1-10 16:18:31 | 显示全部楼层
呵呵,搞定!
其实是不用装那个squid的了,
就是那几条 iptables 的命令了。

感谢 chgtg !请求版主加为精华贴!
 楼主| 发表于 2005-1-11 08:55:02 | 显示全部楼层
squid的主要作用是建立硬盘的cache,可以起到缓冲的作用,也可以使下面的机器浏览网页更快!
还有就是可以限制登录,和登录的时间等等。你可以看它的conf文件。
发表于 2005-1-23 19:28:07 | 显示全部楼层
介绍的不错,辛苦了,不过有点麻烦,直接用IPTABLES应该也是可以的把 直接用IP转发!能不能实现?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-1-24 08:02:40 | 显示全部楼层
直接转发也应该可以的,不过没有试过。没什么发言权。
不过,好像从2.4的内核好像就带路由了,因为有一次我在squid里面drop掉一台机器,但是后来测试该机还是可以上网。然后我就route一下,发现路由已经打开。后来宽带路由器便宜了(400¥),也就不用这个server了!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表