打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Driver for the intermediate queue device
This example show network interface independet traffic controller. Its complette example to show imq device usage for a router that have five network interfaces and ethernet bridge with ebtables patch. Trafics controler is used to manage upload and download bandwidth.

We have assigned more public IP address from ISP with 1Mbit for download and 1Mbit for upload. "Customers" will have assigned private (NATed) and public network address.

We have those NIC's assigned for:
eth0  - Internet from ISP
eth1  - "Customers" with public IP's
wlan0 - "Customers" with public IP's  (WiFi)
eth2  - "Customers" with private IP's
wlan1 - "Customers" with private IP's (WiFi)

Public IP's range will be 195.66.77.0/24 and private IP's range 10.0.0.0/16. The example not show
the firewall and wireless interfaces setup.

The example script with comment:

#!/bin/sh

# Example script to show IMQ driver usage
# Author : Jiri Fojtasek <jiri.fojtasek(at)hlohovec.net> http://hyperfighter.sk/qos
# Version: 1.0

#NIC's and bridge br0 connected to ISP
 brctl addbr br0
 brctl addif br0 eth0
 brctl addif br0 eth1
 brctl addif br0 wlan0
 ifconfig eth0 0.0.0.0 up
 ifconfig eth1 0.0.0.0 up
 ifconfig wlan0 0.0.0.0 up
 ifconfig br0 195.66.77.1 netmask 255.255.255.0
 route add default gw 195.66.77.99

#NIC's for private network
 ifconfig eth2 10.0.1.1 netmask 255.255.255.0
 ifconfig wlan1 10.0.2.1 netmask 255.255.255.0

#Setup IMQ devices (numdevs parameter specifies number of imq devices will be loaded)
 modprobe imq numdevs=2
 ifconfig imq0 up
 ifconfig imq1 up

#Setup the NAT
 iptables -t nat -A POSTROUTING -s 10.0.0.0/16 -o br0 -j SNAT --to 195.66.77.1
 
#Setup traffic controler for imq0 (download)
 tc qdisc del dev imq0 root
 tc qdisc add dev imq0 root handle 1 htb default 99
 tc class add dev imq0 parent 1: classid 1:10 htb rate 1Mbit
 
 #Customer 1 with rate 64 Kbit
  tc class add dev imq0 parent 1:10 classid 1:1000 htb rate 64Kbit ceil 64Kbit
  tc qdisc add dev imq0 parent 1:1000 handle 1000 sfq
  tc filter add dev imq0 parent 1:0 protocol ip prio 200 handle 1000 fw classid 1:1000

 #Customer 2 with rate 128 Kbit
  tc class add dev imq0 parent 1:10 classid 1:1010 htb rate 128Kbit ceil 128Kbit
  tc qdisc add dev imq0 parent 1:1010 handle 1010 sfq
  tc filter add dev imq0 parent 1:0 protocol ip prio 200 handle 1010 fw classid 1:1010

 #Customer 3 with rate 256 Kbit
  tc class add dev imq0 parent 1:10 classid 1:1020 htb rate 256Kbit ceil 256Kbit
  tc qdisc add dev imq0 parent 1:1020 handle 1020 sfq
  tc filter add dev imq0 parent 1:0 protocol ip prio 200 handle 1020 fw classid 1:1020

 #Default class with rate 32 Kbit
  tc class add dev imq0 parent 1:10 classid 1:99 htb rate 32Kbit ceil 32Kbit

#Setup traffic controler for imq1 (upload)
 tc qdisc del imq1 root
 tc qdisc add dev imq1 root handle 1 htb default 98
 tc class add dev imq1 parent 1: classid 1:20 htb rate 1Mbit
 
 #Customer 1 with rate 64 Kbit
  tc class add dev imq1 parent 1:20 classid 1:2000 htb rate 64Kbit ceil 64Kbit
  tc qdisc add dev imq1 parent 1:2000 handle 2000 sfq
  tc filter add dev imq1 parent 1:0 protocol ip prio 200 handle 2000 fw classid 1:2000

 #Customer 2 with rate 128 Kbit
  tc class add dev imq1 parent 1:20 classid 1:2010 htb rate 128Kbit ceil 128Kbit
  tc qdisc add dev imq1 parent 1:2010 handle 2010 sfq
  tc filter add dev imq1 parent 1:0 protocol ip prio 200 handle 2010 fw classid 1:2010

 #Customer 3 with rate 256 Kbit
  tc class add dev imq1 parent 1:20 classid 1:2020 htb rate 256Kbit ceil 256Kbit
  tc qdisc add dev imq1 parent 1:2020 handle 2020 sfq
  tc filter add dev imq1 parent 1:0 protocol ip prio 200 handle 2020 fw classid 1:2020

 #Default class with 32 Kbit
  tc class add dev imq1 parent 1:20 classid 1:99 htb rate 32Kbit ceil 32Kbit

#Setup nfmark for each Customer

 #Customer 1 with public IP 195.66.77.2
  #Download
   iptables -t mangle -A POSTROUTING -d 195.66.77.2 -j MARK --set-mark 1000
  #Upload
   iptables -t mangle -A POSTROUTING -s 195.66.77.2 -j MARK --set-mark 2000

 #Customer 2 with private IP 10.0.1.2
  #Download
   iptables -t mangle -A POSTROUTING -d 10.0.1.2 -j MARK --set-mark 1010
  #Upload
   iptables -t mangle -A POSTROUTING -s 10.0.1.2 -j MARK --set-mark 2010

 #Customer 3 with private IP 10.0.2.2
  #Download
   iptables -t mangle -A POSTROUTING -d 10.0.2.2 -j MARK --set-mark 1020
  #Upload
   iptables -t mangle -A POSTROUTING -s 10.0.2.2 -j MARK --set-mark 2020

#And finnaly direct traffic to right IMQ device :)
 #Download
  iptables -t mangle -A POSTROUTING -d 10.0.0.0/16    -j IMQ --todev 0
  iptables -t mangle -A POSTROUTING -d 195.66.77.0/24 -j IMQ --todev 0
 #Upload
  iptables -t mangle -A POSTROUTING -s 10.0.0.0/16    -j IMQ --todev 1
  iptables -t mangle -A POSTROUTING -s 195.66.77.0/24 -j IMQ --todev 1

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
为dd-wrt添加IP限速功能
Linux流量控制---过滤规则/U32-
用tc iptables HTB解决ADSL宽带速度瓶颈技术[zt]
Linux Htb队列规定指南中文版
Linux 高级流控
搞定DD-WRT 控制网速问题
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服