免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 11376 | 回复: 19
打印 上一主题 下一主题

[proxy] 用squid+iptable做透明代理出现DNS问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-03 15:56 |只看该作者 |正序浏览
配置方法:
用squid+iptable实现透明代理

squid和iptable的具体安装我在此不做太多说明,一般看看它们的说明即可。我公司用一台机器作为代理上网。eth0连接外部网,eth1连接内部网。下面把我的配置写下来。

iptable的配置,在/etc/rc.d/目录下用touch命令建立firewall文件,执行chmod u+x firewll以更改文件属性,编辑/etc/rc.d/rc.local文件,在末尾加上/etc/rc.d/firewall以确保开机时能自动执行该脚本。
echo "starting ip forward"
echo 1 >;/proc/sys/net/ipv4/ip_forward
echo "starting iptables rules"
modprobe ip_tables
modprobe ip_nat_ftp
/sbin/iptables -F -t nat
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128 #将所有80端口的包转发到3128端口
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE #对eth0端口进行欺骗

squid的配置
http_port 3128
cache_mem 512 M
cache_swap_low 75
cache_swap_high 95
maximum_object_size 1024 KB
cache_dir ufs /usr/local/squid/cache 60000 16 256
cache_access_log /var/squid/logs/access.log
cache_log /dev/null
cache_store_log none
debug_options ALL,1

icp_access allow all
icp_query_time out 2000

cache_effective_user nobody
cache_effective_group nogroup

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
acl all src 0.0.0.0/0
acl localnet src 10.0.0.0/20
http_access allow localnet
http_access deny all

acl QUERY urlpath_regex -i cgi-bin \? \.exe$ \.zip$ \.mp3$ \.mp2$ \.rm$ \.avi$
no_cache deny QUERY

reference_age 3 days
quick_abort_min 16 KB
quick_abort_max 16 KB
quick_abort_pct 95
connect_timeout 60 seconds
read_timeout 3 minutes
request_timeout 30 seconds
client_lifetime 30 seconds
half_closed_clients off
pconn_timeout 60 seconds
ident_timeout 10 seconds
shutdown_lifetime 10 seconds

memory_pools off
memory_pools_limit 0


其中reference_age 3 days,ident_timeout 10 seconds两行出错:
2005/03/03 15:09:34| parseConfigFile: line 3379 unrecognized: 'reference_age 3 days'
2005/03/03 15:34:57| parseConfigFile: line 1645 unrecognized: 'ident_timeout 10 seconds'


透明代理可以实现,但是DNS有问题,在客户端浏览器输入IP可以访问外网,输入域名就不行,在客户端命令行模式下执行nslookup命令,提示

  1. DNS request time out
复制代码


在squid.conf中加入

  1. acl Safe_ports port 53          # dns
复制代码
故障依旧

请大侠帮助看看如何处理,谢谢!

论坛徽章:
0
20 [报告]
发表于 2007-05-29 19:26 |只看该作者
先将防火墙关了,squid停了。
然后nslookup一下是不是能够解析
一步一步查,dns服务器设置正确的话关掉防火墙是可以解析的

论坛徽章:
0
19 [报告]
发表于 2007-05-27 17:42 |只看该作者
我的DNS解析好慢。
squid.conf
  1. http_port 172.28.200.11:3128
  2. cache_mgr guo_sheng@163.com
  3. cache_dir ufs /var/cache/squid 1000 16 256
  4. cache_mem 400 MB
  5. cache_swap_low 90
  6. cache_swap_high 95
  7. dns_nameservers 202.102.192.68 202.102.199.68
  8. maximum_object_size 4096 KB
  9. maximum_object_size_in_memory 8 KB
  10. error_directory /usr/share/squid/errors/Simplify_Chinese
  11. ipcache_size 1024
  12. ipcache_low 90
  13. ipcache_high 95
  14. fqdncache_size 1024

  15. hierarchy_stoplist cgi-bin ?
  16. hierarchy_stoplist -i ^https:\\ ?
  17. acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi
  18. acl denyssl urlpath_regex -i ^https:\\
  19. no_cache deny QUERY
  20. no_cache deny denyssl

  21. cache_access_log /var/log/squid/access.log
  22. cache_log /var/log/squid/cache.log
  23. cache_store_log /var/log/squid/store.log
  24. cache_effective_user squid
  25. cache_effective_group nogroup
  26. visible_hostname proxy
  27. client_netmask 255.255.255.255
  28. httpd_accel_host virtual
  29. httpd_accel_port 80
  30. httpd_accel_with_proxy on
  31. httpd_accel_uses_host_header on

  32. acl admin arp "/etc/squid/adminlist"
  33. acl office src "/etc/squid/worklist"
  34. acl worktime time 8:00-12:00 14:30-18:00
  35. acl all src 0.0.0.0/0.0.0.0
  36. http_access allow admin
  37. http_access allow office worktime
  38. http_access deny all
