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!