Linux服务器端网络实用工具比较-Iptable Vs TC

来源:互联网 发布:js动态隐藏tr 编辑:程序博客网 时间:2024/06/15 10:48

IPtable 与 TC都是服务器端开发和测试人员经常使用的工具,先简单比较这两个工具,然后阐述一下TC Tool的强大之处


  • Iptable:  A user space application program that allows asystem administrator to configure the tables forpacketfilter rules provided by the Linux kernel firewall and the chains andrules it stores
  • TC:  trafficcontrol in the iproute2 package.NETEM: net emulator, anextension of TC


Compare

  •  概念基本比较

Function differences

(1)    Can drop whole packages: YES

(2)    Can drop some packages with rate: No

(3)    Can delaying, dropping, duplicating, or corrupting? NO

(4)    Can control priority or bandwidth? NO

Summary: only can be used as firewall: Nat/drop/accept package.

(1)    YES

(2)    YES

(3)    YES

(4)    YES

Summary: with more functions to control traffic.




   

Use steps

Configure rules according to followed elements:

 

TABLE

Specify the table.

CHAIN

Specify the chain.

RULES

Packet selection rules.

TARGET

Action to take place.

Configure one queue for net interface -> [setup classes base on the queue (should be class full queue) -> setup sub class with sub queue-> setup filter to route to the class].

   

Typical use

Rough control

(1)    Block connection

(2)    NAT

Better for traffic detail control

(1)    Limit bandwidth

(2)    Emulator delaying, dropping, duplicating, or corrupting packages


  •  具体用法比较

一.  IpTable Detail Command Show:

Drop

Drop发往目的地址端口的数据(SYN)
iptables -t filter -p tcp -A OUTPUT -d 目标IP --dport 目标端口-j DROP

或者Drop目的地址返回的数据(ACK)
iptables -t filter -p tcp -A INPUT -s 目标IP --sport 目标端口-j DROP

Reject

iptables-t filter -p tcp -A OUTPUT -d 目标IP --dport 目标端口 -j REJECT 

Thentelnet can’t success Src to 目标

限速

通过iptables限制单位时间通过的数据包数,例如每分钟只能通过一个数据包:
iptables -A INPUT -p tcp --dport 目标端口 -m limit --limit 1/m --limit-burst 1 -j ACCEPT
iptables -A INPUT -p tcp --dport 目标端口 -j DROP  


二  .TC Detail Command Show:

1. 延时
(1)设置延时

# tc qdisc add dev eth0 root netem delay 30ms

上面的命令实现了给 eth0 口发包时添加 30ms 的延时。

(2)显示延时的设置

# tc qdisc show

(3)修改延时

# tc qdisc change dev eth0 root netem delay 40ms

(4)删除延时的配置

# tc qdisc del dev eth0 root netem delay 40ms

2. 丢包
设置丢包命令如下:

# tc qdisc add dev eth0 root netem loss 10%

删除丢包恢复tc qdisc del dev eth0 root netem loss 10%

3.破坏包

tc qdisc add dev eth0 root netem corrupt 0.1%
tc qdisc del dev eth0 root netem corrupt 0.1% * *

4.重发包
tc qdisc add dev eth0 root netem duplicate 1%
tc qdisc del dev eth0 root netem duplicate 1%
 5.包的乱序

tc qdisc add dev eth0 root netem gap 5 delay 10ms
tc qdisc add dev eth0 root netem delay 10ms reorder 25% 50%
tc qdisc add dev eth0 root netem delay 100ms 75ms* *



Notes:鉴于项目的需要,测试Server 到Server 内部的异常pdu可以考虑用一台机器作为 破坏包的出口,然后转发到另外一台被测试的Server,达到测试的目的!


check 日常工作中发现的一个Bug


Step1.Launch the C++ multiThread Tool on 10.224.**** ./multiThreadTool -C Ip  -T 10 -N 200000000 -U *****  -S
Step2. Select one node to return the Bad Pdu to Server2
one Node Server 1
:wdhf1wco003:root > tc qdisc add dev eth0 root netem corrupt 0.5%
:wdhf1wco003:root > tc qdisc show
qdisc netem 8001: dev eth0 limit 1000 corrupt 0.5%

except Result: Server will run normally and no memory leak happened
infact Result Server have memory leak


[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1128315200]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x43408a20
[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1128315200]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x43408a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1128315200]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x43408a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20
[03/02/2012 09:13:21.992 pid=14057 tid=1411541312]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x54223a20
[03/02/2012 09:13:21.992 pid=14057 tid=1443010880]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x56026a20
[03/02/2012 09:13:21.992 pid=14057 tid=1128315200]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x43408a20
[03/02/2012 09:13:21.992 pid=14057 tid=1380071744]Error:CCmByteStreamT::Read, can't read. m_ResultRead=10013 this=0x52420a20


Memory Leak:
Mar 2 15:04:04 wdhf1wco001 kernel: Free swap: 0kB
Mar 2 15:04:04 wdhf1wco001 kernel: 8650752 pages of RAM
Mar 2 15:04:04 wdhf1wco001 kernel: 413345 reserved pages
Mar 2 15:04:04 wdhf1wco001 kernel: 27401 pages shared
Mar 2 15:04:04 wdhf1wco001 kernel: 251 pages swap cached
Mar 2 15:04:04 wdhf1wco001 kernel: Out of memory: Killed process 14058 (*****).
Mar 2 15:04:04 wdhf1wco001 kernel: ******: page allocation failure. order:0, mode:0x850
Mar 2 15:04:04 wdhf1wco001 kernel:






原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在一家莆田系医院上班怎么办 被莆田医院骗了怎么办 痘痘红肿有脓包怎么办 换届选举候选人自动退出竞选怎么办 城管暴力执法导致老百姓受伤怎么办 领导制定方案与政策不一致怎么办 第三方支付存在的金融风险怎么办 貔貅鼻子摔坏了怎么办 貔貅鼻子磕破了怎么办 红警2游戏出错怎么办 猛犸牙上油花了怎么办 吃了细菌的食物怎么办 易拉罐罐头拉环断了怎么办 衣服上有火锅味怎么办 衣服沾上火锅味怎么办 做杨梅罐头里面好多小白虫怎么办 一地两检手续怎么办 剩米饭变干硬了怎么办 吃剩的米饭变硬怎么办 误食发热包的水怎么办 玻璃饭盒加热后盖子打不开怎么办 玻璃饭盒盖子被吸住了怎么办 微波炉加热饭盒盖子打不开怎么办 铁饭盒盖子打不开了怎么办 塑料玻璃饭盒打不开了怎么办 方便火锅没有发热包怎么办 加热包的水溢出怎么办 军用黄脸盆坏了怎么办 白瓷洗手盆发黄怎么办 挎包没有拉链东西容易掉怎么办 斜挎包肩带长了怎么办 3个月宝宝不吃奶怎么办 米饭扔厕所堵了怎么办 门过梁搭接不够怎么办 华为g7开不了机怎么办 警务通手机丢了怎么办 手机被伪基站覆盖怎么办 听了高频率声音怎么办 qq音乐签到没了怎么办 手机qq音乐不能播放怎么办 台式电脑放歌没有声音怎么办