复制代码


iptables里面加了:

  1. echo 1 > /proc/sys/net/ipv4/ip_forward
  2. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  3. iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
  4. iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-ports 3128
  5. iptables -t nat -A POSTROUTING -o eth0 -j SNAT
  6. iptables -A INPUT -p udp --dport 53 -j ACCEPT
  7. iptables -A INPUT -p udp --sport 53 -j ACCEPT
  8. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  9. iptables -A FORWARD -p udp --dport 53 -j ACCEPT
复制代码


操作系统是SUSE10,1G内存,P43.0 ,squid和DNS都装在这台机器上,访问外网的时候有时候解析好慢。有时候要3-4秒。
请问是什么原因?

[ 本帖最后由 dw0620 于 2007-5-27 17:46 编辑 ]

论坛徽章:
0
18 [报告]
发表于 2005-06-06 17:29 |只看该作者

用squid+iptable做透明代理出现DNS问题


小弟今年毕业设计,马上就要答辩了
可squid和iptable的透明代理还没搞定,
那位大侠给我一份配置,王分感激!!!
(只要能上网就可以,其他不用考虑)

论坛徽章:
0
17 [报告]
发表于 2005-04-29 16:07 |只看该作者

用squid+iptable做透明代理出现DNS问题

原帖由 "段誉" 发表:


FAINT,53本来就不是在squid.conf中添加的,和squid没有过关系的,只和IPTABLES有关系,重起IPTABLES就OK了。

BTW:楼主把整个过程整理一下吧


Iptables只是个防火墙配置工具而已,在配置防火墙规则时,立即生效,是不需要重启什么服务的!

论坛徽章:
0
16 [报告]
发表于 2005-04-24 01:16 |只看该作者

用squid+iptable做透明代理出现DNS问题

刚按照你的帖子配置了透明代理,查看access.log有数据,说明正常工作,并没有客户端无法解析DNS的情况

不过我的firewall跟你有点不同,我是在防火墙stop的时候删除所有规则,而启动时的前几行是
iptables -P INPUT DROP
iptables -A INPUT -i ! ${UPLINK} -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
        #enable public access to certain services
        for x in ${SERVICES}
        do
                iptables -A INPUT -p tcp --dport ${x} -m state --state NEW -j ACCEPT
        done

但SERVICES里面没有dns或53端口

论坛徽章:
0
15 [报告]
发表于 2005-04-22 11:58 |只看该作者

用squid+iptable做透明代理出现DNS问题

#AUTO DNS
$IPTABLES -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 202.97.230.4
$IPTABLES -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to 202.97.230.4

文中的202.97.230.4换成你们当地的外网的DNS服务器.

这条语法的原理是, 把所有的地址的53端口的请求自动转到一个公网的DNS服务器上.因为DNS先用到udp 要是解释不成功, 在用tcp.

实现的效果是:客户端的DNS的IP地址可以设置什么都可以. 比如说:1.1.1.1也一样能解释.

好长时间没有到这个论坛来了, 因有前些天有太多的心情, 还好, 现在算是基本调整过来了. 希望大家多多给我支持.

QQ 11217404
serpron 该用户已被删除
14 [报告]
发表于 2005-04-21 08:31 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
brensen 该用户已被删除
13 [报告]
发表于 2005-04-06 22:11 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
12 [报告]
发表于 2005-04-03 16:49 |只看该作者

用squid+iptable做透明代理出现DNS问题

>这是因为你的客户端3没有指定DNS服务器的原因,因为你的服务器并没有提供DNS服务,故只需要将你的客户端的DNS服务器设置成你的ISP的提供的服务器地址就可以了。
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP