Limit transfer speed rate by Iptables Rules

374

You can limit speed by iptables, like this.

iptables -I FORWARD -d 192.168.1.6 -j DROP
iptables -I FORWARD -d 192.168.1.6 -m limit --limit 100/sec -m state --state ESTABLISHED -j ACCEPT

But in not very convenient, because "limit" limits by packets, not bytes per seconds. If we suppose 1 packet = 1500 bytes, 100 packets/s = 150 KB/s. But some protocols with smaller packets will work slower. Also this may cause sudden disconnections.

However, if you must limit traffic in router, there is not much choice, often iptables is the only utility on router to do this.

Note that, "limit" and "drop" rules should be in right order. First rule limits and allow traffic, second rule blocks traffic over the limit.

Share:
374

Related videos on Youtube

mohan111
Author by

mohan111

Updated on September 18, 2022

Comments

  • mohan111
    mohan111 over 1 year

    i am trying to get value in Decimal in this query but unable to get i am getting NULL Value

    SELECT CAST(CAST(CAST(SUM(CAST(0 AS INT)) AS DECIMAL(10, 2)) * 100 
    / CAST(NULLIF(SUM(CAST(0 AS INT)) 
    + SUM(CAST(0 AS INT)) + 
    SUM(CAST(0 AS INT)), 0)
     AS DECIMAL(10, 2)) AS DECIMAL(10, 2)) AS DECIMAL)
    

    how to get output

    0.00
    

    instead of null in this query

    • Aaron Bertrand
      Aaron Bertrand over 10 years
      What on earth is the point of this query? Could you post your real problem?
    • Hauke Laging
      Hauke Laging over 9 years
      It doesn't make much sense to call a source rule (--mac-source) an alternative to a destination rule (-d)... You can limit the bandwidth with traffic shaping (tc), too, but if connlimit isn't available that raises the question whether tc is.
    • roaima
      roaima over 9 years
      --limit doesn't do what you appear to think it does, and you can't limit traffic speed with iptables. Instead use tc to manage traffic shaping. Have a search for myshaper, amongst other utilities.
    • Davor Cubranic
      Davor Cubranic about 4 years
      For a full-blown example using tc, you can find myshaper.sh at tldp.org/HOWTO/ADSL-Bandwidth-Management-HOWTO/…
  • Aaron Bertrand
    Aaron Bertrand over 10 years
    At first I thought WTH but then I read this meta post. Do you have JavaScript disabled, or post from mobile or something?
  • gbn
    gbn over 10 years
    @AaronBertrand: dunno. Hypnomullet powers?