FreeBSD 利用IPFW实现限制局域网使用QQ


一、分析腾讯QQ服务器的分布范围:

  QQ服务器分为三类:

  1、UDP 8000端口类7个:速度最快,服务器最多。QQ上线会向这7个服务器发送UDP数据包,选择回复速度最快的一个作为连接服务器。

  这7个服务器名字均以sz-sz7开头,域后缀是tencent.com,域名与IP对应为

  sz 61.144.238.145

  sz2 61.144.238.146

  sz3 202.104.129.251

  sz4 202.104.129.254

  sz5 61.141.194.203

  sz6 202.104.129.252

  sz7 202.104.129.253

  其它: 61.144.238.156

  2、TCP HTTP连接服务器2个,使用HTTP 80端口连接这2个服务器名字均以tcpconn开头,域后缀是tencent.com,域名与IP对应为

  tcpconn 218.17.209.23

  tcpconn3 218.17.209.23

  tcpconn2 218.18.95.153

  tcpconn4 218.18.95.153

  虽然有4个名字,但是只有2个服务器

  3、会员VIP登陆服务器,使用HTTP 443安全连接

  服务器IP 218.17.209.42

  由于第2、3种我这儿无法选择进行登陆,我只是通过反向查询得到了IP及端口,至于第1种我经过了详细的测试,封锁了这7个UDP服务器,QQ是不能登陆的。

  二、实现限制内网客户端上QQ(注意:我的网络是用nat+ipfw做透明代理加防火墙实现共享上网的)

  1.加入以下规则使内核支持ipfw防火墙功能,重新编辑内核文件.

  options IPFIREWALL //通知操作系统的内核检查每个IP数据包,将它们与规则集进行比较

  options IPFIREWALL_FORWARD

  options IPDIVERT //启用由ipfw divert使用的转向IP套接字。这一选项需要与natd联合使用。

  options IPFIREWALL_VERBOSE //向系统的注册程序发送注册信息包
options IPFIREWALL_VERBOSE_LIM99v=100 //限制一台机器注册的次数。

  options IPSTEALTH //启动支持秘密转发的代码,这一选项在使防火墙不被traceroute和类似工具发现时很有用。

  options IPFIREWALL_DEFAULT_TO_ACCEPT

  options ACCEPT_FILTER_DATA

  options ACCEPT_FILTER_HTTP //接受过滤器中的静态连接

  options ICMP_BANDLIM //ICMP_BANDLIM根据带宽限制产生icmp错误。一般情况下我们需要这个选项,它有助于你的系统免受D.O.S.攻击。

  2、内核编辑好以后,在/etc/rc.conf文件中加入以下内容,好让系统重启后防火墙自动启动

  gateway_enable="YES" //启动网关

  ##########IP-firewall#################

  firewall_enable="YES" //激活firewall防火墙

  firewall_type="/etc/ipfw.conf" //firewall自定义脚本

  firewall_quiet="NO" //起用脚本时,是否显示规则信息。现在为“NO”假如你的防火墙脚本已经定型,那么就可以把这里设置成“YES”了。

  firewall_logging_enable="YES" //启用firewall的log记录。"

  ##########NATD#######################

  natd_interface="rl0" //NATD服务启用在哪块网卡。

  natd_enable="YES" //激活NATD服务

  natd_flags="-config /etc/natd.conf" //NATD服务参数设置文件。

  3.设置完成后我们再编辑/etc/syslog.conf文件,加入以下代码:

  !ipfw

  *.* /var/log/ipfw.log

  4.在/var/log/建立一个ipfw.log的文件,内容为空的就可以了,然后保存退出。(这是一个记录防火墙的日志文件)
5.在/etc下也建立一个natd.conf的文件,内容也为空的,保存退出。(这是一个nat的配置文件,可以作一些NAT的设置)

  6.在/etc下新建ipfw.conf文件,在文件里写入以下内容:

  add 00400 divert natd ip from any to any via rl0

  add 00001 deny log ip from any to any ipopt rr

  add 00002 deny log ip from any to any ipopt ts

  add 00003 deny log ip from any to any ipopt ssrr

  add 00004 deny log ip from any to any ipopt lsrr

  add 00005 deny tcp from any to any in tcpflags syn,fin

  #####TCP#####

  add 10000 deny tcp from any to any 4000

  add 10001 deny tcp from any to any 8000

  add 10002 deny udp from any to any 4000

  add 10003 deny udp from any to any 8000

  add 10004 deny all from any to 61.144.238.145

  add 10005 deny all from 61.144.238.145 to any

  add 10006 deny all from any to 61.144.238.146

  add 10007 deny all from 61.144.238.146 to any

  add 10008 deny all from any to 202.104.129.251

  add 10009 deny all from 202.104.129.251 to any

  add 10010 deny all from any to 202.104.129.254

  add 10011 deny all from 202.104.129.254 to any

  add 10012 deny all from any to 61.141.194.203

  add 10013 deny all from 61.141.194.203 to any

  add 10014 deny all from any to 202.104.129.252

  add 10015 deny all from 202.104.129.252 to any

  add 10016 deny all from any to 202.104.129.253

  add 10017 deny all from 202.104.129.253 to any


  add 10018 deny all from any to 218.18.95.153

  add 10019 deny all from 218.18.95.153 to any

  add 10020 deny all from any to 218.17.209.23

  add 10021 deny all from 218.17.209.23 to any

  add 10022 deny all from any to 61.144.238.156

  add 10023 deny all from 61.144.238.156 to any

  add 10024 deny all from any to 218.17.209.42

  add 10025 deny all from 218.17.209.42 to any

  #####ICMP#####

  add 30000 allow icmp from any to any icmptypes 3

  add 30001 allow icmp from any to any icmptypes 4

  add 30002 allow icmp from any to any icmptypes 8 out

  add 30003 allow icmp from any to any icmptypes 0 in

  add 30004 allow icmp from any to any icmptypes 11 in

  #####LAN#####

  add 40001 allow all from any to any

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3