Use TC to implement linux-based traffic management-general Linux technology-Linux programming and kernel information. The following is a detailed description. Red Hat Linux 7.3 kernel 2.4.18 or above.
The external address eth0: 192.168.1.3 is bound to eth0 on the server.
Eth1 is bound to the internal address eth1: 1 172.17.1.1
Eth1: 2 172.18.1.1
Eth1: 3 172.19.1.1
The function to be implemented now is to limit the entire exit to 512 kbit (upload traffic), 172.17 download traffic to 512 Kbit, and 172.18 network segment to 128 kbit, the CIDR block of 172.19 is limited to 3 Mbit.
The method is as follows:
First, bind the corresponding address to implement route settings, using iptables.
# Mask IP addresses so that packets of internal hosts can be connected to the outside world through the server.
Manage traffic
# Tc qdisc add dev eth0 root tbf rate 512 k lantency 50 ms burst1540
# Use the TokenBucket Filter (tbf) to Filter the queue on the eth0 Nic. the outbound traffic is limited to 512 kbit, the delay is 50 ms, and the burst data is 1540. The specified rate value is the limited bandwidth.
Continue to limit eth1.
Create a root category. The bandwidth is limited to 5 Mbit and other bandwidths cannot be borrowed.
The parameters following Prio are priority values, indicating the order in which data packets are processed.
Under each category, create a queue and use sfq (Stochastic Fareness Queueing) to then fair the queue.
# Tc filter add dev eth1 parent 1:0 protocol ip prio 1 u32 match ip dst 172.17.0.0/16 flowid :3
# Tc filter add dev eth1 parent 1:0 protocol ip prio 1 u32 match ip dst 172.18.0.0/16 flowid :4
# Tc filter add dev eth1 parent 1:0 protocol ip prio 1 u32 match ip dst 172.19.0.0/16 flowid :5
Use the u32 filter to classify the destination address and match the created queue.
Through the above method, simple traffic control is implemented to limit the upload traffic at the exit and the download traffic at the internal port.
The download speed of 172.18.1.2 is 128 kbit, And the download speed is 13-16.3kB.
The download speed of 172.19.1.2 is limited to 3 Mbit, And the download speed reaches 180-500kB.
Note: If the data packet does not match any rule, the rule set by root is sent.
It is found that the limit error of 3 M bandwidth is relatively large.
The above tests are based on a single machine and are not fully loaded.
The above articles are written in a rush. The TC filter involves a lot of things. There are many methods that can be implemented, either based on IP addresses or ports.
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