Use iptables speed limit to control bandwidth traffic

Source: Internet
Author: User
In linux, iptables is used to limit traffic, which is simple and practical. You can use the following script to configure the machine as a gateway. 1. configure iptables forwarding (omitted) 2. speed limit script vi/root/xiansu. sh #! /Bin/bash/sbin/iptables-FFORWARD # restrict the network segment for (i1; i253; I ++) do/sbin/ip in linux IptablesIt is simple and practical to restrict traffic. You can use the following script to configure the machine as a gateway.

1. configure iptables forwarding (omitted)

2. speed limit script
Vi/root/xiansu. sh
#! /Bin/bash
/Sbin/iptables-F FORWARD

# CIDR block restriction
For (I = 1; I <253; I ++ ))
Do
/Sbin/iptables-a forward-s 192.168.2. $ I-m limit \ -- limit 60/s-j ACCEPT
/Sbin/iptables-a forward-s 192.168.2. $ I-j DROP

Done

# Restrict a single ip address
/Sbin/iptables-a forward-s 192.168.1.135/32-m limit \ -- limit 60/s-j ACCEPT
/Sbin/iptables-a forward-s 192.168.1.135/32-j DROP

Vi/root/xiansu. sh
#! /Bin/bash
/Sbin/iptables-F FORWARD

# CIDR block restriction
For (I = 1; I <253; I ++ ))
Do
/Sbin/iptables-a forward-s 192.168.2. $ I-m limit \ -- limit 60/s-j ACCEPT
/Sbin/iptables-a forward-s 192.168.2. $ I-j DROP

Done

# Restrict a single ip address
/Sbin/iptables-a forward-s 192.168.1.135/32-m limit \ -- limit 60/s-j ACCEPT
/Sbin/iptables-a forward-s 192.168.1.135/32-j DROP

2. added the execution permission:
Chmod + x/root/xiansu. sh
When the traffic is less than 60/s, iptables accepts and forwards the data. When the traffic exceeds 60/s, iptables discards the packet.
Done!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.