Chinaunix

标题: pf的NAT能做到100Mb以上流量吗? [打印本页]

作者: wxw2004gl    时间: 2006-10-11 18:34
标题: pf的NAT能做到100Mb以上流量吗?
我用的pf做nat,平常的连接数在10玩左右,流入量在45M,流出量在60M左右。然后连接数再多,流量再增加的就会导致效率迅速下降。有没有那位能帮忙优化一下吗?让pf可以上到100Mb的流量。
作者: langue    时间: 2006-10-11 18:36
nat 主要的 cpu 瓶颈在于数据包的匹配和处理。贴一下你的 pf.conf(老版本的也贴一下你的 nat.conf)
作者: wxw2004gl    时间: 2006-10-11 18:41
标题: pf.conf的配置
Lan="em1"
Wan="em0"
# Options: tune the behavior of pf, default values are given.
#set timeout { interval 10, frag 30 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 3600 }
set timeout { tcp.closing 240, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 20, icmp.error 10 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
#set timeout { adaptive.start 0, adaptive.end 0 }
set limit { states 1000000, frags 150000 }
#set loginterface none
set optimization normal
set block-policy drop
#set require-order yes
scrub in all

private_nets = "{ 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 }"
Lan_nets="{202.x.x.0/20,222.x.x.0/20}"

nat on $Wan from $Lan_nets to any -> ($Wan)

block in quick proto tcp all flags SF/SFRA
block in quick proto tcp all flags SFUP/SFRAU
block in quick proto tcp all flags FPU/SFRAUP
block in quick proto tcp all flags /SFRA
block in quick proto tcp all flags F/SFRA
block in quick proto tcp all flags U/SFRAU
block in quick proto {tcp,udp} from any to any port 134 >< 140
block in quick proto {tcp,udp} from any to any port = 445
block in quick proto {tcp,udp} from any to any port = 593
block in quick proto {tcp,udp} from any to any port = 333
block in quick proto {tcp,udp} from any to any port = 5554
block in quick proto {tcp,udp} from any to any port = 9995
block in quick proto {tcp,udp} from any to any port = 9996
block in quick proto {tcp,udp} from any to any port = tftp
block in quick proto {tcp,udp} from any to any port = 554
block in quick proto {tcp,udp} from any to any port = 1434
block in quick proto {tcp,udp} from any to any port = 4444
antispoof quick for $Wan inet
block all
pass quick on lo0 all
##############################################
#Wan Interface
#############################################
block drop in quick on $Wan from $private_nets to any
block drop out quick on $Wan from any to $private_nets
pass quick on $Wan all
################################################
#Lan Interface
################################################
pass quick on $Lan all




xeon 2.4GX2,cpu利用率最高到35%,1G ECC DDR 533 RAM,空闲为720M

[ 本帖最后由 wxw2004gl 于 2006-10-11 18:44 编辑 ]
作者: wxw2004gl    时间: 2006-10-11 18:50
标题: sysctl.conf的配置
kern.ipc.somaxconn=16384
kern.ipc.maxsockbuf=2097152
#kern.ipc.nmbclusters=65535
kern.maxfilesperproc=32768
kern.maxfiles=65536
net.inet.tcp.msl=7500
#net.inet.tcp.tcbhashsize=1638
net.inet.tcp.sendspace=65535
net.inet.udp.maxdgram=65535
net.local.stream.sendspace=65535
net.local.stream.recvspace=52768

net.inet.icmp.icmplim_output=0
net.inet.tcp.blackhole=1
net.inet.udp.blackhole=1
作者: lowmer    时间: 2006-10-11 18:54
限制每IP最大连接数(一般在15个以内即可)限制发包速率,man pf.conf,效果会好不少。

把所有的端口过滤编成宏(端口过滤越少越好)。防扫描项对于BSD防火墙作用不大,可以全部注释掉,提高处理速度。如果防火墙上有ssh,可以考虑用密钥登陆方式。后端有服务器的话,可以在服务器上安装防火墙。

一些set参数如果设置不当也会降低防火墙性能,如果没有经过长时间的实验和理论功底还是默认比较好,把参数设置的太小和太大都是不对的。

要想提高速度,其中之一就是将规则变得越少越好。通过一个命令好像可以看到最终的规则长度,好久不用忘了。我觉得最终规则最好限制在50条以内。

[ 本帖最后由 lowmer 于 2006-10-11 19:00 编辑 ]
作者: colddawn    时间: 2006-10-11 19:20
state 100w ,不用这么极端吧。
作者: wxw2004gl    时间: 2006-10-11 19:25
标题: 回复 6楼 colddawn 的帖子
我怕设置的太小连接数会超过啊,设置到100w应该不影响性能吧!

[ 本帖最后由 wxw2004gl 于 2006-10-11 19:26 编辑 ]
作者: wxw2004gl    时间: 2006-10-11 19:31
只要提高nat性能就可以了,其他的过滤和防病毒可以不做!
作者: colddawn    时间: 2006-10-11 19:50
对于state条目不应该想放多大就多达,首先多占用内存,而且我记得pf的state查找是RB树,放太大了绝对影响查找速度。

在你现在这种规模的网络下很难有一定可以有效地参数,但既然发生转发丢包了,肯定是哪些地方出现瓶颈了,可以多注意看看日志以及内核当前某些参量,定位瓶颈的地方后再做调整。例如是否出现某些异常日志,netstat -m检查mbuf利用情况,pfctl -si查看搜索命中以及包统计状态,pfctl -ss检查是否存在异常状态等等。
作者: wxw2004gl    时间: 2006-10-11 19:59
标题: 回复 9楼 colddawn 的帖子
pfctl -si的显示如下:

Hostid: 0x92fb9eba

State Table                          Total             Rate
  current entries                    94364               
  searches                     11631376151       104102.5/s
  inserts                        161046458         1441.4/s
  removals                       160952094         1440.5/s
Counters
  match                         6293046925        56323.7/s
  bad-offset                             0            0.0/s
  fragment                            8945            0.1/s
  short                                  6            0.0/s
  normalize                          17900            0.2/s
  memory                                 0            0.0/s
  bad-timestamp                          0            0.0/s
  congestion                             0            0.0/s
  ip-option                              7            0.0/s
  proto-cksum                            0            0.0/s
  state-mismatch                   1692050           15.1/s
  state-insert                           1            0.0/s
  state-limit                            0            0.0/s
  src-limit                       34473692          308.5/s
  synproxy                               0            0.0/s

root@NAT[~]#netstat -m
790/1130/1920 mbufs in use (current/cache/total)
788/1042/1830/65536 mbuf clusters in use (current/cache/total/max)
785/879 mbuf+clusters out of packet secondary zone in use (current/cache)
0/0/0/0 4k (page size) jumbo clusters in use (current/cache/total/max)
0/0/0/0 9k jumbo clusters in use (current/cache/total/max)
0/0/0/0 16k jumbo clusters in use (current/cache/total/max)
1773K/2366K/4140K bytes allocated to network (current/cache/total)
0/0/0 requests for mbufs denied (mbufs/clusters/mbuf+clusters)
0/0/0 requests for jumbo clusters denied (4k/9k/16k)
0/7/65535 sfbufs in use (current/peak/max)
0 requests for sfbufs denied
0 requests for sfbufs delayed
0 requests for I/O initiated by sendfile
0 calls to protocol drain routines

麻烦看看有什么问题没!谢谢
作者: lowmer    时间: 2006-10-11 22:57
原帖由 wxw2004gl 于 2006-10-11 19:31 发表
只要提高nat性能就可以了,其他的过滤和防病毒可以不做!


你自己试试就知道了,当时冲击波病毒泛滥的时候,能让你的BSD防火墙存活半个小时就相当不错了!
作者: wxw2004gl    时间: 2006-10-12 09:11
没有人用pf做过这么大流量的NAT应用吗?

liuliang.JPG (22.62 KB, 下载次数: 19)

2006-10-11的流量图表

2006-10-11的流量图表

作者: colddawn    时间: 2006-10-12 11:50
貌似没看出什么问题来,这应该不是出现丢包时的状态吧
不过既然这方面检查不出问题,建议先检查是否达到网卡瓶颈了吧,另外限制并发连接估计也要做.
作者: lowmer    时间: 2006-10-12 14:35
呵呵,路过!
作者: Momoass    时间: 2006-10-12 16:54
Full Pass? keep state?
作者: wxw2004gl    时间: 2006-10-12 16:57
原帖由 Momoass 于 2006-10-12 16:54 发表
Full Pass? keep state?

没看明白!
作者: Momoass    时间: 2006-10-12 17:04
set timeout { tcp.first 10, tcp.opening 10, tcp.established 1800 }
set timeout { tcp.closing 5, tcp.finwait 5, tcp.closed 5 }
set timeout { udp.first 30, udp.single 10, udp.multiple 300 }
set timeout { icmp.first 10, icmp.error 5 }
set timeout { other.first 30, other.single 10, other.multiple 60 }

pass 语句加 keep state 减少匹配时间。

最好用altq限制每客户的最高连接数。
作者: langue    时间: 2006-10-12 18:45
原帖由 Momoass 于 2006-10-12 17:04 发表
set timeout { tcp.first 10, tcp.opening 10, tcp.established 1800 }
set timeout { tcp.closing 5, tcp.finwait 5, tcp.closed 5 }
set timeout { udp.first 30, udp.single 10, udp.multiple 300 }
set timeout { icmp.first 10, icmp.error 5 }
set timeout { other.first 30, other.single 10, other.multiple 60 }

pass 语句加 keep state 减少匹配时间。

最好用altq限制每客户的最高连接数。


这主意不错。
作者: wxw2004gl    时间: 2006-10-12 22:05
原帖由 langue 于 2006-10-12 18:45 发表


这主意不错。

这样做好像不行哦,加了之后性能更加低了,keep state后连接数到了23w了!
作者: Momoass    时间: 2006-10-13 04:25
1个公网IP最多只有6W4个左右端口可以用,也就是说一个公网IP支持最佳states应该是6W4以内。
假如你有1000个客户,每客户允许500个states,1000x500=50W,每客户都满负载运行的话应该要用8个公网IP来做NAT池才够。

你现在keep state之后达到23W,如果只有1IP的话肯定端口不够用了,很多都是处于等待分配的状态。
作者: langue    时间: 2006-10-13 05:22
原帖由 wxw2004gl 于 2006-10-12 22:05 发表

这样做好像不行哦,加了之后性能更加低了,keep state后连接数到了23w了!


我是指:用altq限制每客户的最高连接数。
作者: wxw2004gl    时间: 2006-10-13 22:11
原帖由 Momoass 于 2006-10-13 04:25 发表
1个公网IP最多只有6W4个左右端口可以用,也就是说一个公网IP支持最佳states应该是6W4以内。
假如你有1000个客户,每客户允许500个states,1000x500=50W,每客户都满负载运行的话应该要用8个公网IP来做NAT池才够。 ...

pf怎么做NAT地址池?可不可以帮忙,我有其他的公网ip,但是和接口ip不是在同一个网段,不知道可以不?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2