Iptables + Tc speed limit script for Internet cafes per IP Address

Source: Internet
Author: User
#! /Bin/sh # xiaoh www.linuxbyte.org # define the inbound and outbound devices (eth0 Intranet and eth1 Internet) IDEV = "eth0" odev = "eth1" # define the total up/down bandwidth = "50 Mbit" down = "50 Mbit" # define the up/down bandwidth of each restricted IP address # rate start bandwidth upload = "4 Mbit" Download = "5 Mbit" # Ceil maximum bandwidth mupload = "5 Mbit" mdownload = "10 Mbit" # Intranet IP segment Inet = "192.168.0. "# Restricted IP range, IPS starting IP, and IPE ending IP. IPS = "1" IPE = "114" # Clear the original Nic queue rule TC qdisc del Dev $ odev Root 2>/dev/nulltc qdisc del Dev $ IDEV Root 2>/dev/ null # define the top layer (Root) queue rule, and specify the default category number TC qdisc add Dev $ odev root handle 10: htb default 256tc qdisc add Dev $ IDEV root handle 10: htb default 256 # define the 10:1 class of the first layer (total uplink/downlink bandwidth) TC class add Dev $ odev parent 10: classid 10:1 htb rate $ up Ceil $ uptc class add Dev $ IDEV parent 10: classid 10:1 htb rate $ down Ceil $ down # Start iptables tagging and set specific rules I = $ IPs; while [$ I-Le $ IPE] DOTC class add Dev $ odev parent 10:1 classid $ I htb rate $ upload Ceil $ mupload PRIO 1tc qdisc add Dev $ odev parent $ I handle 100 $ I: pfifotc filter add Dev $ odev parent 10: protocol ip prio 100 handle 2 $ I fw classid $ ITC class add Dev $ IDEV parent 10classid $ I htb rate $ download Ceil $ mdownload PRIO 1tc qdisc add Dev $ IDEV parent $ I handle 100 $ I: pfifotc filter add Dev $ IDEV parent 10: protocol ip prio 100 handle 2 $ I fw classid 10:2 $ iiptables-T mangle-A prerouting-S $ Inet $ I-j mark -- Set-mark 2 $ iiptables-T mangle- prerouting-S $ Inet $ I-j returniptables-T mangle-A postrouting-d $ Inet $ I-j mark -- Set-mark 2 $ iiptables-T mangle-A postrouting-d $ Inet $ I-j returnI = 'expr $ I + 1' done
Related Article

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.