is there a way in Linux to simulate slow traffic inbound to my server at a specific port? I looked at NETEM but it only seems to WAN wide.
Asked
Active
Viewed 4,079 times
7
-
I've been meaning to figure this out for a while; it's more complicated than you may think, but [it is possible](http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm). Off to dinner. – sarnold May 22 '12 at 02:23
-
1can't **telnet host port** be used? – tuxuday May 22 '12 at 07:05
-
@sarnold, you shouldn't need to add a htb queue, see below – Mike Pennington May 24 '12 at 03:45
-
For Reference: related to https://stackoverflow.com/questions/40196730/simulate-network-latency-on-specific-port-using-tc – Stefan Profanter Dec 13 '16 at 12:24
2 Answers
5
An example of limiting all traffic matching tcp (protocol 6) destination port of 54000 at 256Kbits inbound to eth0
, using tc
...
As root...
tc qdisc add dev eth0 handle ffff: ingress
tc filter add dev eth0 parent ffff: protocol ip prio 50 u32 \
match ip protocol 6 0xff \
match ip dport 54000 0xffff police rate 256kbit burst 10k drop \
flowid :1
You can monitor it like this... notice the dropped
number for ffff
, below
[mpenning@Bucksnort ~]$ sudo tc -s qdisc show
qdisc pfifo_fast 0: dev eth0 root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 17796311917 bytes 5850423 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc ingress ffff: dev eth0 parent ffff:fff1 ----------------
Sent 140590 bytes 1613 pkt (dropped 214, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
[mpenning@Bucksnort ~]$
To delete all ingress traffic filters:
tc qdisc del dev eth0 ingress

Mike Pennington
- 41,899
- 19
- 136
- 174
-
-
Can I replace "police rate 256kbit burst 10k drop" with "delay 100ms" and this would delay incoming traffic by 100ms? – delita May 24 '12 at 23:53
-
This is superb, far simpler than the route I _thought_ was necessary to take. Thanks Mike! – sarnold May 25 '12 at 23:11
-
I'm not sure why, but no, you can't drop in "delay 100ms" in place of "police...". – dsummersl Jun 11 '13 at 14:46
0
Have a look at JMeter. Depending on what type of traffic you need, it may already provide the functionality.

Lars Kotthoff
- 107,425
- 16
- 204
- 204