Recently, some colleagues used Bt and e for crazy download. We were greatly affected when playing Cs on the Internet, so we made traffic control on Nat and introduced some experience to netizens, hope to help CS fans.
The Internet environment is as follows:
Eth0 Internet IP Address: A. B. C. d
Eth1 Intranet IP1: 192.168.0.0/24 for the boss and BT
Eth2 Intranet ip2: 192.168.1.0/24 For Me And csfans
The Linux-based NAT command is as follows:
Echo 1>;/proc/sys/NET/IPv4/ip_forward
Iptables-F
Iptables-T nat-F ---- clear old rules
Iptables-T Nat-A postrouting-s 192.168.0.0/24-O eth0-j snat -- to A. B. C. d --- Nat for Intranet IP1
Iptables-T Nat-A postrouting-s 192.168.1.0/24-O eth0-j snat -- to A. B. C. d --- Nat for Intranet ip2
------------ Mark Traffic Control Based on fw Filter
Iptables-I prerouting-T mangle-P TCP-s 192.168.0.0/24-J mark -- Set-mark 1
Iptables-I prerouting-T mangle-P TCP-s 192.168.1.0/24-J mark -- Set-mark 2
------------ Perform traffic control for the upload speed
TC requires kernel 2.4.18 or above, so upgrade is not enough
TC can only control the speed at which packets are sent by the Network Adapter. Therefore, the upload speed must be limited to eth0.
---- Delete old queue
TC qdisc del Dev eth0 Root
---- Add a root queue with a NIC speed of 10 Mbit, And the upload speed is also available
TC qdisc add Dev eth0 root handle 100: CBQ bandwidth 10 Mbit avpkt 1000
---- Add a root class
TC class add Dev eth0 parent 100:0 classid 100cbq bandwidth 10 Mbit rate 10 Mbit allot 1514 weight 1 Mbit PRIO 8 maxburst 8 avpkt 1000 bounded
---- Add a subclass for Intranet 1 speed limit of 300 kbit
TC class add Dev eth0 parent 100classid 100:2 CBQ bandwidth 10 Mbit rate 300 kbit allot 1513 weight 30 kbit PRIO 5 maxburst 8 avpkt 1000 bounded
---- Add a subclass for Intranet 2 with a speed limit of 320 kbit
TC class add Dev eth0 parent 100classid 100:3 CBQ bandwidth 10 Mbit rate 320 kbit allot 1513 weight 32 kbit PRIO 6 maxburst 8 avpkt 1000 bounded
---- Set queue rules
TC qdisc add Dev eth0 parent 100:2 SFQ quantum 1514b perturb 15
TC qdisc add Dev eth0 parent 100:3 SFQ quantum 1514b perturb 15
------ Map the queue to the FW filter. The 1 of hand 1 is the tag that begins to use iptables, and the 2 of hand 2 is also the tag that begins to use iptables.
TC filter add Dev eth0 parent 100:0 Protocol ip prio 1 handle 1 FW classid 100:2
TC filter add Dev eth0 parent 100:0 Protocol ip prio 2 handle 2 FW classid 100:3
----------------------- I only limit the download speed of the boss and BT, and the filter uses u32.
TC qdisc del Dev eth1 Root
TC qdisc add Dev eth1 root handle 200: CBQ bandwidth 10 Mbit avpkt 1000
TC class add Dev eth1 parent 200:0 classid 200cbq bandwidth 10 Mbit rate 10 Mbit allot 1514 weight 2 kbit PRIO 8 maxburst 8 avpkt 1000 bounded
TC class add Dev eth1 parent 200classid 200:2 CBQ bandwidth 10 Mbit rate 1000 kbit allot 1513 weight 1 Mbit PRIO 5 maxburst 8 avpkt 1000 bounded
TC qdisc add Dev eth1 parent 200:2 SFQ quantum 1514b perturb 15
TC filter add Dev eth1 parent 200:0 Protocol ip prio 25 u32 Match ip DST 192.168.0.0/24 flowid 200:2
----------------------
Now we can use TC-s qdisc ls Dev eth0
TC-s qdisc ls Dev eth1
TC-S Class ls Dev eth0
TC-S Class ls Dev eth1 monitoring traffic